Script to generate random parts in LDCad

RE: Script to generate random parts in LDCad
#2
(2020-01-22, 11:44)Jaco van der Molen Wrote: Hi all,

For a MOC I have to simulate a kind of landscaping rough soil-like.
I am looking for a way in LDCad to make something like this with a script.

With it, you should be able to specify dimensions (in this case 8x8), what bricks to use (plates, tiles, etc.) and colors (like LBG, tan, white, ...)
Would that be possible?

The random part is easy, the parts/colors are tricky because they need input from the user.

Below an example/starter script

Code:
```genTools=require('genTools') function onRun()   local base='41539.dat'   local baseCol=7   local yPos=-8   local colors={4,15,1,14}   local colCnt=4   local xCnt=8   local zCnt=8   local xStep=20   local zStep=20     local sf=ldc.subfile()   local ses=ldc.session()     if not ses:isLinked() then     ldc.dialog.runMessage('No session')     return   end     local sel=ses:getSelection()     local parts={}   local partCnt=sel:getRefCount()     if partCnt==0 then     ldc.dialog.runMessage('No parts in selection')     return    end     for i=1,partCnt do     parts[i]=sel:getRef(i):getName()   end     sel:remove()     local xOfs=10-xCnt*xStep/2   local zOfs=10-zCnt*zStep/2     sel:add(sf:addNewRef(base, baseCol))     for z=0,zCnt-1 do     for x=0,(xCnt-1) do       sel:add(sf:addNewRef(parts[math.random(partCnt)], colors[math.random(colCnt)], ldc.matrix(xOfs+x*xStep, yPos, zOfs+z*zStep)))     end   end end function register()   local macro=ldc.macro('My macro')   macro:setEvent('run', 'onRun') end register()```

Colors are static but you could also get them from the selection if needed.

It will use the parts in the selection to randomly fill a 8x8 plate.

If you want the plate to be selected too you could do that be asking for the dimensions followed by determining the correct plate to use. Or just adjust the script constants at its top.
« Next Oldest | Next Newest »

 Messages In This Thread Script to generate random parts in LDCad - by Jaco van der Molen - 2020-01-22, 11:44 RE: Script to generate random parts in LDCad - by Roland Melkert - 2020-01-23, 18:55 RE: Script to generate random parts in LDCad - by Jaco van der Molen - 2020-01-23, 21:09 RE: Script to generate random parts in LDCad - by Philippe Hurbain - 2020-01-24, 9:56 RE: Script to generate random parts in LDCad - by Jaco van der Molen - 2020-01-27, 8:48 RE: Script to generate random parts in LDCad - by Jaco van der Molen - 2020-01-29, 14:51

Forum Jump:

Users browsing this thread: 1 Guest(s)