If I create a new property and then insert the text "Sketch003" targeting a sketch, can that reference later be invalid. I notice that when I bring a new Body into a existing model there can be changes to the sketch names. This makes since because you can't have two "sketch001". Is there something unique that I can use in a macro to keep track of the names? How do I keep the references valid.
Thanks
New property, storing a sketch name, can that name change?
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Re: New property, storing a sketch name, can that name change?
If you could assign the name during creation, yes, simply don't use the "Sketchxxxx" text, and make your own name.
But as some functions detect the "pattern" you should use to avoid problems "Sketch" and prefix, so probably something like "Sketch_n_" and a number will work, and it will not be overwritten by the automatic naming.
Apparently it works, with the example code in:
https://wiki.freecadweb.org/Sketcher_scripting
This line seems to reveal that object "Name" is correctly assigned and used as internal variable name.
Hope it helps.
Regards
Carlo D.
But as some functions detect the "pattern" you should use to avoid problems "Sketch" and prefix, so probably something like "Sketch_n_" and a number will work, and it will not be overwritten by the automatic naming.
Apparently it works, with the example code in:
https://wiki.freecadweb.org/Sketcher_scripting
Code: Select all
DOC =FreeCAD.ActiveDocument
sketch = DOC.addObject("Sketcher::SketchObject", "Sketch_u_001")
Code: Select all
ActiveSketch = App.getDocument('Unnamed').getObject('Sketch_u_001')
Regards
Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
Re: New property, storing a sketch name, can that name change?
Have you tried using the App::PropertyLink type?
Re: New property, storing a sketch name, can that name change?
No I haven't. I looked here and found this list:Roy_043 wrote
Have you tried using the App::PropertyLink type?
https://forum.freecadweb.org/viewtopic. ... 06#p316906
I'm always two steps behind, I'm guessing that if I use the correct Property type FreeCAD will change all the names for me as I bring in a model/Body . I never understood the PropertyLInk. Time for research.....
If anyone knows which type to use from the above link it could save some time.
Thanks
onekk, thanks. I'm hoping for something automated. That's interesting creating named sketches.
Re: New property, storing a sketch name, can that name change?
Roy_043, that works.
I used "App::PropertyLinkChild"
This works across Body and Part boundaries which is what I wanted. If the targeted Body object is deleted then the LinkChild data will be invalid and the object Link is removed, leaving a blank Property, perfect!
Thank you.
I used "App::PropertyLinkChild"
This works across Body and Part boundaries which is what I wanted. If the targeted Body object is deleted then the LinkChild data will be invalid and the object Link is removed, leaving a blank Property, perfect!
Thank you.