Hello all,
I'm working on some new scripts for the upcoming LDCad 1.6c release.
Just some stuff I think could be useful or people asked about through emails.
To get some of them working I also expanded the api with minor new functions etc.
Anyhow just wanted to give everyone the opportunity to request additional scripts/macros/api extensions.
Things I'm working on:
- "MLCad hide" meta toggle on the selection.
- Select all "MLCad hide" content in current (non nested) model.
- Move the current building step's content down/up.
Any additional suggestions are welcome.
(2019-05-19, 8:01)Philippe Hurbain Wrote: [ -> ]Parts list macro?
You mean generating a pbg or csv?
This is possible with the 1.6b scripting I think, but I could make it more easy by adding a couple of new functions to the subfile interface (e.g. isPart or isShortCut etc)
You still need to save it to the clipboard though, as not sure I want to add fileio to the scripting api
Also 1.6c has a current partbin view export feature, if you point it to the model part list group you could also just export the part list as a csv.
I meant generation of a csv bill of material from a model created whit LDCad... I think this is the thing missing the most in LDraw tools today. LDView/MPDCenter HTML BOM feature is great, but is not easy to use in a spreadsheet.
It may be good for the guys that designs the ability to export to cvs, or html the bricks lets say the BOM. or some way to interact with bricks sites.
Other thing that can be implemented, its to auto generate the pbg file and add it to "part listing of lego set" gathered from rebricable or similar sites. (the main problem with this that if the site make changes you may need to update your software to be able to download the pbg file, and i dont like this idea)
This is not for scripting but its something on my head that i have for a long time. when you use pbg files on "part listing of lego set", in the brick description on the pbg file you put the amount of bricks that it the kit has. "COUNT"
Quote:6093a.dat:[sourceInv=parts] [color=0] [count=1]
3737.dat:[sourceInv=parts] [color=0] [count=2]
3708.dat:[sourceInv=parts] [color=0] [count=6]
3705.dat:[sourceInv=parts] [color=0] [count=8]
and when you use the part the amount of bricks that you have available on the list its always the same. it could be interesting that in the part listing amount of bricks keeps changing when you add one brick to your design, and when you add more bricks that are available on the set. the number goes red. So you know for that design you will be short of some bricks or you should be making changes if you don't want to add extra bricks. This is usefull only for people that make designs based on one kit only.
(2019-05-20, 14:11)Tatubias Wrote: [ -> ][...]
Other thing that can be implemented, its to auto generate the pbg file and add it to "part listing of lego set" gathered from rebricable or similar sites. (the main problem with this that if the site make changes you may need to update your software to be able to download the pbg file, and i dont like this idea)
[...]
Note that it is possible to directly export from Rebrickable to a pbg file, in case you didn't know

(2019-05-20, 16:43)Merlijn Wissink Wrote: [ -> ]Note that it is possible to directly export from Rebrickable to a pbg file, in case you didn't know 
yes i know, the idea its to automatize the process.
(2019-05-20, 5:23)Philippe Hurbain Wrote: [ -> ]I meant generation of a csv bill of material from a model created whit LDCad... I think this is the thing missing the most in LDraw tools today. LDView/MPDCenter HTML BOM feature is great, but is not easy to use in a spreadsheet.
Below code should work in 1.6b, I'll add its final version to the misc script
Code:
function findBomInfo(info, name, col, cnt)
for i=1, cnt do
if (info[i].name==name) and (info[i].color==col) then
return i
end
end
return nil;
end
function collectBomInfo(sf, info, pCol, cnt)
local refCnt=sf:getRefCount()
for i=1,refCnt do
local ref=sf:getRef(i)
local refTo=ref:getSubfile()
local col=ref:getColor()
if col==16 then
col=pCol
end
col=math.tointeger(col)
if ref:getString():sub(-4):lower()=='.dat' then
local refName=refTo:getFileName()
local idx=findBomInfo(info, refName, col, cnt)
if idx~=nil then
info[idx].count=info[idx].count+1
else
cnt=cnt+1
info[cnt]={name=refName; count=1; color=col}
end
else
cnt=collectBomInfo(ref:getSubfile(), info, col, cnt)
end
end
return cnt
end
function runBomTest()
info={}
cnt=collectBomInfo(ldc.subfile(), info, 16, 0)
local text=''
for i=1, cnt do
local info=info[i]
local line=info.name..','..info.color..','..info.count
print(line)
text=text..line..'\n'
end
ldc.setClipboardText(text)
end
(2019-05-20, 14:11)Tatubias Wrote: [ -> ]and when you use the part the amount of bricks that you have available on the list its always the same. it could be interesting that in the part listing amount of bricks keeps changing when you add one brick to your design, and when you add more bricks that are available on the set. the number goes red. So you know for that design you will be short of some bricks or you should be making changes if you don't want to add extra bricks. This is usefull only for people that make designs based on one kit only.
This is something that can't be done with the current scripting api, but it is something I want to do in a future (2.x) version.
Decreasing numbers in the part bin is something I wanted for awhile now, maybe even counting down from real-life owned inventory etc

Great! The good thing of scripting is that it's easyto customize (in my French Excel, the separator of csv is semicolon instead of coma!!!!!). I guess there is no way yet to retrieve part description from part file? Or color information from ldconfig?
(2019-05-21, 7:13)Philippe Hurbain Wrote: [ -> ]Great! The good thing of scripting is that it's easyto customize (in my French Excel, the separator of csv is semicolon instead of coma!!!!!). I guess there is no way yet to retrieve part description from part file? Or color information from ldconfig?
I use LibreOffice it let you choose the separation character for csv and paste of text.
the part description should be getable by
Code:
refTo:getLine(1):getString():sub(3)
on the .dat content
untested though
(2019-05-21, 19:41)Roland Melkert Wrote: [ -> ]I use LibreOffice it let you choose the separation character for csv and paste of text.
the part description should be getable by
Code:
refTo:getLine(1):getString():sub(3)
on the .dat content
untested though
I already use a modified version of your macro:register('Generate BOM list').
Would there also be an easy way to get the color name instead of the color number? I can make a function which can do this but then I would need to insert all the color name manually. Perhaps there is a neat solution which already does this. I want to keep my code as clean as possible.
Looking forward to your reply.
(2022-07-25, 8:54)Joachim Wrote: [ -> ]I already use a modified version of your macro:register('Generate BOM list').
Would there also be an easy way to get the color name instead of the color number? I can make a function which can do this but then I would need to insert all the color name manually. Perhaps there is a neat solution which already does this. I want to keep my code as clean as possible.
Looking forward to your reply.
Currently there is no way to get the color name trough script, as colors don't have a special ldc object like ldc.matrix etc.
I might add that to the next version though.
(2022-07-25, 20:57)Roland Melkert Wrote: [ -> ]Currently there is no way to get the color name trough script, as colors don't have a special ldc object like ldc.matrix etc.
I might add that to the next version though.
Thanks for the quick reply! I appreciate it!
I understand. Do you perhaps have a list of all the color names with the numbers?
I can then use this in a custom function and make sure that I have listed them all.
Regards, J
(2022-07-25, 21:18)Joachim Wrote: [ -> ]Thanks for the quick reply! I appreciate it!
I understand. Do you perhaps have a list of all the color names with the numbers?
I can then use this in a custom function and make sure that I have listed them all.
Regards, J
You should be able to parse ldcondig.ldr (in LDraw folder) to get number <-> name
(2022-07-26, 6:30)Philippe Hurbain Wrote: [ -> ]You should be able to parse ldcondig.ldr (in LDraw folder) to get number <-> name
Great suggestion. I will look into this. Thanks!