realthunder wrote: Ping
Position and orientation in the reference frame of a LCS
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Re: Position and orientation in the reference frame of a LCS
+1 to me, @rt, is there a reason why App::Link do not have this method?
follow my experiments on BIM modelling for architecture design
-
- Veteran
- Posts: 2190
- Joined: Tue Jan 03, 2017 10:55 am
Re: Position and orientation in the reference frame of a LCS
I actually think 'GlobalPlacement' should be deprecated because 'Link' is introduced. Just imaging Link A that links to a Group that contains another Link B, when you ask for the global placement of Link B, which one should it return, because Link B will appear in two placements in the 3D view. This problem extends to all objects, because the same object can appear in multiple places through Link.
The solution is to always use the full object path to query for the placement. You can obtain the object path by passing an extra argument to Gui.Selection.getSelectionEx(), the path is available through attribute SubElementNames. You can then pass the path to DocumentObject.getSubObject() to obtain the accumulated global placement.
The solution is to always use the full object path to query for the placement. You can obtain the object path by passing an extra argument to Gui.Selection.getSelectionEx(), the path is available through attribute SubElementNames. You can then pass the path to DocumentObject.getSubObject() to obtain the accumulated global placement.
Code: Select all
for sel in Gui.Selection.getSelectionEx('',0):
for path in sel.SubElementNames if sel.SubElementNames else ['']:
placement = sel.Object.getSubObject(path, retType=3) # retType 3 returns the placement. Check the doc string for more info
print('%s.%s -- %s' % (sel.Object.Name, path, placement))
Re: Position and orientation in the reference frame of a LCS
Makes no real sense to me.realthunder wrote: ↑Mon Feb 07, 2022 1:31 am I actually think 'GlobalPlacement' should be deprecated because 'Link' is introduced. Just imaging Link A that links to a Group that contains another Link B, when you ask for the global placement of Link B, which one should it return, because Link B will appear in two placements in the 3D view. This problem extends to all objects, because the same object can appear in multiple places through Link.
You should consider "object" in the meaning of "document object", not "solid shape".
An object can appear several time in a document, but not at different placements (or there is a flaw somewhere).
-
- Veteran
- Posts: 2190
- Joined: Tue Jan 03, 2017 10:55 am
Re: Position and orientation in the reference frame of a LCS
Just create a Part container, and add a cube inside, and then create a link to the Part container, and finally move the link to somewhere else. Now you have the same cube object at two placements. That's how complex hierarchical models can be handled efficiently. The STEP standard uses similar 'object path' concenpt to uniquely identify instance in an assembly.
-
- Veteran
- Posts: 3194
- Joined: Thu Sep 24, 2020 10:31 pm
- Location: Hawaii
- Contact:
Re: Position and orientation in the reference frame of a LCS
I think we are all talking past each other. Above we end up with two instances of the same object at different locations in 3D. If you interrogate the two instances, they have different global placements. Why not provide the link instances with a getGlobalPlacement() method - even if all it does is repeat what is found in Object.getSubObject(path, retType=3)?realthunder wrote: ↑Tue Feb 08, 2022 2:14 am Just create a Part container, and add a cube inside, and then create a link to the Part container, and finally move the link to somewhere else. Now you have the same cube object at two placements. That's how complex hierarchical models can be handled efficiently. The STEP standard uses similar 'object path' concenpt to uniquely identify instance in an assembly.
If you deprecate getGlobalPlacement(), a lot of code will break - but as it stands, it only works some of the time. Or am I still missing some situation where this won't work?
-
- Veteran
- Posts: 2190
- Joined: Tue Jan 03, 2017 10:55 am
Re: Position and orientation in the reference frame of a LCS
The point I am trying to make is that the current 'bottom up' use case of 'getGlobalPlacement()' is ill defined, where the user code expects to obtain the global placement from a bottom leaf object. What I am saying is that you should do this from the top. Even if you are just suggesting a better name of an API for getting global placement, using the old name (that applies in a different use case) would just confuse user.edwilliams16 wrote: ↑Tue Feb 08, 2022 3:05 am I think we are all talking past each other. Above we end up with two instances of the same object at different locations in 3D. If you interrogate the two instances, they have different global placements. Why not provide the link instances with a getGlobalPlacement() method - even if all it does is repeat what is found in Object.getSubObject(path, retType=3)?
If you deprecate getGlobalPlacement(), a lot of code will break - but as it stands, it only works some of the time. Or am I still missing some situation where this won't work?
Re: Position and orientation in the reference frame of a LCS
Imho getGlobalPlacement still make Sense when you have to deal with the DocumentObjects, but looks broken when you use It in Gui environment.
I can speak about Draft cause it's the only part of the codebase that i know pretty well. All the commands like move, rotate, etc compute the global placement in the "App" module of the function. This Is still valid when scripting, but result in broken behavior when in Gui and links are involved.
So why not make It clearer and have a:
- getGlobalPlacement of the documentObject
- getVisualPlacement method of the selectionobject?
I can speak about Draft cause it's the only part of the codebase that i know pretty well. All the commands like move, rotate, etc compute the global placement in the "App" module of the function. This Is still valid when scripting, but result in broken behavior when in Gui and links are involved.
So why not make It clearer and have a:
- getGlobalPlacement of the documentObject
- getVisualPlacement method of the selectionobject?
follow my experiments on BIM modelling for architecture design
Re: Position and orientation in the reference frame of a LCS
Thanks for this. See what you need now. Need to rethink about it.realthunder wrote: ↑Tue Feb 08, 2022 2:14 am Just create a Part container, and add a cube inside, and then create a link to the Part container, and finally move the link to somewhere else. Now you have the same cube object at two placements. That's how complex hierarchical models can be handled efficiently. The STEP standard uses similar 'object path' concenpt to uniquely identify instance in an assembly.
-
- Posts: 437
- Joined: Wed Sep 15, 2010 9:38 am
Re: Position and orientation in the reference frame of a LCS
I wish I had read this piece of code before writing the GetGlobalPlacement macro!realthunder wrote: ↑Mon Feb 07, 2022 1:31 am I actually think 'GlobalPlacement' should be deprecated because 'Link' is introduced. Just imaging Link A that links to a Group that contains another Link B, when you ask for the global placement of Link B, which one should it return, because Link B will appear in two placements in the 3D view. This problem extends to all objects, because the same object can appear in multiple places through Link.
The solution is to always use the full object path to query for the placement. You can obtain the object path by passing an extra argument to Gui.Selection.getSelectionEx(), the path is available through attribute SubElementNames. You can then pass the path to DocumentObject.getSubObject() to obtain the accumulated global placement.
Code: Select all
for sel in Gui.Selection.getSelectionEx('',0): for path in sel.SubElementNames if sel.SubElementNames else ['']: placement = sel.Object.getSubObject(path, retType=3) # retType 3 returns the placement. Check the doc string for more info print('%s.%s -- %s' % (sel.Object.Name, path, placement))
I agree with realthunder in the sense that it's better to not have a feature that doesn't work as expected.
Gaël
Re: Position and orientation in the reference frame of a LCS
Se more thoughts? To me this is quite a crucial topic and would be nice if we could have a consistent api exposed to the developers...
follow my experiments on BIM modelling for architecture design