diff --git a/portail_coulissant/porcou_doc-fr.blend b/portail_coulissant/porcou_doc-fr.blend index 6eea1eb..f40f145 100644 Binary files a/portail_coulissant/porcou_doc-fr.blend and b/portail_coulissant/porcou_doc-fr.blend differ diff --git a/portail_coulissant/porcou_doc.py b/portail_coulissant/porcou_doc.py index 496e72a..c70f77d 100644 --- a/portail_coulissant/porcou_doc.py +++ b/portail_coulissant/porcou_doc.py @@ -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", "movement-card", "sensor-card", "gyro-card", "board-card", "model-card", "arduino-card"] +# system_card=["twins-card"] card_description ={} # Jumeau numérique diff --git a/twin_doc-gen.py b/twin_doc-gen.py index 479f591..c3efa9a 100644 --- a/twin_doc-gen.py +++ b/twin_doc-gen.py @@ -1,5 +1,6 @@ import bpy # Blender import importlib +import sys import time ############################################################################### @@ -20,19 +21,24 @@ scene = bpy.context.scene card_description ={} # 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_card = system.get_system_card() -# card_description.update(system.get_card_description()) +system_card = system.get_system_card() +card_description.update(system.get_card_description()) ############################################################################### # Documentation Python ############################################################################### # "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"] -python_card=["function-card" ,"alternative-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" ,"alternative-card"] # 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 +" ...") if obj.name == "Doc_chap-system": chap_card = system_card + rep_chap= bpy.data.objects["Doc_chap-system"] if obj.name == "Doc_chap-python": chap_card = python_card + rep_chap= bpy.data.objects["Doc_chap-python"] # Création des objets 3D + # bpy.ops.collection.create(name='Collection') i=1 for card in chap_card : print ("Génération de la page : "+ card) # Repère page rep_ref= bpy.data.objects["Doc_chap-ref"] - rep_chap= bpy.data.objects["Doc_chap-python"] - 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) + 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) + # collection = bpy.data.collections["Test"] + # collection.objects.link(rep_page) i+=1 - # Texte de la page - # bpy.ops.collection.create(name='Collection') - lines = card_description[card][1].split("\n") - for j in range (13): - ligne_name = "Doc_text-l"+str(j+1)+"-"+str(card) - ligne_ref=bpy.data.objects["Doc_text-l"+str(j+1)+"-ref"] - ligne_text = duplicateObject(scene, ligne_name, "Doc_text-l"+str(j+1)+"-ref", - ligne_ref.location.x-rep_ref.location.x, - ligne_ref.location.y-rep_ref.location.y, - ligne_ref.location.z-rep_ref.location.z) - ligne_text.parent = rep_page - if j >= len(lines): - ligne_text.data.body="" - else: - if len(lines[j]) ==0: - ligne_text.data.body="" - else: - ligne_text.data.body=lines[j] + # Titre + titre_name = "Doc_title-"+str(card) + titre_ref=bpy.data.objects["Doc_title-ref"] + titre = addText(scene, titre_name, "Doc_title-ref", card_description[card][0], + titre_ref.location.x-rep_ref.location.x, + titre_ref.location.y-rep_ref.location.y, + 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.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 + + # Texte de la page découpé + # lines = card_description[card][1].split("\n") + # for j in range (13): + # ligne_name = "Doc_text-l"+str(j+1)+"-"+str(card) + # ligne_ref=bpy.data.objects["Doc_text-l"+str(j+1)+"-ref"] + # # 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 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 ############################################################################### -def duplicateInstance (scene, name, x, y, z) : - ob_new = bpy.data.objects.new(name, None) - ob_new.location = (x,y,z) - return ob_new +# Copier un object def duplicateObject (scene, name, src, x, y, z) : - # print (name, src, x, y, z) - obj = bpy.data.objects[src].copy() + for obj in bpy.context.selected_objects: + 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 - # 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.location = (x,y,z) 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 ############################################################################### -# text_gene(scene.objects["Doc_chap-system"]) +text_gene(scene.objects["Doc_chap-system"]) text_gene(bpy.data.objects["Doc_chap-python"]) text_gene_end()