adrianinsaval wrote: ↑Mon Oct 28, 2019 3:58 am
Interesting, how do you propose this variants should be saved? embedded in the assembly file?
well, first I think that these are still App::Link objects, so no, not in the assembly. What should be stored in the assembly is the base file and the variables that shall be modified to produce — on the fly, in RAM, not on disk — the variant. The point is also that this should be forward compatible, meaning that files produced today shall be usable in 10 years. But in 10 years people are going to come with new ideas. While it would be quite easy to come up with a solution for today, this would not scale well.
The minimum would be to store in the assembly:
- the base file : Path
- a boolean that it's a variant of that base file : isVariant
- the variant type (because I'm sure other people will have other use-cases in mind) : VariantType
- the variables that shall be changed and their values : a list
And then, according to the variant type, take evasive action. So for each App::Link, there should be 1 additional boolean property
isVariant if "
false" then it's a normal App::Link:
Code: Select all
<Object name="Part_1" Extensions="True">
<Properties Count="18" TransientCount="0">
...
<Property name="LinkedObject" type="App::PropertyXLink" status="256">
<XLink file="part1.FCStd" stamp="2019-10-28T07:10:15Z" name="Part"/>
</Property>
<Property name="isVariant" type="App::PropertyBool" status="256">
<Bool value="false"/>
</Property>
...
</Properties>
</Object>
adrianinsaval wrote: ↑Mon Oct 28, 2019 3:58 am
If you add further features to the original file, how will they be updated in the variants?
To be clear, the primary use-case would be for families of parts, to be used as library, therefore the occurrence of the base part changing should be rare. When that happens, a command "
Reload Variant" is needed, that re-fetches the base part from disk, and re-applies the variants changes to it. Thus, if additional functions have been added, they will be included also.
adrianinsaval wrote: ↑Mon Oct 28, 2019 3:58 am
Unrelated cuestion: how did you make the "Variables" object, it seems very handy
They're FeaturePython objects. They're the poor man's spreadsheet. In a new document, try:
Code: Select all
App.ActiveDocument.addObject('App::Part','Model')
vars = App.ActiveDocument.getObject('Model').newObject( 'App::FeaturePython', 'Variables' )
vars.addProperty( 'App::PropertyBool', 'Variant', 'Variables' )
vars.Variant = True
vars.addProperty( 'App::PropertyFloat', 'Length', 'Variables' )
vars.Length = 10
vars.addProperty( 'App::PropertyEnumeration', 'Size', 'Variables' )
vars.Size = ['M2', 'M2.5', 'M3', 'M4', 'M5', 'M6']
vars.addProperty( 'App::PropertyString', 'Comment', 'Variables' )
vars.Comment = 'This is a comment'