There is very little information about the non parametric array. (For my code, the Parametric array is OK, but this is not OK)
My question is this:
When I use "App:: PropertyLinkList" to link three objects. When I array, I only get the parent object, but not the three child objects.
https://forum.freecadweb.org/viewtopic.php?f=3&t=74100
Code: Select all
obj.addProperty('App::PropertyLinkList', 'Links', 'Lens', 'FreeCAD objects to be lenses').Links = [front_Surface, rear_Surface, edge_Surface]
I tried a variety of "objectslist". This seems a bit difficult to solve.
I'm sorry I can't provide ". FCStd" because it doesn't work
edit: I made a similar example, just change the "Draft. array (obj,)" in "def NonParametric_array (self, obj):"
Copy the code to the python console, and select "NonParametric" from the array's Power
Code: Select all
import FreeCAD as App
import Part
import Draft
import FreeCAD, FreeCADGui, Part
def create():
"""
Object creation method
"""
obj = App.ActiveDocument.addObject('Part::FeaturePython', "name")
objCylinder = Part.show(Part.makeCylinder(5,10))
box(obj, objCylinder)
ViewProviderBox(obj.ViewObject)
App.ActiveDocument.recompute()
return obj
class box():
def __init__(self, obj, objCylinder):
"""
Default constructor
"""
self.Type = 'box'
self.objCylinder = objCylinder
obj.addProperty("App::PropertyEnumeration","Power","Array","Lens Array").Power=["Off", "NonParametric"]
obj.addProperty('App::PropertyLength', 'Length', 'Dimensions', 'Box length').Length = 10
obj.addProperty('App::PropertyLength', 'Width', 'Dimensions', 'Box width').Width = 10
obj.addProperty('App::PropertyLength', 'Height', 'Dimensions', 'Box height').Height = 10
obj.addProperty('App::PropertyLinkList', 'Links', 'Lens', 'FreeCAD objects to be lenses').Links = [objCylinder]
obj.Proxy = self
def execute(self, obj):
"""
Called on document recompute
"""
obj.Shape = Part.makeBox(obj.Length, obj.Width, obj.Height)
def onChanged(self, obj, prop):
if prop == "Power":
if obj.Power == "NonParametric":
self.NonParametric_array(obj)
def NonParametric_array(self, obj):
objlist = [obj, self.objCylinder]
Draft.array(obj,FreeCAD.Vector(20, 0, 0),
FreeCAD.Vector(0, 20, 0),
FreeCAD.Vector(0, 0, 0),
3,3,1)
class ViewProviderBox(object):
def __init__(self, vobj):
"""
Set this object to the proxy object of the actual view provider
"""
self.Object = vobj.Object
vobj.Proxy = self
def attach(self, vobj):
"""
Setup the scene sub-graph of the view provider, this method is mandatory
"""
self.Object = vobj.Object
self.onChanged(vobj, '')
def updateData(self, fp, prop):
"""
If a property of the handled feature has changed we have the chance to handle this here
"""
pass
def getDisplayModes(self,obj):
"""
Return a list of display modes.
"""
return []
def getDefaultDisplayMode(self):
"""
Return the name of the default display mode. It must be defined in getDisplayModes.
"""
return "Shaded"
def setDisplayMode(self,mode):
"""
Map the display mode defined in attach with those defined in getDisplayModes.
Since they have the same names nothing needs to be done.
This method is optional.
"""
return mode
def onChanged(self, vp, prop):
"""
Print the name of the property that has changed
"""
pass
def onDelete(self, feature, subelements):
'''Here we can do something when the feature will be deleted'''
return True
def claimChildren(self):
'''Return a list of objects that will be modified by this feature'''
return self.Object.Links
def getIcon(self):
"""
Return the icon in XMP format which will appear in the tree view. This method is optional and if not defined a default icon is shown.
"""
return """
/* XPM */
static const char * ViewProviderBox_xpm[] = {
"16 16 6 1",
" c None",
". c #141010",
"+ c #615BD2",
"@ c #C39D55",
"# c #000000",
"$ c #57C355",
" ........",
" ......++..+..",
" .@@@@.++..++.",
" .@@@@.++..++.",
" .@@ .++++++.",
" ..@@ .++..++.",
"###@@@@ .++..++.",
"##$.@@$#.++++++.",
"#$#$.$$$........",
"#$$####### ",
"#$$#$$$$$# ",
"#$$#$$$$$# ",
"#$$#$$$$$# ",
" #$#$$$$$# ",
" ##$$$$$# ",
" ####### "};
"""
def __getstate__(self):
"""
Called during document saving.
"""
return None
def __setstate__(self,state):
"""
Called during document restore.
"""
return None
create()