Idea for LUA script to create a knolling layout


RE: Idea for LUA script to create a knolling layout
#19
(2024-10-11, 7:41)Fredrik Hareide Wrote: I made some adjustments to the script to reset rotation and prepare for inlining. I'm not sure how to inline in LDCad script so here I might need Roland.

You could build a flattened list of all used subfiles (parts) with their abs position and other needed info.

This is done recursive on the refs like:

Code:
function buildFlatList(parentSf, parentPosOri, list) local cnt=parentSf:getRefCount() for i=1, cnt do local ref=parentSf:getRef(i) local sf=ref:getSubfile() local relPosOri=ref:getPosOri() local absPosOri=relPosOri*parentPosOri if sf:isPart() then local item={ pos=absPosOri:getPos(), sf=sf } table.insert(list, item) --print(item.sf:getFileName() .. ' => ' .. item.pos:__tostring()) else if sf:isGenerated() then --collect/map flex info if needed, for now just skip it. --print('flex: '..sf:getFileName()) else buildFlatList(sf, absPosOri, list) end end end end

and use it like:

Code:
local list={} buildFlatList(ldc.subfile(), ldc.matrix(), list) -- sort/use list etc

Also I think the overlap are caused by not compensating for the parts absolute center. The bounding min max vecs are not symmetrical.

Small tip:
setIdentity is not needed a new ldc.matrix defaults to identity. (technically it is noise until used internally, but from pov of the user it will be id)
Reply
« Next Oldest | Next Newest »



Messages In This Thread
RE: Idea for LUA script to create a knolling layout - by Roland Melkert - 2024-10-15, 20:45

Forum Jump:


Users browsing this thread: 1 Guest(s)