LDraw.org Discussion Forums
LDCad Scripting: cannot get group position/orientation - Printable Version

+- LDraw.org Discussion Forums (https://forums.ldraw.org)
+-- Forum: LDraw Programs (https://forums.ldraw.org/forum-7.html)
+--- Forum: LDraw Editors and Viewers (https://forums.ldraw.org/forum-11.html)
+--- Thread: LDCad Scripting: cannot get group position/orientation (/thread-22120.html)



LDCad Scripting: cannot get group position/orientation - Greg Montgomery - 2017-03-20

Hello everybody,

I have built a LEGO model comprising of submodels, groups and some scripting functions.
The problem is my local script in LDCad cannot determine the position or orientation of a (toplevel) group.
Calling group:getPosOri() always returns the identity matrix (0 0 0 1 0 0 0 1 0 0 0 1).

these are the relevant lines:
Code:
local mainsf = ldc.subfile()
local mygroup = mainsf:getGroup('MyGroup')
local posori = mygroup:getPosOri()  --> identity matrix, whereas the editor window in LDCad shows clearly different values

If required I can also provide a small working example.

Can someone please explain what is going wrong here...  Huh

using LDCad 1.6 Beta 2a

Edit: model and script added


RE: LDCad Scripting: cannot get group position/orientation - Roland Melkert - 2017-03-20

Welcome to the forum Greg,

Things to check:
- Are you sure there is no relative grid active when checking the group posori in the editor as scripts always use absolute space.
- Is the matrix you expecting the one the groups main part uses, as groups always use the first part as its ori source, same goes for the position part unless the group uses a custom center.

I did a quick test and it seems to work fine for me using a rotated group, if you post or mail me your ldr/lua files I might be able to tell more.


RE: LDCad Scripting: cannot get group position/orientation - Greg Montgomery - 2017-03-20

I have attached 2 files to the OP (rename the script file to ".lua" first).
Since this is the most basic example, I feel something must be terribly wrong in my editor / model / script.

Yes, the (nested) editor uses absolute grid orientation (ABS), switching to REL shows the position of the currently selected group as (0, 0, 0).
Switching back to ABS shows the position of the first item of the group again.

Even though the bottom right in the editor always says '(rel) grid position  X; Y; Z'


RE: LDCad Scripting: cannot get group position/orientation - Roland Melkert - 2017-03-20

(2017-03-20, 10:36)Greg Montgomery Wrote: I have attached 2 files to the OP (rename the script file to ".lua" first).
Since this is the most basic example, I feel something must be terribly wrong in my editor / model / script.

It is a bug, i just posted working results (removed it again) as it seemed to work for me at first glance.

But I just discovered that is because I used animation mode before testing this.

Thanks for reporting this very weird bug

edit: found the cause of this bug, it is best to not use group posOri io from macros until the next version. It is using the animation 'anti rounding error' stuff which you don't want in macros, forgot all about that Smile Sorry about that.


RE: LDCad Scripting: cannot get group position/orientation - Greg Montgomery - 2017-03-21

Alrighty then, thanks you for your help