Archive site for Autodesk Ecotect Analysis educational resources, notes and tutorials



Script example 05

CheckZeroLengthSegments.scr

When creating objects in ECOTECT, quite a few people seem to click twice on the same vertex or join up a closed planar object that is already closed, despite warning dialog boxes that appear in each case. This results in a line segment with each vertex in exactly the same segment, hence zero length. ECOTECT itself is tolerant of such constructions but other third-party tools that you export to may not be.

This script searches through all visible objects in the model and selects those objects that contain zero-length line segments.

Script Contents (Lang: lua)

--[[----------------------------------------------
-- CHECK FOR ZERO LENGTH LINE SEGMENTS:
-- This script searches for line segments with
-- zero length (ie: two vertexes in exactly the
-- same position) and selects any object(s) that
-- contain them.
--]]-----------------------------------------------

-- Get number of selected objects.
objects = get("model.objects")

-- Display 3D EDITOR page,
set("app.page", 1)

-- Make sure nothing is selected.
cmd("select.none")

-- Cycle through selected objects.
for o = 0, objects do

  selected = false
  nodes = get("object.nodes", o)
  zone = get("object.zone", o)

  -- Only consider visible objects.
  if (nodes > 0) and (get("zone.off", zone) <= 0)
   and (get("zone.hidden", zone) <= 0) then

    -- Fills x1, y1 and z1 with coordinates.
    x1, y1, z1 = get("object.node.position", o, 0)

    -- Cycle rest of nodes
    for n = 1, nodes do
                
      -- Fills x2, y2 and z2 with coordinates.
      x2, y2, z2 = get("object.node.position", o, n)

      -- Use ECOTECT to calculate the distance.
      dist = get("model.distance", x1, y1, z1, x2, y2, z2)

      -- If less than 1mm, select it.
      if dist < 1e-3 then
        selected = true
      end

      -- Shuffle coordinates along one.
      x1 = x2
      y1 = y2
      z1 = z2

      end

    -- Set the selection state of the object.
    set("object.selected", o, selected)

  end
        
end

-- Update the view to show
-- any newly selected objects.
cmd("view.redraw")

HOW WOULD YOU RATE THIS SCRIPT ?

No votes yet


Navigation

User login

Translate Site To: