![]() |
[LDCad] Simple LDCad script - Printable Version +- LDraw.org Discussion Forums (https://forums.ldraw.org) +-- Forum: LDraw Programs (https://forums.ldraw.org/forum-7.html) +--- Forum: LDraw Editors and Viewers (https://forums.ldraw.org/forum-11.html) +--- Thread: [LDCad] Simple LDCad script (/thread-26168.html) |
Simple LDCad script - N. W. Perry - 2022-03-25 So, I wrote my first script for LDCad, hooray! ![]() It is a simple macro to transpose two colors in a selection. You might use it if you have built a huge checkered floor out of tiles and realized you have the pattern backwards! I'm sure there are ways to improve it, but I'm actually pleased I was able to work it out in one day. ![]() Here it is: Code: genTools=require('genTools') Suggestions are welcome! RE: Simple LDCad script - Roland Melkert - 2022-03-25 (2022-03-25, 4:27)N. W. Perry Wrote: So, I wrote my first script for LDCad, hooray!Congratulations, be careful though it can be addictive ![]() Minor potential bug: Code: local cnt=sel:getRefCount() RE: Simple LDCad script - N. W. Perry - 2022-03-25 (2022-03-25, 19:56)Roland Melkert Wrote: Minor potential bug: Fixed. Couldn't I also move the local variables col and ref up higher somewhere, so I don't have to repeat them? My next attempt will be a macro to comment out BUFEXCHG lines. I think I know how to identify the affected ref lines, now to learn how to actually alter them. :-) RE: Simple LDCad script - Roland Melkert - 2022-03-25 (2022-03-25, 22:33)N. W. Perry Wrote: Couldn't I also move the local variables col and ref up higher somewhere, so I don't have to repeat them? Yes, just write them without the value assignment. (2022-03-25, 22:33)N. W. Perry Wrote: My next attempt will be a macro to comment out BUFEXCHG lines. I think I know how to identify the affected ref lines, now to learn how to actually alter them. :-) scripts can't actually modify lines on a string level (mostly because of the undo tracking), but you get the same effect by creating a new line and deleting the old one. For an example of this see the global mlcad.lua script. RE: Simple LDCad script - N. W. Perry - 2022-03-26 (2022-03-25, 22:57)Roland Melkert Wrote: Yes, just write them without the value assignment. I couldn't get them to work except inside the loops themselves (which meant I had to declare them in both loops). But the cnt variable does, for some reason. (2022-03-25, 22:57)Roland Melkert Wrote: scripts can't actually modify lines on a string level (mostly because of the undo tracking), but you get the same effect by creating a new line and deleting the old one. Yes, I'll be studying that one tonight. :-) RE: Simple LDCad script - Yx Wang - 2025-02-13 Is there any auto-save script available? RE: Simple LDCad script - Roland Melkert - 2025-02-13 (2025-02-13, 10:06)Yx Wang Wrote: Is there any auto-save script available? It is possible to save the current file with script, but currently there is no way to do this at a set time interval. RE: Simple LDCad script - HWQ - 2025-06-26 (2025-02-13, 18:13)Roland Melkert Wrote: It is possible to save the current file with script, but currently there is no way to do this at a set time interval. Why can't we add a function to automatically save backups at intervals through scripts? RE: Simple LDCad script - Roland Melkert - 2025-06-28 (2025-06-26, 6:10)HWQ Wrote: Why can't we add a function to automatically save backups at intervals through scripts? The current scripting environment is not designed for this. The one in 2.0 will have a much deeper integration with the internals which should make these kinds of thins naturally available. Not sure if the 2.0 scripting language will be lua though, I'm also researching embedded JavaScript for this. RE: Simple LDCad script - HWQ - 2025-07-02 (2025-06-28, 19:55)Roland Melkert Wrote: The current scripting environment is not designed for this. When will version 2.0 be released? I am so looking forward to it. RE: Simple LDCad script - Roland Melkert - 2025-07-02 (2025-07-02, 2:41)HWQ Wrote: When will version 2.0 be released? I am so looking forward to it. I don't really know, it's going to take some considerable time though. First I need to finish 1.7 Beta 2, and the final 1.7. |