Is there any way to export a Tree Objects to a file to use it as an template
Hello,
I have a question about the script in mechanical.
For example, I have a contact object in model A, which includes many settings. I want to reuse these settings as a contact template in some other models.
Is there any good way to export a tree object as a reusable file? Then I can import the file and modify the geometry scope to use it in a new model.
I tried to export the data like below, but the file not importable. It does not include and information.
import pickle
with open(r"A.pickle", 'wb') as f:
a=Tree.FirstActiveObject
pickle.dump(a, f)
Thanks!
Best Answers
-
FYI, there is a UI, built-in method to do this for contacts. You can RMB>Export and/or Import from a .xml file.
If you want to make the logic more robust, I would suggest you use the mechanical recording function in the scripting console. All the UI actions of modifying the details window properties of a contact should be recorded. You can then re-use this python to set properties of other contact objects any way you want.
0 -
Thanks @Mike.Thompson I was not aware of this enhancement! Using script recording at 24.2:
contact_region_35 = DataModel.GetObjectById(35) contact_region_35.SaveContactRegionSettings(r'D:\Temp\Contact Region.xml') contact_region_38 = DataModel.GetObjectById(38) contact_region_38.LoadContactRegionSettings(r'D:\Temp\Contact Region.xml')
0
Answers
-
Hi
Another possible way is just to extract all of the contact properties (via mech script) and save them all to a text file.
All the best
Erik
0 -
@Mike.Thompson Do you have a tool for this?
0 -
Thanks, @Mike.Thompson & @Landon Mitchell Kanner. It works great for contact.
Beside the contact, is there any good way to export the load and other object?
Especially for the one has tabular data.I try to go through all the items in "Tree.FirstActiveObject.VisibleProperties", but it looks like there is no tabular data included.
0