[LDCad] Use script to create submodel


[LDCad] Use script to create submodel
#1
Hi all,

Is it possible to use a script to create a submodel in LDCad?
I ask this because I have to create multiple submodels that all require some basic other (LPub3D) metacommands and one or more parts, always in the same place.
This should be done by looping through a simple series of model names and descriptions.

I need to have submodels called A1, A2, A3, A4, .... A16
And B1, B2, B3 to B16 etc.
All the way to H.

Then I need submodels LA1, LA2, etc. to LH16

The A1, B1, etc. submodels should all have these lines:


Code:
0 ROTSTEP 90 180 0 ABS
0 !LPUB CALLOUT BEGIN
1 16 0 0 0 -0.5 0 0 0 0.5 0 0 0 -0.5 LA1.ldr
0 !LPUB CALLOUT END
0 !LPUB ASSEM MODEL_SCALE LOCAL  1.2500
0 !LPUB PLI BEGIN IGN
1 71 -150 0 150 1 0 0 0 1 0 0 0 1 91405.dat
0 !LPUB PLI END


Where in line 3 LA1.ldr is, of course, incremental like LA2, LA3, etc.

The LA1, LA2, etc. submodels should have more part lines in them and all start looking like this:

Code:
0 !LPUB ASSEM MODEL_SCALE LOCAL  0.3500
0 !LPUB PLI BEGIN IGN
[many part lines, all the same]
0 !LPUB PLI END

I was thinking about creating some sort of array that contains the names of the submodel files and then loop through to create all the submodels I need.

At least, that is my theory if I can use a script.

Or: can it be done another way?

Thanks all.
Jaco van der Molen
lpub.binarybricks.nl
Reply
RE: [LDCad] Use script to create submodel
#2
(2019-09-16, 19:15)Jaco van der Molen Wrote: Is it possible to use a script to create a submodel in LDCad?

Not directly, as it would need access to the internal file object (owner of all the subfile objects within a ldr/mpd) while currently there is only the ldc.subfile wrapper.

But you can (as of 1.6c) read/write any kind of file you want trough the lua io module.

You could use that to generate the ldraw content as nomal text (so without the ldc.subfile object etc).

Then load an existing file (if you want to append it to an existing model)
Add the new text and save the file again (i recommend using a different name though for backup purposes).

If you appended to a file currently open in LDCad it should trigger a reload in the editor once the script is done.
Reply
RE: [LDCad] Use script to create submodel
#3
(2019-09-17, 21:49)Roland Melkert Wrote: Not directly, as it would need access to the internal file object (owner of all the subfile objects within a ldr/mpd) while currently there is only the ldc.subfile wrapper.

But you can (as of 1.6c) read/write any kind of file you want trough the lua io module.

You could use that to generate the ldraw content as nomal text (so without the ldc.subfile object etc).

Then load an existing file (if you want to append it to an existing model)
Add the new text and save the file again (i recommend using a different name though for backup purposes).

If you appended to a file currently open in LDCad it should trigger a reload in the editor once the script is done.

OK, I see.
So basically I'd only use LUA in LDCad. Or rather use LDCad to run a LUA script.
A bit like creating a BOM, like described in this thread?

Any hints as to how to achieve something like I'd want? Blush
Jaco van der Molen
lpub.binarybricks.nl
Reply
RE: [LDCad] Use script to create submodel
#4
(2019-09-18, 12:20)Jaco van der Molen Wrote: So basically I'd only use LUA in LDCad. Or rather use LDCad to run a LUA script.
A bit like creating a BOM, like described in this thread?

Yes, but you could assign a button to it in LDCad's tool bar and or involve the selection as a basis or something.
Reply
RE: [LDCad] Use script to create submodel
#5
(2019-09-18, 18:39)Roland Melkert Wrote: ...assign a button to it in LDCad's tool bar...

Enlighten me? How?
I cannot seem to find that in de documentation.

(I got a basic script running a loop that creates multiple lines, so that goes well)
Jaco van der Molen
lpub.binarybricks.nl
Reply
RE: [LDCad] Use script to create submodel
#6
(2019-09-18, 20:19)Jaco van der Molen Wrote: Enlighten me? How?
Sorry I was mistaken, you can only assign hotkeys to macro's.

Might add it to 1.6d though, as I can't remember why it is blocked in my code (some function always returns false when asked if it can be in the toolbar).
Reply
RE: [LDCad] Use script to create submodel
#7
(2019-09-18, 20:46)Roland Melkert Wrote: Sorry I was mistaken, you can only assign hotkeys to macro's.

OK, how? Blush

(2019-09-18, 20:46)Roland Melkert Wrote: Might add it to 1.6d though, as I can't remember why it is blocked in my code (some function always returns false when asked if it can be in the toolbar).

16.d? I thought 1.6c was the last version before 2.0 ;-)
Jaco van der Molen
lpub.binarybricks.nl
Reply
RE: [LDCad] Use script to create submodel
#8
(2019-09-19, 7:38)Jaco van der Molen Wrote: OK, how? Blush
prefs/gui or right click on menu bar


(2019-09-19, 7:38)Jaco van der Molen Wrote: 16.d? I thought 1.6c was the last version before 2.0 ;-)
I discovered a medium sized bug in 1.6c ('by category' bin is messed up combined with the 1902 library).
It's also a nice moment to update the snap info.

2.0 is still a (very) far way out.
Reply
« Next Oldest | Next Newest »



Forum Jump:


Users browsing this thread: 9 Guest(s)