LDCad My second LDCad script :)


My second LDCad script :)
#1
I have "completed" (read: not perfectly) my second attempt at an LDCad script. It's attached below (change .txt to .lua).

This script scans an LDraw file for parts or submodels that are hidden by buffer exchange in the final display state. If it finds any, it comments out their type 1 reference lines in the code, so that they won't appear in LDView, Studio, or other programs that don't recognize the BUFEXCHG metas. (For my inner monologue on the development process, see this thread.)

The script only runs from the end of the file (i.e., the last step) so it shows the completed model. It's not meant to work on intermediate steps to show the visibility at any given build phase. It's more meant as a cleanup tool

Some functionality is missing in this version, but hopefully I can improve it in the future:
  • It's not recursive, so you have to run the script separately on any submodels that also use buffer exchange, as well as on the main file. (This because I'm not sure how to access all the subfile objects of an mpd file via the API.)
  • It modifies the current file, rather than writing a new file, so you'd want to save the changed file as a copy. Offering a choice here would be a nice feature.
  • Technically, it's not actually a toggle function since it doesn't work in reverse—you can't un-comment hidden lines with this script. Mainly this is because there's no way to tell a commented-out ref line generated by this script from one that's meant to be there already. (I suppose I could add a flag of some kind to the lines affected by the script.) Meanwhile, you can always just use LDCad's undo.

Please feel free to send me any test files, particularly those with complicated or unusual implementations of buffer exchange, or to test your own models. (In particular, there may be an issue with Wine, causing a crash when closing open files in LDCad.)


Attached Files
.txt   togBufEx.txt (Size: 1.42 KB / Downloads: 5)
Reply
RE: My second LDCad script :)
#2
I've updated my buffer exchange cleanup script; it is now a true toggle function. I've added a tag "BufEx:" to any lines that are commented out by the script, so that it will also uncomment any such lines with that tag, while leaving other comments alone.

At the same time, I've added another toggle macro to comment out or uncomment any line. Actually, this is just Roland's togglePrefix() function that comes with the MLCad script, except with a slight modification so that it will correctly remove both "0 //" and "0 // " (with an extra space). It will always write the extra space, however.

There's probably a way I could have structured the whole thing differently and used the same method for both toggle functions, since they're essential identical. But maybe not, since one works on the whole subfile, while the other only works on a selection.

There is one problem, but I'm not sure if the issue is with the script or with the way LDCad handles the source window: it doesn't seem to work on actual comments! If I try to uncomment an existing, all-text comment (i.e., not a type 1-5 lines or a type 0 meta), it's replaced with an empty line. If I toggle again, it comments out the empty line.

Anyway, here's the updated script:
.lua   togBufEx.lua (Size: 2.81 KB / Downloads: 3)
Reply
« Next Oldest | Next Newest »



Forum Jump:


Users browsing this thread: 1 Guest(s)