How can I modify a FreeCAD obeject's "Name"?
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
How can I modify a FreeCAD obeject's "Name"?
- Attachments
-
- Snipaste_2022-05-11_10-05-36.png (7.55 KiB) Viewed 903 times
Thank you!
-
- Veteran
- Posts: 3179
- Joined: Thu Sep 24, 2020 10:31 pm
- Location: Hawaii
- Contact:
Re: How can I modify a FreeCAD obeject's "Name"?
You can't. You can assign your own Label. Names are assigned by FreeCAD. https://wiki.freecadweb.org/Object_name
-
- Posts: 4
- Joined: Wed May 11, 2022 8:22 pm
Re: How can I modify a FreeCAD obeject's "Name"?
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.)
# 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.)
Re: How can I modify a FreeCAD obeject's "Name"?
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