this is a follow-up on one of my previous requests, and I'll try to describe here what I'd like to do. I think it should be possible to do it with current (pre-v0.19) FreeCAD, but I'm not sure.
Basically, what I'd like to do is (EDIT: I got the sequence wrong):
- load an App::Part from a file (or have it already opened)
- modify some parameters of that App::Part (like a length, an angle...)
- create a hidden temporary document
- deep-copy the (modified) App::Part into this new document
- modify some parameters of that App::Part (like a length, an angle...)
- link to that App::Part
- insert that link into an assembly
- the parameter can be changed from within the assembly, and when recalculating the assembly the (new) parameters shall be applied
- when closing and re-opening the assembly, the placement and parameters of the (variant) link shall be preserved/restored
- for a beam, have a single FreeCAD file with a default length, and be able to insert the beam several times into an assembly with different length
- a family of screw (yes, I know about the Fasteners WB) and set the parameters of the screw interactively in the assembly
- for a sub-assembly, have multiple versions of it in an assembly with different settings (like a switch that would have positions ON or OFF)
- ... I'm sure there are other use-cases
I did read the documentation about parametric objects and scripted objects but I don't understand them. Ideally, I'd like some very basic template object (App::FeaturePython or App::LinkPython) and I'd try to modify them to do what I want them to do.realthunder wrote: ↑Thu Jan 09, 2020 2:48 am This is just a Python extended version of App::Link, similar to what Part::FeaturePython to Part::Feature. Whether it is suitable for you or not depends on you need. Please elaborate, maybe in a separate post.
This is what I did by hand that nearly works (I can't save the result to a file):
Code: Select all
asmDoc = App.ActiveDocument
tmpDoc = App.newDocument('tmpDoc', label='tmpDoc', hidden='True')
App.setActiveDocument(asmDoc.Name)
tmpDoc.FileName ='toto'
beamCopy = tmpDoc.copyObject( asmDoc.getObject( 'Beam'), 'True' )
asmDoc.getObject('Beam_2').LinkedObject = beamCopy
asmDoc.getObject('Beam_3').LinkedObject = beamCopy
asmDoc.getObject('Beam_4').LinkedObject = beamCopy
copyVars = beamCopy.getObject('Variables')
copyVars.Length=50
copyVars.Size=50
asmDoc.recompute()
All help would be welcome.