LDraw.org Discussion Forums

Full Version: Aligning parts using rotation scripts
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
(2021-12-23, 11:24)Milan Vančura Wrote: [ -> ]Another improvement is using current coordination system instead of the global one. To make script works for setups rotated in any way - just select a part, press "O" to get local coordination system, and continue with the script as usual.

OK, I was not able to find this in API reference easily, so I return to thisafter Christmas. Thanks again, David, and enjoy Christmas too!
(2021-12-23, 11:24)Milan Vančura Wrote: [ -> ]Another improvement is using current coordination system instead of the global one. To make script works for setups rotated in any way - just select a part, press "O" to get local coordination system, and continue with the script as usual.

Hi Milan,

thank you for your feedback and kind words.

In truth, requiring the user to explicitly set the axis of rotation as opposed to rotating around the appropriate axis for the current camera was a bit of laziness on my part. I imagine that I could use the LDCad API to work out the appropriate axis. However, making the axis user selectable meant it was less code/easier code for this initial release and thus I could release the code sooner. I'll add improved axis rotation to the To Do list for a subsequent release!

Regards,

David
(2021-12-23, 11:24)Milan Vančura Wrote: [ -> ]LDCAD does not allow neither user nor scripts work with snap objects, AFAIK. (And as I remember past conversations with Roland,it is not easy to implement in current LDCAD code.)
It is actually partial available in LDCad 1.6 (a leftover from my experiments which I forgot to remove).
The current 1.7 version has it all commented out, but I might put it back in again when picking 1.7 development up in my coming vacation.

(2021-12-23, 11:24)Milan Vančura Wrote: [ -> ]Another improvement is using current coordination system instead of the global one. To make script works for setups rotated in any way - just select a part, press "O" to get local coordination system, and continue with the script as usual.
This is something I can easily add, so I will add it to the ldc.view ( http://www.melkert.net/LDCad/docs/scriptAPI2#view ) object in the upcoming version.

It will only return the current matrix, as the LDCad api is supposed to be (very) low level only.
Thank you for this couple of great messages, Roland. I'm ready to test snap objects and give you feedback from user POV: having chance to work with snap objects is a base for several features I have in my mind for such a time... And many of them, I believe, are even easy to implement IF having an access to snap objects.


API to grid matrix makes David's script much more useful because not everything is aligned to original XYZ system, esp. in Technic models. With this API (and David's script using it), it becomes a matter of one click and one keypress for the user: select the base part and press 'O'.

David: this is how we can bend hinges as well, using your script together with my new helper part axis.dat.
Idea Arrow a video of hinge bending using David's script
Ah, sorry for forgetting the part itself. Here it is. It works with clip-bar pair, old 3-2 fingers hinge, hinge brick and new hinge plate - and everything what uses these kind of hinge connections. We may add more, of course. And, in future, maybe we will not need any help parts at all, we will be able to select snap objects directly. But, until then, this helper does its job.

Installation: put axis.dat in your directory with unofficial parts and rename shadow_axis.dat as axis.dat in your directory with unofficial shadow files, as set in your LDCAD configuration.
(2021-12-26, 11:59)Milan Vančura Wrote: [ -> ]Installation: put axis.dat in your directory with unofficial parts and rename shadow_axis.dat as axis.dat in your directory with unofficial shadow files, as set in your LDCAD configuration.

It being an unofficial helper part, you can also put the snap meta's in the part itself (no shadow needed).

LDCad processes parts as a single file after appending the shadow content to it.
(2021-12-27, 23:02)Roland Melkert Wrote: [ -> ]It being an unofficial helper part, you can also put the snap meta's in the part itself (no shadow needed).

LDCad processes parts as a single file after appending the shadow content to it.
Thanks, Roland, for this detail. The merged file is attached to this message.

For me, this part makes an important improvement to David's script because, so far, I did not know any way how to bend hinges in LDCAD like it was possible in SR3D editor. What about adding David's script to the LDCAD default set of scripts? Maybe with this axis part as well? Or should I improve the axis part somehow? Add more snap infos?

BTW, the axis part has its usage in different cases as well, for example illustrations like this one. Maybe we can add it to Helper parts when/if the standard for them is agreed.
Error loading submodel 1 4-4edge.dat.
File: C:\Users\...\Downloads\1226\axis.lddptmp
Line #37
Line: 1 16  0 -12.5 2.5  0 1 0  0 0 0.5  1 0 0  1 4-4edge.dat


Error loading submodel 1 4-4disc.dat.
File: C:\Users\...\Downloads\1226\axis.lddptmp
Line #38
Line: 1 16  0 -12.5 2.5  0 -1 0  0 0 -0.5  1 0 0  1 4-4disc.dat


There's a single 1 to much in those lines.
(2021-12-30, 16:39)Magnus Forsberg Wrote: [ -> ]There's a single 1 to much in those lines.

Ah, such a stupid mistake of mine, thank you for pointing this out, Magnus.
I attach a new version which is, I hope, both better looking and with more readable source.

I made no changes in snap info so it still snaps to hinges types mentioned above. It works for me and expands David's script capabilities exactly in a way I looked for. I'm interested both in your experience and your tips for this helper part improvement.

For example, the naming of the "subpart" definitely does not follow any convenience simply because I do not know them, I'm not a part author. I just try my best to help Smile But this is the last point, I believe - if there is an interest to add this part (and subpart) to standard helper parts (and when the Standard Committee agrees on them). So far, please test this and tell us tips for improvements or your experiences or that I made another stupid mistake etc. Big Grin
8 Align parts / Linkage Animations, revised

This is a follow-up to provide information about revised scripts for aligning parts and the linkages animation. The appropriate scripts can be downloaded from BrickSafe and installed as per the original description albeit that the installation will also install the script linkages.lua into the sub-directory named global.

8.1 Align Parts / Rotation around current view plane

The only changes related to aligning parts is changes to the align parts / Rotation Parameters dialog. Two “choice” dialogs now exist. The first (see Figure 24) allows aligning the parts according to the currently active view plane.

[Image: 100_axis_of_rotation.png]
Figure 24 – Rotate around view plane option

Note that if the current view plane option is selected, ensure that when a part alignment macro is invoked the appropriate view plane is active. Otherwise, your results may not be as expected.

8.2 Part Selection Sequence

The second dialog displayed when the Rotation Parameters dialog is invoked is shown in Figure 25. This allows a user to decide the sequence that parts are to be selected when running the part alignment script. If you don’t like the default option, make a one-time change to the script align parts.lua and change the initial value of the variable part_selection_order_option_mi.

[Image: 107_alignment_part_selection_sequence.png]
Figure 25 – Alignment Part Selection Sequence

8.3 Linkage Animation Changes

The Linkages animation have been modified in a couple of ways. Firstly (and hopefully invisible to anyone), the animations now make use of the same compound rotation.lua code module as that used by the part alignment scripts. There are a number of other changes and additions which are perhaps more visible.

If  you install the linkages module as a custom/global script, your LDCad menu structure will look something like that shown in Figure 26.

[Image: 101_linkages_menu_00.png]
Figure 26 - Linkages added to scripts Global menu

8.4 Linkage Menu Change

Logic has been added for a crank-slider animation. As there are now multiple animations available, a menu option named Choose linkage animation has been added for the user to identify which animation they want to run (refer to Figure 27). Selecting this menu option causes the dialog shown in Figure 28 to be displayed.

[Image: 102_linkages_menu_01.png]
Figure 27 - Linkage menu

[Image: 103_linkages_animation_choose.png]
Figure 28 - Animation selection

Further menu options allow for;
  • identifying which parts are involved in the animation (menu option Pick the animation parts which was previously named 4 bar linkage selection)
  • identifying the sequence in which the animation parts are being selected (Figure 29). This is equivalent to that for the part alignment logic (refer to section 8.2) but is pertinent to the linkage animations.

[Image: 104_linkages_part_selection_sequence.png]
Figure 29 - Animation part selection sequence

8.5 Crank Slider Animation

Code has been added for the animation of a crank-slider mechanism. The default part selection sequence is illustrated in Figure 30. The axes have been highlighted in the screenshot to illustrate which axis will be used when the animation is run using the current view plane as the rotation axis.

[Image: 105_linkages_crank_selection.png]
Figure 30 - Crank Slider Default Part Selection Sequence

The model used in this animation was authored by Walt White and is available on rebrickable.com.

The result of running the animation is shown here:
Pages: 1 2 3