Bonjour,
Actuellement en stage, je travaille sur le développement d'un addon sous blender et je rencontre un problème lors de l'appel d'une fonction dans un script différent malgré l'import.
Le premier fichier est supposé ouvrir l'explorateur de fichier et j'aimerais récupérer dans le deuxième script le path du fichier sélectionné par l'utilisateur le hic est que lorsque je sélectionne le fichier et que j'essaye de créer le graphique j'ai l'erreur suivante
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 Traceback (most recent call last): File "/home/wquentel/.config/blender/2.79/scripts/addons/create_custom_graph/CustomGraphOperator.py", line 45, in execute self.a() File "/home/wquentel/.config/blender/2.79/scripts/addons/create_custom_graph/CustomGraphOperator.py", line 15, in a f = open(CustomDrawOperator.getPath(),"r") AttributeError: module 'create_custom_graph.CustomDrawOperator' has no attribute 'getPath' location: <unknown location>:-1et voici le deuxième fichier
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 import bpy import struct import os from bpy.types import Panel, Operator #--------------------------------- #FileOpener and selector #--------------------------------- #will contain the file from CustomDrawOperator for CustomGraphOperator class CustomDrawOperator(bpy.types.Operator): bl_idname = "object.custom_opener" bl_label = "Import" filepath = bpy.props.StringProperty(subtype="FILE_PATH") my_float = bpy.props.FloatProperty(name="Float") my_bool = bpy.props.BoolProperty(name="Toggle Option") my_string = bpy.props.StringProperty(name="String Value") def getPath(self): return self.filepath def execute(self, context): print() return {'FINISHED'} def invoke(self, context, event): context.window_manager.fileselect_add(self) return {'RUNNING_MODAL'} def draw(self, context): layout = self.layout col = layout.column() col.label(text="Custom Interface!") row = col.row() row.prop(self, "my_float") row.prop(self, "my_bool") col.prop(self, "my_string") def register(): bpy.utils.register_class(CustomDrawOperator) def unregister(): bpy.utils.unregister_class(CustomDrawOperator)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 import bpy import bmesh import struct from . import CustomDrawOperator from bpy.types import Panel, Operator #-------------------------------------------------- #Custom Operator to make Graph from data file #-------------------------------------------------- class CustomGraphOperator(bpy.types.Operator): bl_idname = "object.custom_draw" bl_label = "Import" #Will use raw data file to create uvsphere and place them def a(self): f = open(CustomDrawOperator.getPath(),"r") for line in f: objName=line.split()[0] strX=line.split()[1] strY=line.split()[2] strZ=line.split()[3] x=float(strX) y=float(strY) z=float(strZ) print(objName," ",x," ",y," ",z) bpyscene = bpy.context.scene # Create an empty mesh and the object. mesh = bpy.data.meshes.new(objName) basic_sphere = bpy.data.objects.new(objName, mesh) # Add the object into the scene. bpyscene.objects.link(basic_sphere) bpyscene.objects.active = basic_sphere basic_sphere.select = True # Construct the bmesh cube and assign it to the blender mesh. bm = bmesh.new() bmesh.ops.create_uvsphere(bm, u_segments=32, v_segments=16, diameter=1) bm.to_mesh(mesh) bm.free() bpy.ops.object.modifier_add(type='SUBSURF') bpy.ops.object.shade_smooth() bpy.data.objects[objName].location.x += x bpy.data.objects[objName].location.y += y bpy.data.objects[objName].location.z += z f.close() def execute(self,context): self.a() return {'FINISHED'} def register(): bpy.utils.register_class(CustomGraphOperator) def unregister(): bpy.utils.unregister_class(CustomGraphOperator)
Je pense que ma démarche est bonne pour la récupération du path mais j'avoue être incapable de comprendre pour quelle raison cela ne fonctionne pas
Merci d'avance pour vos réponse !
Partager