Bugfix : Génération statique de la documentation

This commit is contained in:
Philippe Roy 2022-12-30 02:41:32 +01:00
parent e313a7d410
commit 918f715eb1
3 changed files with 89 additions and 42 deletions

View File

@ -14,6 +14,7 @@
# system_card=["twins-card", "serial-card", "movement-card", "sensor-card", "gyro-card", "board-card", "model-card", "arduino-card"] # system_card=["twins-card", "serial-card", "movement-card", "sensor-card", "gyro-card", "board-card", "model-card", "arduino-card"]
system_card=["twins-card", "movement-card", "sensor-card", "gyro-card", "board-card", "model-card", "arduino-card"] system_card=["twins-card", "movement-card", "sensor-card", "gyro-card", "board-card", "model-card", "arduino-card"]
# system_card=["twins-card"]
card_description ={} card_description ={}
# Jumeau numérique # Jumeau numérique

View File

@ -1,5 +1,6 @@
import bpy # Blender import bpy # Blender
import importlib import importlib
import sys
import time import time
############################################################################### ###############################################################################
@ -20,19 +21,24 @@ scene = bpy.context.scene
card_description ={} card_description ={}
# Documentation du sytème # Documentation du sytème
# FIXME : plus tard path = scene.objects['Doc']['path']
name = scene.objects['Doc']['system']+'_doc'
spec = importlib.util.spec_from_file_location(name, path)
system = importlib.util.module_from_spec(spec)
sys.modules[spec.name] = system
spec.loader.exec_module(system)
# system=importlib.import_module(scene.objects['Doc']['system']+'_doc') # Système # system=importlib.import_module(scene.objects['Doc']['system']+'_doc') # Système
# system_card = system.get_system_card() system_card = system.get_system_card()
# card_description.update(system.get_card_description()) card_description.update(system.get_card_description())
############################################################################### ###############################################################################
# Documentation Python # Documentation Python
############################################################################### ###############################################################################
# "oop-card" # "oop-card"
# python_card=["function-card", "alternative-card", "loop-card", "flow-card", "text-card", "list-card", "dict-card", "console-card", "sleep-card", "python-card"] python_card=["function-card", "alternative-card", "loop-card", "flow-card", "text-card", "list-card", "dict-card", "console-card", "sleep-card", "python-card"]
# python_card=["function-card"] #python_card=["function-card"]
python_card=["function-card" ,"alternative-card"] # python_card=["function-card" ,"alternative-card"]
# Fonction # Fonction
card_function_title="Fonction" card_function_title="Fonction"
@ -164,38 +170,64 @@ def text_gene(obj):
print ("Génération des pages de la documentation pour le chapitre : "+ obj.name +" ...") print ("Génération des pages de la documentation pour le chapitre : "+ obj.name +" ...")
if obj.name == "Doc_chap-system": if obj.name == "Doc_chap-system":
chap_card = system_card chap_card = system_card
rep_chap= bpy.data.objects["Doc_chap-system"]
if obj.name == "Doc_chap-python": if obj.name == "Doc_chap-python":
chap_card = python_card chap_card = python_card
rep_chap= bpy.data.objects["Doc_chap-python"]
# Création des objets 3D # Création des objets 3D
# bpy.ops.collection.create(name='Collection')
i=1 i=1
for card in chap_card : for card in chap_card :
print ("Génération de la page : "+ card) print ("Génération de la page : "+ card)
# Repère page # Repère page
rep_ref= bpy.data.objects["Doc_chap-ref"] rep_ref= bpy.data.objects["Doc_chap-ref"]
rep_chap= bpy.data.objects["Doc_chap-python"] rep_page = duplicateObject(scene, "Doc_page-"+str(card), "Doc_chap-ref",rep_chap.location.x+ i*100, rep_chap.location.y, rep_chap.location.z)
rep_page = duplicateObject(scene, "Doc_text-"+str(card), "Doc_chap-ref",rep_chap.location.x+ i*100, rep_chap.location.y, rep_chap.location.z) # collection = bpy.data.collections["Test"]
# collection.objects.link(rep_page)
i+=1 i+=1
# Texte de la page # Titre
# bpy.ops.collection.create(name='Collection') titre_name = "Doc_title-"+str(card)
lines = card_description[card][1].split("\n") titre_ref=bpy.data.objects["Doc_title-ref"]
for j in range (13): titre = addText(scene, titre_name, "Doc_title-ref", card_description[card][0],
ligne_name = "Doc_text-l"+str(j+1)+"-"+str(card) titre_ref.location.x-rep_ref.location.x,
ligne_ref=bpy.data.objects["Doc_text-l"+str(j+1)+"-ref"] titre_ref.location.y-rep_ref.location.y,
ligne_text = duplicateObject(scene, ligne_name, "Doc_text-l"+str(j+1)+"-ref", titre_ref.location.z-rep_ref.location.z)
titre.parent = rep_page
# Texte de la page en une seule fois
ligne_name = "Doc_text-"+str(card)
ligne_ref=bpy.data.objects["Doc_text-l1-ref"]
ligne_text = addText(scene, ligne_name, "Doc_text-l1-ref", card_description[card][1],
ligne_ref.location.x-rep_ref.location.x, ligne_ref.location.x-rep_ref.location.x,
ligne_ref.location.y-rep_ref.location.y, ligne_ref.location.y-rep_ref.location.y,
ligne_ref.location.z-rep_ref.location.z) ligne_ref.location.z-rep_ref.location.z)
# bpy.data.collections["Doc generation"].objects.link(ligne_text)
ligne_text.parent = rep_page ligne_text.parent = rep_page
if j >= len(lines):
ligne_text.data.body="" # Texte de la page découpé
else: # lines = card_description[card][1].split("\n")
if len(lines[j]) ==0: # for j in range (13):
ligne_text.data.body="" # ligne_name = "Doc_text-l"+str(j+1)+"-"+str(card)
else: # ligne_ref=bpy.data.objects["Doc_text-l"+str(j+1)+"-ref"]
ligne_text.data.body=lines[j] # # ligne_ref.data.body="A"
# if j >= len(lines):
# pass
# else:
# if len(lines[j]) ==0:
# pass
# else:
# ligne_text = addText(scene, ligne_name, "Doc_text-l"+str(j+1)+"-ref", lines[j],
# ligne_ref.location.x-rep_ref.location.x,
# ligne_ref.location.y-rep_ref.location.y,
# ligne_ref.location.z-rep_ref.location.z)
# bpy.data.collections["Doc generation"].objects.link(ligne_text)
# ligne_text.parent = rep_page
# # for obj_selected in bpy.context.selected_objects:
# # obj_selected.select_set(False)
# # bpy.ops.object.join()
# Fin # Fin
print ("Génération des pages de la documentation pour le chapitre : "+ obj.name +" Ok") print ("Génération des pages de la documentation pour le chapitre : "+ obj.name +" Ok")
@ -204,32 +236,46 @@ def text_gene(obj):
# Bas niveau duplication d'objet # Bas niveau duplication d'objet
############################################################################### ###############################################################################
def duplicateInstance (scene, name, x, y, z) : # Copier un object
ob_new = bpy.data.objects.new(name, None)
ob_new.location = (x,y,z)
return ob_new
def duplicateObject (scene, name, src, x, y, z) : def duplicateObject (scene, name, src, x, y, z) :
# print (name, src, x, y, z) for obj in bpy.context.selected_objects:
obj = bpy.data.objects[src].copy() obj.select_set(False)
bpy.data.objects[src].select_set(True)
bpy.ops.object.duplicate()
for obj in bpy.context.selected_objects:
break
obj.name = name obj.name = name
# me = obj.data
# me = bpy.context.object.data
# print (me.body)
# obj.data = bpy.data.objects[src].data.copy()
# me = obj.data = obj.data.copy()
# print (obj)
collection = bpy.data.collections["Test"]
collection.objects.link(obj)
obj.scale = bpy.data.objects[src].scale obj.scale = bpy.data.objects[src].scale
obj.location = (x,y,z) obj.location = (x,y,z)
return obj return obj
# Créer un texte
def addText (scene, name, src, body, x, y, z) :
curve = duplicateObject(scene, name, src, x, y, z)
curve.data.body=body
return curve
# Créer un maillage texte
def addTextMesh (scene, name, src, body, x, y, z) :
curve = duplicateObject(scene, name, src, x, y, z)
curve.data.body=body
mesh = bpy.data.meshes.new_from_object(curve)
obj = bpy.data.objects.new(name, mesh)
obj.matrix_world = curve.matrix_world
for obj_selected in bpy.context.selected_objects:
obj_selected.select_set(False)
curve.select_set(True)
bpy.ops.object.delete()
obj.name = name
return obj
############################################################################### ###############################################################################
# Main # Main
############################################################################### ###############################################################################
# text_gene(scene.objects["Doc_chap-system"]) text_gene(scene.objects["Doc_chap-system"])
text_gene(bpy.data.objects["Doc_chap-python"]) text_gene(bpy.data.objects["Doc_chap-python"])
text_gene_end() text_gene_end()