Variables in LDraw files - Printable Version +- LDraw.org Discussion Forums (https://forums.ldraw.org) +-- Forum: General (https://forums.ldraw.org/forum-12.html) +--- Forum: General LDraw.org Discussion (https://forums.ldraw.org/forum-6.html) +--- Thread: Variables in LDraw files (/thread-26542.html) |
Variables in LDraw files - Cam's Bricks - 2022-07-06 I am pretty sure the answer is "no, no, not ever, no thanks, that is a terrible idea" BUT I wanted to ask if there is support for variables in the LDraw file format? It would probably take support of all the editors and renders which is probably causing someone's eyebrows to make odd shapes as even type this out I am someone who enjoys the "make it once and for all use cases", so the pragmatic nature of making a lot of similar parts that have one or two changes for each iteration feels quite bothersome. RE: Variables in LDraw files - Max Murtazin - 2022-07-06 (2022-07-06, 12:31)Cam's Bricks Wrote: I am pretty sure the answer is "no, no, not ever, no thanks, that is a terrible idea" BUT I wanted to ask if there is support for variables in the LDraw file format?I'm not sure how this can be useful, any examples? RE: Variables in LDraw files - Magnus Forsberg - 2022-07-06 (2022-07-06, 15:20)Max Murtazin Wrote: I'm not sure how this can be useful, any examples? I'm not sure I even understand the question... RE: Variables in LDraw files - Cam's Bricks - 2022-07-06 (2022-07-06, 15:20)Max Murtazin Wrote: I'm not sure how this can be useful, any examples? 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 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 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 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. RE: Variables in LDraw files - Orion Pobursky - 2022-07-06 While this is a good idea, it would break backwards compatibility in a huge way. In my (long neglected) LPov project, I created a POV-Ray macro to programmatically create plates and bricks in much the same way as you describe above. RE: Variables in LDraw files - Cam's Bricks - 2022-07-06 (2022-07-06, 16:57)Orion Pobursky Wrote: While this is a good idea, it would break backwards compatibility in a huge way. I am not asking to change anything. I am glad I am not the only one to have thought of this. I was more or less doing a check to make sure there wasnt some hidden feature to do this kind of programing in the files before I do it outside the ldraw format and then export to dat. RE: Variables in LDraw files - Max Murtazin - 2022-07-06 (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. 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 RE: Variables in LDraw files - Orion Pobursky - 2022-07-06 In hindsight, I think a meta to tell the LDraw programs to simple geometric primitives (think cylinders, cones, discs, etc.) with a well defined spec would have saved a lot of heartache. But, alas, that train left the station long ago. RE: Variables in LDraw files - Orion Pobursky - 2022-07-06 Here's the link to my POV-Ray macros for bricks, plates, tiles, and Technic bricks. https://github.com/billthefish/LDrawPOV/blob/master/LPov/macros.inc RE: Variables in LDraw files - Philippe Hurbain - 2022-07-06 (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 may want to try to track this... https://news.lugnet.com/cad/?n=13657 RE: Variables in LDraw files - Milan Vančura - 2022-07-06 (2022-07-06, 17:03)Cam's Bricks Wrote: I am not asking to change anything. I am glad I am not the only one to have thought of this. AFAIK, there is one feature in this way, kind of. Some basic shapes are in the included files which are modified by matrix on the line they are included/used. "box5.dat" on the first line of your example is such a case. It is very limited from your POV but this is how parts in ldraw are constructed. If you need more advanced features you need to generate .dat files from richer language. RE: Variables in LDraw files - Roland Melkert - 2022-07-06 (2022-07-06, 16:43)Cam's Bricks Wrote: You could (should?) do this using a new meta, especially since you would need to extend existing software in order to use it anyway. Something like: Code: !VAR "height" = 24 You Could also loose the quotes (I always hate those) by defining grammar for the variable name, for example ([a-zA-z]+[a-zA-Z0-9]*) (case insensitive if needed) RE: Variables in LDraw files - Cam's Bricks - 2022-07-07 (2022-07-06, 21:10)Roland Melkert Wrote: You could (should?) do this using a new meta, especially since you would need to extend existing software in order to use it anyway. Fortunately for LDraw community, I am no where near a good enough programmer to extend the file format or any of the existing editors to support this. I was just looking to make sure that this hadnt been developed but never got a write up or was still in an alpha or beta phase of development. Thanks for all the interesting thoughts about this. I will probably do some simple scripting to get what I want then just export to .dat and go from there. RE: Variables in LDraw files - Cam's Bricks - 2022-07-07 (2022-07-06, 17:17)Philippe Hurbain Wrote: You may want to try to track this... This is very interesting. I dont know that a tool from 2006 would still be around or work on modern systems. Do you happen to know if the person who posted there is still active in the LDraw community? RE: Variables in LDraw files - Cam's Bricks - 2022-07-07 (2022-07-06, 17:14)Orion Pobursky Wrote: Here's the link to my POV-Ray macros for bricks, plates, tiles, and Technic bricks. Thanks for this! Constants in LDraw files - Nils Schmidt - 2022-07-07 (2022-07-06, 12:31)Cam's Bricks Wrote: I am pretty sure the answer is "no, no, not ever, no thanks, that is a terrible idea" BUT I wanted to ask if there is support for variables in the LDraw file format? I did a quick implementation to try it out. One difficulty is to parse the occurences in an efficient manner, otherwise I would need to try to replace every substring of a line with a potential constant which slows down the parsing of the file significantly. I am not sure if I am going to finally implement this in LDPE. But I suggest to use global constants instead of variables. A variable implies some kind of re-assignment, a scope or a calculation. For this I would create some kind of unofficial specification for the use of a scripting language (LDCad for example supports lua scripts ). RE: Constants in LDraw files - Max Murtazin - 2022-07-08 I would like to see this being adopted as an optional feature, maybe even one day this growing into smth like an internal ldraw scripting language, since stuff like this would probably be really neat for use in custom parts and stuff. For example, what I could see being a thig are also matrix variables, that could probably be applied to the line after them with a meta command. All such QOL stuff Also, with those ideas, I could also imagine something like a "compiler" of LDraw files using those features into a proper LDraw file LDPartEditor 1.8.60 has variables/constants now (unofficial meta command) - Nils Schmidt - 2022-07-10 (2022-07-06, 12:31)Cam's Bricks Wrote: I am pretty sure the answer is "no, no, not ever, no thanks, that is a terrible idea" BUT I wanted to ask if there is support for variables in the LDraw file format? (2022-07-08, 16:07)Max Murtazin Wrote: I would like to see this being adopted as an optional feature, maybe even one day this growing into smth like an internal ldraw scripting language, since stuff like this would probably be really neat for use in custom parts and stuff. A part editor supports now variables on its own. Example: Code: 0 More here: https://forums.ldraw.org/showthread.php?tid=26551&pid=47005&mode=threaded |