LDraw.org Discussion Forums

Full Version: XML to LDR
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
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
Hi Arthur,

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

Tim
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.

Rolf
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.

Edit:
Ok, now I have downloaded that application and did a quick test. The output for our parts are better Smile.
Sample:
Code:
<unit>
    <element>
        Plate_1x1_(3024)
    </element>
    <color>
        01_White
    </color>
</unit>
<unit>
    <element>
        Plate_1x1_(3024)
    </element>
    <color>
        99_Very_Light_Bluish_Gray
    </color>
</unit>
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.
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);
legoTop.setColor("85_Dark_Bluish_Gray",73,88,101);
legoTop.setColor("86_Light_Bluish_Gray",161,171,178);
legoTop.setColor("99_Very_Light_Bluish_Gray",198,205,209);
legoTop.setColor("01_White",255,255,255);
legoTop.setColor("03_Yellow",255,214,0);
legoTop.setColor("33_Light_Yellow",255,233,143);
legoTop.setColor("69_Dark_Tan",144,144,105);
legoTop.setColor("02_Tan",214,191,145);
legoTop.setColor("88_Reddish_Brown",104,46,47);
legoTop.setColor("04_Orange",244,123,32);
legoTop.setColor("31_Medium_Orange",248,155,28);
legoTop.setColor("59_Dark_Red",247,4,55);
legoTop.setColor("05_Red",238,46,36);
legoTop.setColor("25_Salmon",246,150,124);
legoTop.setColor("26_Light_Salmon",250,188,174);
legoTop.setColor("47_Dark_Pink",205,127,181);
legoTop.setColor("23_Pink",247,179,204);
legoTop.setColor("89_Dark_Purple",70,42,135);
legoTop.setColor("24_Purple",127,63,152);
legoTop.setColor("93_Light_Purple",142,49,146);
legoTop.setColor("71_Magenta",171,29,137);
legoTop.setColor("63_Dark_Blue",0,54,96);
legoTop.setColor("07_Blue",0,87,164);
legoTop.setColor("42_Medium_Blue",94,174,224);
legoTop.setColor("62_Light_Blue",193,224,244);
legoTop.setColor("39_Dark_Turquoise",0,146,121);
legoTop.setColor("40_Light_Turquoise",0,179,176);
legoTop.setColor("41_Aqua",162,218,222);
legoTop.setColor("80_Dark_Green",0,65,37);
legoTop.setColor("06_Green",0,148,74);
legoTop.setColor("37_Medium_Green",151,211,184);
legoTop.setColor("38_Light_Green",186,225,209);
legoTop.setColor("34_Lime",181,206,47);
legoTop.setColor("76_Medium_Lime",193,216,55);
legoTop.setColor("35_Light_Lime",197,225,170);
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:
Code:
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).

Rolf
"Top View" and "Side View" needs at least another value in the following line:
Code:
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.

Edit:
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.
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 ...
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.

Usage:
Code:
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:
Code:
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.

Rolf
Hi Rolf,

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

Best regards,
Arthur
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.

Rolf
Pages: 1 2