New property, storing a sketch name, can that name change?

Need help, or want to share a macro? Post here!
Post Reply
freedman
Veteran
Posts: 2653
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

New property, storing a sketch name, can that name change?

Post by freedman »

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
User avatar
onekk
Veteran
Posts: 3216
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: New property, storing a sketch name, can that name change?

Post by onekk »

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

Code: Select all

DOC =FreeCAD.ActiveDocument
sketch = DOC.addObject("Sketcher::SketchObject", "Sketch_u_001")
This line seems to reveal that object "Name" is correctly assigned and used as internal variable name.

Code: Select all

ActiveSketch = App.getDocument('Unnamed').getObject('Sketch_u_001')
Hope it helps.

Regards

Carlo D.
My English and Italian Scripting Guide https://github.com/onekk/freecad-doc.
My Blog: https://onekk-maker.blogspot.com/

To help development see on GitHub Page

For enquiry about customized FC Scripting job PM me.
User avatar
Roy_043
Veteran
Posts: 5453
Joined: Thu Dec 27, 2018 12:28 pm

Re: New property, storing a sketch name, can that name change?

Post by Roy_043 »

Have you tried using the App::PropertyLink type?
freedman
Veteran
Posts: 2653
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: New property, storing a sketch name, can that name change?

Post by freedman »

Roy_043 wrote
Have you tried using the App::PropertyLink type?
No I haven't. I looked here and found this list:
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.
freedman
Veteran
Posts: 2653
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: New property, storing a sketch name, can that name change?

Post by freedman »

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.
Post Reply