Variables in LDraw files


RE: Variables in LDraw files
#7
(2022-07-06, 16:43)Cam's Bricks Wrote: At a basic level something as simple as bricks and plates could be "automated" in this fashion. 

You would have a line type that is used to define a variable. That variable can be used in the part where repetitive dimensions are used or sub-parts are called or any number of other useful calculation points. 

If we look at 3005.dat Brick 1 x 1 we see that the number 24 all over the file:
Code:
1 16 0 24 0 6 0 0 0 -20 0 0 0 6 box5.dat

4 16 10 24 10 6 24 6 -6 24 6 -10 24 10
4 16 -10 24 10 -6 24 6 -6 24 -6 -10 24 -10
4 16 -10 24 -10 -6 24 -6 6 24 -6 10 24 -10
4 16 10 24 -10 6 24 -6 6 24 6 10 24 10

1 16 0 24 0 10 0 0 0 -24 0 0 0 10 box5.dat

1 16 0 0 0 1 0 0 0 1 0 0 0 1 stud.dat


Now if we look at 3024.dat Plate 1 x 1 we see it is the same exact file but with every instance of 24 replaced with 8:
Code:
1 16 0 8 0 6 0 0 0 -4 0 0 0 6 box5.dat

4 16 10 8 10 6 8 6 -6 8 6 -10 8 10
4 16 -10 8 10 -6 8 6 -6 8 -6 -10 8 -10
4 16 -10 8 -10 -6 8 -6 6 8 -6 10 8 -10
4 16 10 8 -10 6 8 -6 6 8 6 10 8 10

1 16 0 8 0 10 0 0 0 -8 0 0 0 10 box5.dat

1 16 0 0 0 1 0 0 0 1 0 0 0 1 stud.dat

If variables could be used then making both parts would be as simple as adding a line like this and changing the line to equal 8 or 24 or 48 or whatever we want without changing anything else in the file:

Code:
0 !VAR "height" = 24

1 16 0 "height" 0 6 0 0 0 -20 0 0 0 6 box5.dat

4 16 10 "height" 10 6 "height" 6 -6 "height" 6 -10 "height" 10
4 16 -10 "height" 10 -6 "height" 6 -6 "height" -6 -10 "height" -10
4 16 -10 "height" -10 -6 "height" -6 6 "height" -6 10 "height" -10
4 16 10 "Height" -10 6 "height" -6 6 "height" 6 10 "height" 10

1 16 0 "height" 0 10 0 0 0 -"height" 0 0 0 10 box5.dat

1 16 0 0 0 1 0 0 0 1 0 0 0 1 stud.dat


This is a simple use case and I would not expect to be able to do math in these lines except for adding "-" to make it negative as needed to meet the BFC rules. Doing math would be bad for rounding errors unless the standard defined a calculation method to be used by all editors and renders.

My more advanced use case is that I want to make train wheels of various sizes and combinations but I would like to write the file once then just change a few variables (radius, subfile call(s), etc) in each of the files without having to type it all again or copy/paste and have errors.

I don't think there is a much need of this. LDraw files are just models most of the time you don't touch, so there is no much need than this
Also, as mentioned by Orion, LDraw is built to be backwards compatible. It's not a good idea to mess with something that has pretty much became a core of the LDraw - new things should be extending the tools by not changing the ones that exist already
Reply
« Next Oldest | Next Newest »



Messages In This Thread
Variables in LDraw files - by Cam's Bricks - 2022-07-06, 12:31
RE: Variables in LDraw files - by Max Murtazin - 2022-07-06, 17:07
Constants in LDraw files - by Nils Schmidt - 2022-07-07, 20:42

Forum Jump:


Users browsing this thread: 2 Guest(s)