LDraw.org Discussion Forums
[Windows] A request for a simple script of ldcad - Printable Version

+- LDraw.org Discussion Forums (https://forums.ldraw.org)
+-- Forum: LDraw Programs (https://forums.ldraw.org/forum-7.html)
+--- Forum: LDraw Editors and Viewers (https://forums.ldraw.org/forum-11.html)
+--- Thread: [Windows] A request for a simple script of ldcad (/thread-28544.html)



A request for a simple script of ldcad - HWQ - 2024-12-14

I hope to add a Lua script to detect and delete parts of duplicate coordinate axes
Sometimes I accidentally put in overlapping parts and it’s hard to find them. 
I think this should be easy to implement, such as detecting the same XYZ coordinates in the file and deleting them, but I don't know much about Lua.
hope someone can help me solve it.thk


RE: A request for a simple script of ldcad - Roland Melkert - 2024-12-17

(2024-12-14, 9:18)HWQ Wrote: I hope to add a Lua script to detect and delete parts of duplicate coordinate axes
Sometimes I accidentally put in overlapping parts and it’s hard to find them. 
I think this should be easy to implement, such as detecting the same XYZ coordinates in the file and deleting them, but I don't know much about Lua.
hope someone can help me solve it.thk

This should be fairly easy, I'll try to write a quick and dirty one later this week or in the weekend.


RE: A request for a simple script of ldcad - HWQ - 2024-12-23

Big GrinBig Grin Big Grin waiting for u .thks Heart
(2024-12-17, 22:43)Roland Melkert Wrote: This should be fairly easy, I'll try to write a quick and dirty one later this week or in the weekend.



RE: A request for a simple script of ldcad - Roland Melkert - 2024-12-23

(2024-12-23, 3:45)HWQ Wrote: Big GrinBig Grin Big Grin waiting for u .thks Heart

sorry, something has gotten in the way. I probably won't be able to work at anything ldraw related for at least a week Angry


RE: A request for a simple script of ldcad - HWQ - 2024-12-24

(2024-12-23, 21:03)Roland Melkert Wrote: sorry, something has gotten in the way. I probably won't be able to work at anything ldraw related for at least a week Angry
OHHHHHHHHH NO.
I hope you'll finish your work as soon as possible and help me handle this small request. Blush


RE: A request for a simple script of ldcad - HWQ - 2024-12-30

(2024-12-23, 21:03)Roland Melkert Wrote: sorry, something has gotten in the way. I probably won't be able to work at anything ldraw related for at least a week Angry

Hello, can you help me with this request? It's too troublesome for me to check the overlap one by one. Sad


RE: A request for a simple script of ldcad - Roland Melkert - 2025-01-03

Made a quick and dirty one:

Code:
function isUique(lst, needle)

  for key, item in pairs(lst) do
    if needle.name==item.name and (needle.pos-item.pos):getLength()<0.1 then
      return false
    end
  end

  return true
end

function onRun()

  local sf=ldc.subfile()
  local sel=ldc.selection()
  local lst={}
  
  sel:remove()

  for i=1,sf:getRefCount() do
    local ref=sf:getRef(i)
    local info={pos=ref:getPos(), name=ref:getName()}

    if isUique(lst, info) then
      table.insert(lst,info)
    else
      sel:add(ref)
    end
  end

end

function register()

  local macro=ldc.macro('Select dups')
  macro:setEvent('run', 'onRun')
end

register()

Save it to a .lua file and place it in LDCad/scripts/default/global to use it.

It will find identical parts at (nearly,<0.1 ldu) the same place ignoring color and rotation.