How can I modify a FreeCAD obeject's "Name"?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
oscarchan
Posts: 47
Joined: Mon Apr 11, 2022 2:04 am

How can I modify a FreeCAD obeject's "Name"?

Post by oscarchan »

Image
Attachments
Snipaste_2022-05-11_10-05-36.png
Snipaste_2022-05-11_10-05-36.png (7.55 KiB) Viewed 894 times
Thank you!
edwilliams16
Veteran
Posts: 3112
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: How can I modify a FreeCAD obeject's "Name"?

Post by edwilliams16 »

You can't. You can assign your own Label. Names are assigned by FreeCAD. https://wiki.freecadweb.org/Object_name
timo.kinnunen
Posts: 4
Joined: Wed May 11, 2022 8:22 pm

Re: How can I modify a FreeCAD obeject's "Name"?

Post by timo.kinnunen »

It's possible, just not directly. You could do it by:

# 1. Creating a temporary Document and creating in it a new object with the desired name.
# 2. Reading back the resulting name to get a sanitized name we know we are allowed to use.
# 3. Creating a shallow copy of the original object. We do this without any dependencies,
# as we want to leave those alone.
# 4. Creating another temporary Document and moving the shallow copy there.
# 5. Saving the temporary Document to the temp directory, making note of
# the Name and Label the shallow copy ended up with.
# 6. Opening the saved Document as a .ZIP file...
# 7. ...Then creating an element-wise copy, with each file in the archive having had
# every occurrence of Name and Label values changed to the name we got from step 1.
# 8. And finally, merging the modified Document back into the original Document.


If I had an API that could swap all references to object A to reference its copy A_2 and viceversa, I could turn this into a fully-functional macro.

(Now that I think about it, all these steps could be avoided if Std DuplicateSelection allowed the names of the new objects it creates to be customized.)
oscarchan
Posts: 47
Joined: Mon Apr 11, 2022 2:04 am

Re: How can I modify a FreeCAD obeject's "Name"?

Post by oscarchan »

Thanks for your reply!
Thank you!
User avatar
dprojects
Posts: 721
Joined: Mon Mar 06, 2017 6:02 pm
Location: Poland
Contact:

Re: How can I modify a FreeCAD obeject's "Name"?

Post by dprojects »

You can remove the object and create new one with exact name. If there is no such name this will be working.

Thanks
Darek
github.com/dprojects

workbench for woodworking is available at: github.com/dprojects/Woodworking
Post Reply