SylvainLS

lxf2ldr.html, the even more awesome lxf2ldr

Recommended Posts

Hi all,

I just released an extra portable version of lxf2ldr: lxf2ldr.html  (still on gitlab, next to its brother, and also in GPLv3+).

Yes, .html like in HTML/ECMAScript (aka JavaScript) but it’s totally local and self-contained!

No compilation, no dependencies, no web server or arcane application (well, except for a d/recent web browser).

Just download the zip (or tarball…), unpack it somewhere and open the file lxf2ldr.html in your browser.

(See the senseless green/yellow coloured bar ?  Click on the little cloud just below, on the right, just next to “Find File.”)

 

Okay, okay, the look is spartan but it gets the job done.  Tell me what you think… or not :wink:

 

BTW, this is the initial release, I haven’t tested all the cases / stumbled upon all the :cry3: of the language (two days on this and I know why I hadn’t touched JavaScript since the last century), so any issue, bug, glitch is welcome.

Edited by SylvainLS
typo, in the title of course

Share this post


Link to post
Share on other sites
54 minutes ago, SylvainLS said:

(See the senseless green/yellow coloured bar ?  Click on the little cloud just below, on the right, just next to “Find File.”) 

Useful reminder. Almost "invisible" download button I desperately search each time I need something on github...

Even more awesome indeed! Worked fine for me for the few files I converted. The only thing I noticed - but I think that the problem comes from ldraw.xml - is that the 28t differential (62821) is rotated 90°, making the middle bevel gear float in mid air.

Share this post


Link to post
Share on other sites

Thanks and, er, oopsie?  Yes, a misktake in ldraw.xml.  One of the parts that checked too quickly back then.  I’ll correct it soonish (there’s already a couple new parts in the queue).

Share this post


Link to post
Share on other sites

@supertruper1988 PM received and answered :classic:

To everybody: corrections have been uploaded this afternoon, along with latest version of ldraw.xml.  I blame typos and JavaScript’s insanity :grin:  Well, okay, I blame myself for not understanding and not having tested this translation enough :ashame:

Share this post


Link to post
Share on other sites

New version available!

As it appears some people loved LDD’s building instructions, I added an option to use them (when present) to make steps.

Note that there’s no submodels and LDD’s groups are lost if you use this option.

It’s here.

And remember the repository keeps an up-to-date ldraw.xml file too (so download it when I update ldraw.xml).

 

Share this post


Link to post
Share on other sites

I looked at it a little bit more (I used a more complex example file :grin:).

It appears the LDD steps are in a somewhat meaninigful hierarchy.  That means we can use them for submodels (and subsubmodels…).  But LDD also puts each part in a step (or at least shows parts one by one).  So that makes for a “tétrachiée” (lot) of steps and subsub…subsubmodels.

Here is the results of the two options for a small example: no submodels and with submodels.

What do you think?  (I’d rather not make the choice a suboption.)

Share this post


Link to post
Share on other sites

@SylvainLS

Do you remember hrontos post about using LDD groups to creare building instructions? (I'm quite sure the references are still available in the Section Index)
As you surely know, the lxfml file has separate sections for groups and instructions. Hrontos created a script to generate BI starting from LDD Groups, a very helpful tool that helped to make some sense to LDD instructions. Obviously, as the feature was not supported by LDD, the so built Building Instructions section in lxfml file was destroyed as son as the file was opened and saved again in LDD.

How does your script works? Why preserving BI groups and submodels are removed?

Edited by Calabar

Share this post


Link to post
Share on other sites

I do remember hrontos’ technique now you talk about it :grin:  I never used it though (simpler to use LDraw steps).

LDD steps and groups are hierarchical but they are separate hierarchies.  LDD groups can span several steps whereas LDraw submodels have steps but their parts can’t be spread into their supermodel steps.  So, when converting to LDraw, we can either conserve LDD groups by converting them into submodels, or conserve the steps and break the groups.  It could happen that all the parts of a LDD group end up in LDD’s instructions in only one step (no more than four parts then), or strictly consecutive steps or in a strict hierarchy of steps, but I’m pretty sure the only way to see that happening is to use hrontos’ technique.

My programs simply read the three interesting parts of the LXF in order: the bricks, the groups, the instructions.
The groups are converted to submodels.  The parts not in a group are put in the main model.
If there are instructions and the user chooses to:

  • in the flat version, the groups are broken and the parts are converted in the order they are referenced in the instructions, each in an LDraw step (to simulate how LDD shows them),
  • and in the hierarchical version, the groups are broken and each step is converted into a submodel, with its parts/substeps in the same order and each in its LDraw step.

Flexible parts (one part in LDD) are each converted to a submodel of multiple LSync parts.  Assemblies (like minifigure torso) (one part with multiple subparts in LDD) are converted into submodels to keep them grouped in LDraw.

 

So, if you used hrontos’ technique, the hierarchy of groups and the hierarchy of steps are the same.  If you choose not to use the instructions, the conversion will only give you the groups, in the order they appear in the LXF (creation order), and if you choose to use the instructions in the conversion, in the flat version, you loose the submodels, and in the hierarchical version, you get the groups and their order as hrontos’ script made them.

Share this post


Link to post
Share on other sites

Okay, so after the numerous and varied feedback (crickets…), I decided to upload the hierarchical version as it keeps more information and information is important.

 

Share this post


Link to post
Share on other sites

Ok, tell me if I've understood.
LDD maintain both group and BI hierarchies in the lxfml file in two separate areas. LDRAW instead maintain a single tree sharing both the informations (steps are included among submodel info).
Unfortunately LDRAW structure has some limit (a part can't belong to a subgroup and to its parent group too), so it is not possible to maintain both the grups and the BI info from a lxfml file.

What about to output two files? Something like modelname.ldr and modelname-BI.ldr?

Share this post


Link to post
Share on other sites
25 minutes ago, Calabar said:

Ok, tell me if I've understood.
LDD maintain both group and BI hierarchies in the lxfml file in two separate areas. LDRAW instead maintain a single tree sharing both the informations (steps are included among submodel info).
Unfortunately LDRAW structure has some limit (a part can't belong to a subgroup and to its parent group too), so it is not possible to maintain both the grups and the BI info from a lxfml file.

Exactly.

LDraw is a strict hierarchy.  It’s simple and elegant: primitives, subparts, parts, submodels, models, supermodels, all have the same format.  But you can have only one hierarchy.

When you edit a LDraw submodel, you can move or add parts so that they collide with their sibling submodels.  Or if two submodels are linked by a hinge, you better have that hinge at the same level as the submodels: if it’s in one of the submodels, rotating it won’t hinge the other submodel (at least, that’s how it works in Studio).

 

33 minutes ago, Calabar said:

What about to output two files? Something like modelname.ldr and modelname-BI.ldr?

Well, I think it’s simpler to just run the conversion twice: once with the BI option checked, and once with the option unchecked.  Not many people are interested in both.

Share this post


Link to post
Share on other sites
2 minutes ago, SylvainLS said:

Well, I think it’s simpler to just run the conversion twice: once with the BI option checked, and once with the option unchecked.  Not many people are interested in both. 

Oh, ok, I understood that you removed the option to create the BI version!
I thought something like using a checkbox "create BI file too" that create both files, but actually run the software twice do the trick!

Share this post


Link to post
Share on other sites
1 hour ago, Calabar said:

Oh, ok, I understood that you removed the option to create the BI version!

No, I only replaced the “flat BI” version with the “hierarchical BI” version.  But the “group” version is still the main one (most useful IMHO). 

 

1 hour ago, Calabar said:

I thought something like using a checkbox "create BI file too" that create both files, but actually run the software twice do the trick!

Well, if there’s no BI, both files would be the same, and presenting two files to the user might be confusing, especially when they are the same.  So I prefer to have the option “use BI if there are BI.”

Share this post


Link to post
Share on other sites

hi, i know i'm necrobumping this thread but i would ask if is still possible to request a modification in this utility (sorry i can't program...)

with my old hardware, i'm an happy user of ldd and lpub...
is it possibile, as an option, to create submodels in reverse order respect to the groups order?
this would be very useful if you build a model in ldd and then create groups dismantling it so, when converted, the submodels list follows the right order of construction.
now i do this editing the mpd with a spreadsheet but it would be much easier if this utility will do the job.

thanks, andrea.

Share this post


Link to post
Share on other sites

Hi,

Could you give an example file so I can understand how you’re using groups?

Share this post


Link to post
Share on other sites
Posted (edited)

thanks for your reply!

first i build the full model with ldd.

then i create step/groups in reverse order of construction removing pieces.

this is a simple pyramid. i build the blue floor, then the red floor and finally the yellow one. i create groups in reverse order, selecting bricks then hiding them.

this is what i get when i convert pyr.lxf with your utility:

0 FILE pyr_lxf
1 16 -30.000001192092896 -47.999998927116394 -150 1 0 0 0 1 0 0 0 1 pyr_lxf_0
1 16 -30.000001192092896 -23.999999463558197 -170.00000476837158 1 0 0 0 1 0 0 0 1 pyr_lxf_1
1 16 -30.000001192092896 0 -190.00000953674316 1 0 0 0 1 0 0 0 1 pyr_lxf_2

0 FILE pyr_lxf_0
1 14 30 -24 10 1 0 0 0 1 0 0 0 1 3001.dat

0 FILE pyr_lxf_1
1 4 30 -24 10 1 0 0 0 1 0 0 0 1 3001.dat
1 4 30 -24 50.000009536743164 1 0 0 0 1 0 0 0 1 3001.dat

0 FILE pyr_lxf_2
1 272 30 -24 10 1 0 0 0 1 0 0 0 1 3001.dat
1 272 30 -24 49.99999761581421 1 0 0 0 1 0 0 0 1 3001.dat
1 272 30 -24 90.00000715255737 1 0 0 0 1 0 0 0 1 3001.dat


the submodels/groups follow the reverse order, top-down (0-1-2) in this example.

as an option, it should be:

 

0 FILE pyr_lxf

1 16 -30.000001192092896 0 -190.00000953674316 1 0 0 0 1 0 0 0 1 pyr_lxf_2

1 16 -30.000001192092896 -23.999999463558197 -170.00000476837158 1 0 0 0 1 0 0 0 1 pyr_lxf_1
1 16 -30.000001192092896 -47.999998927116394 -150 1 0 0 0 1 0 0 0 1 pyr_lxf_0

(the rest is the same)
so now submodels/groups are in down-top order (2-1-0), following the right way of build it.

actually, i also add 0 STEP command between every submodel so i can check if everything is ok with ldcad and finally pass the file to lpub and create bi.

this is the final result:

0 FILE pyr_lxf
1 16 -30.000001192092896 0 -190.00000953674316 1 0 0 0 1 0 0 0 1 pyr_lxf_2
0 STEP
1 16 -30.000001192092896 -23.999999463558197 -170.00000476837158 1 0 0 0 1 0 0 0 1 pyr_lxf_1
0 STEP
1 16 -30.000001192092896 -47.999998927116394 -150 1 0 0 0 1 0 0 0 1 pyr_lxf_0

0 FILE pyr_lxf_0
1 14 30 -24 10 1 0 0 0 1 0 0 0 1 3001.dat

0 FILE pyr_lxf_1
1 4 30 -24 10 1 0 0 0 1 0 0 0 1 3001.dat
1 4 30 -24 50.000009536743164 1 0 0 0 1 0 0 0 1 3001.dat

0 FILE pyr_lxf_2
1 272 30 -24 10 1 0 0 0 1 0 0 0 1 3001.dat
1 272 30 -24 49.99999761581421 1 0 0 0 1 0 0 0 1 3001.dat
1 272 30 -24 90.00000715255737 1 0 0 0 1 0 0 0 1 3001.dat

i'm sorry i can't attach an lxf file, the interface allow me only images under 100k.

thanks, andrea.

pyr.jpg

Edited by spinox

Share this post


Link to post
Share on other sites

Okay.  I don’t think that’s something many people will use and so making an option for that is too much work.  So here’s a solution just for you:

Open lxf2ldr.js in a simple editor (Notepad or such), go to line 500 and replace “push” by “unshift”, the line will then be:

  siblings.unshift( g );

This builds the list in reverse order.

Share this post


Link to post
Share on other sites
Posted (edited)

WOW! It works! A real-time solution!

Thank you very much, this helps me a lot!

You're a master programmer!

Edited by spinox

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.