LDraw.org Discussion Forums
XML to LDR - Printable Version

+- LDraw.org Discussion Forums (https://forums.ldraw.org)
+-- Forum: LDraw Programs (https://forums.ldraw.org/forum-7.html)
+--- Forum: LDraw File Processing and Conversion (https://forums.ldraw.org/forum-22.html)
+--- Thread: XML to LDR (/thread-8501.html)

Pages: 1 2

XML to LDR - Arthur Sigg - 2013-03-06

Hi at all,

Does anyone know if it possible to convert a XML file generated by pictobrick to a LDR file ?
pictobrick's XML shows the bricks (plates) in any row as a sequence of parts, row for row.
Such a conversion must be easy but browsing around for hours I couldn't finding such a tool.

Thanks for any help,

Arthur Sigg

Re: XML to LDR - Tim Gould - 2013-03-06

Hi Arthur,

I'm not aware of any such thing. I guess any tool would have to come with standardised configuration files too.


Re: XML to LDR - Rolf Osterthun - 2013-03-07

Hey Arthur,

yes, generally it is possible. I wrote a small test application that converts a XML file generated by pictobrick ("LEGO side view") into a LDraw File. But currently the application is not in a shareable state.


Re: XML to LDR - Michael Heidemann - 2013-03-07

I did not yet installed that application. So I went to the homepage and found the following screenshot:[Image: screenshot_29.jpg]

So there seems to be no information about part number and also the colors are different from ours. If we have a table to match those entries to our numbers it should be possible to quickly code such a tool.

Ok, now I have downloaded that application and did a quick test. The output for our parts are better Smile.
So the part information is given (3024.dat). But from where are the color numbers?
Also I need to figure out where to place the parts, as no information is given about that.

Re: XML to LDR - Rolf Osterthun - 2013-03-07

Hey Michael,

all predefined colors can be found in the source files, which are free available:
DataManagement.java Wrote:legoTop.setColor("11_Black",0,0,0);
But you can define colors yourself!

The xml-file contains the data "row by row top down and from the left to the right". The xml-file represents one huge matrix. If you only use LEGO plates 1x1 each entry (tag) in the matrix (the xml-file) would be filled. If you use bigger parts, only the upper left most matrix entry for each part is filled. All overlayed matrix entries will appear as an empty tag.

Here is a pseudo code to convert the xml-file to LDraw:
read xmlFile
foreach row in xmlFile
    x = 0 // each row starts at the left
    foreach unit in row
        if unit is not empty
            color = translateColor
            part = translateElement
            offest = calculateOffset(part) // the origin of the ldraw parts is not the upper left most stud
            write ldrFile "1 color x+offset y 0 1 0 0 0 1 0 0 0 1 part.dat"
        x += 20 // for each horizontal entry (unit) in the matrix, we have to shift right
    y += 8 // for each vertical entry (row) in the matrix, we have to go down

You would have to translate the given color and the given element. For this you can implement some kind of dictionary. But also parts can be defined by yourself! This means: if you work with the predefined colors and elements a conversion is possible. But once there is a userdefined element, an "always working" conversion would become impossible.

Currently I have not detected any difference between the xml-files for "LEGO in top view" and "LEGO in side view". Only some entries might give a hint (e.g. LEGO plate 4x4 would not appear in side view).


Re: XML to LDR - Michael Heidemann - 2013-03-07

"Top View" and "Side View" needs at least another value in the following line:
y += 8 // for each vertical entry (row) in the matrix, we have to go down
Thank you for the moment for the detailed information. I am sure I will have some more questions when I have some code already Smile.

Hmmm. I can not see any information in the xml file from that I can decide top-view or side-view. As long as only base elements are used (1 x 1) it only will distort the picture in the height.
It is getting more complicated than on the first view I would expect.

Re: XML to LDR - Arthur Sigg - 2013-03-07

The information about the actual selected view (and other informations) can be found in: configuration.html
As an alternative to the XML file pictoprick also generates a TEXT file: buildingsinstructions.html
All to find in the working directory folder under "data" if related outputdata has been selected in pictobrick

Perhaps it helps a little bit ...

Re: XML to LDR - Rolf Osterthun - 2013-03-09

Hey Arthur,

the mentioned test application has grown to a small console application. It is implemented in .Net 3.5 C# and compiled for windows. You can download it at www.digital-bricks.de/download/PicToBrick2LDraw.zip.

This application is not very intelligent. If you use it you will have to define whether your mosaic.xml file contains data for “LEGO in top view” or “LEGO in side view”. And it knows only the predefined colors and parts.

PicToBrick2LDraw.exe inputFile [-top|-side]
-top : The content of the inputFile is 'LEGO in top view'.
-side : The content of the inputFile is 'LEGO in side view'. This is default.

For example:
PicToBrick2LDraw.exe Y:\gimli_002\data\mosaic.xml –top
You would get a file Y:\gimli_002\data\<projectName>.ldr

I hope this works for you.


Re: XML to LDR - Arthur Sigg - 2013-03-10

Hi Rolf,

Great, it works fine ! Thank you very much !
It's so easy now to modify the pattern and colors :-)

Best regards,

Re: XML to LDR - Rolf Osterthun - 2013-03-15

Hey Arthur,

since the PicToBrick application works with color quantization, the results should become better the more colors you define. But the colors that are predefined in PicToBrick are no LDraw colors. So, recoloring might still result in a distorted image. You would get the best LDraw results, if you use a PicToBrick configuration that includes all known LDraw colors.

I created such a configutation file: PicToBrick_LDraw_Top_View.cfg. Just copy it in your PicToBrick working directory. It contains all the solid colors from the LDConfig.ldr (UPDATE 2012-09-13).

With a new version of the converter you can migrate the new mosaics, too.