Automatic naming of linked bodies (instance naming vs source naming)

Discussion about the development of the Assembly workbench.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
gntech
Posts: 56
Joined: Tue May 23, 2017 9:03 am

Automatic naming of linked bodies (instance naming vs source naming)

Post by gntech »

Is it possible to get automatic naming of linked bodies so that the name of the links follow the source in some way?

For example, I have made a part that I call "Beam" and then I create a link to that part using alt+drag method. I would then like that the links get a name that shows the connection with the source part like "Instance name (Beam)". And if I chose to rename the source part to Truss then the linked instance will change its name to "Instance name (Truss)"

OS: KDE neon User Edition 5.17 (KDE//usr/share/xsessions/plasma)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.18714 (Git) AppImage
Build type: Release
Branch: master
Hash: a7ad04ba4aefb486fbc5e7c68da3dd488443b08c
Python version: 3.7.3
Qt version: 5.12.5
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: Swedish/Sweden (sv_SE)
chrisb
Veteran
Posts: 54280
Joined: Tue Mar 17, 2015 9:14 am

Re: Automatic naming of linked bodies (instance naming vs source naming)

Post by chrisb »

The label is aware of Expressions. I succeeded in referencing another label, and I can even double it with an expression such as
Box.Label + Box.Label, which seemed to have worked well. However, this has three drawbacks:
- I didn't manage to add a constant string
- The label didn't update automatically
- A recompute crashed FreeCAD
Perhaps you can use a spreadsheet for this.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
gntech
Posts: 56
Joined: Tue May 23, 2017 9:03 am

Re: Automatic naming of linked bodies (instance naming vs source naming)

Post by gntech »

Below is a mockup of what I am looking for.

The parts are named:

Code: Select all

Instance name (partname)
Instance name is what is changed on a rename. The source partname information is sort of already available, see the red ring.
freecad_name_link.png
freecad_name_link.png (58.71 KiB) Viewed 1978 times
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: Automatic naming of linked bodies (instance naming vs source naming)

Post by vocx »

gntech wrote: Sun Nov 17, 2019 7:16 pm ...
The parts are named:

Code: Select all

Instance name (partname)
...
I think this was like this some commits ago. Since the App::Link was merged quite a few changes have occurred. I think at some point Links did have the sentence "Link to something" in the tree view. It's after all a stylistic change, because as you notice, the real object is mentioned in the LinkedObject property.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
gntech
Posts: 56
Joined: Tue May 23, 2017 9:03 am

Re: Automatic naming of linked bodies (instance naming vs source naming)

Post by gntech »

I think it gives a nice overview to be able to see what each part really is directly in the tree. But I realise it is a matter of personal preference.
User avatar
Zolko
Veteran
Posts: 2213
Joined: Mon Dec 17, 2018 10:02 am

Re: Automatic naming of linked bodies (instance naming vs source naming)

Post by Zolko »

gntech wrote: Sun Nov 17, 2019 7:16 pm Instance name is what is changed on a rename.
No: a FreeCAD object has a Name and a Label. The Name is set at creation time and cannot, ever, be modified. The Label is set identical to Name at creation time, but can be modified later. This is also true for App::Link. If you create an App::Link and then assign a linked object to it, the name of the App::Link — the instance — will be Link, and subsequent links will be called Link001, Link002 .... Whatever the object you assign to it later, you can only change the link's Label. The Label is what appears in the tree, the Name is what is used to access an object (with getObject(obj.Name) )

If you want to set the Name of the App::Link instance, you first have to select the object you want to link and then create the link to that object with the Name of the link instance set to the object's Name.
try the Assembly4 workbench for FreCAD — tutorials here and here
gntech
Posts: 56
Joined: Tue May 23, 2017 9:03 am

Re: Automatic naming of linked bodies (instance naming vs source naming)

Post by gntech »

Thanks for the clarification! So the name can be considered an unique identifier of the part or link. And the label is the user given "name".
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: Automatic naming of linked bodies (instance naming vs source naming)

Post by vocx »

gntech wrote: Thu Nov 21, 2019 5:27 pm Thanks for the clarification! So the name can be considered an unique identifier of the part or link. And the label is the user given "name".
Yes. Every "DocumentObject", objects that you see in the tree view, must have a unique Name. If you try to name another object with that same name, its name will be incremented by a counter, like Solid and Sollid001. Names only support alphanumeric characters and the underscore.

The Label is the user defined name, and can use special unicode characters, like spaces and accented letters. There is a preference that controls whether the label can be repeated or not. By default labels cannot be repeated, so they are also incremented numerically if the same Label is used.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
Post Reply