LDCad scripting and macros


RE: LDCad scripting and macros
#8
(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
Reply
« Next Oldest | Next Newest »



Messages In This Thread
RE: LDCad scripting and macros - by Roland Melkert - 2019-05-20, 18:01
RE: LDCad scripting and macros - by Joachim - 2022-07-25, 8:54
RE: LDCad scripting and macros - by Joachim - 2022-07-25, 21:18
RE: LDCad scripting and macros - by Joachim - 2022-07-26, 10:33

Forum Jump:


Users browsing this thread: 1 Guest(s)