DesignCAD 3D Max 2027 box
Now available

DesignCAD 2027

Hatches that follow their boundaries, an on-screen dial to turn your model, and a way to find any command by name, in a clean Windows 11 look.

Duplicate entities on the same layer.

Started by WarrenKinney01, April 02, 2013, 04:11:29 AM

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

WarrenKinney01

From time to time, after duplicating entities from layer to layer, I end up with a duplicate line or whatever entity on the same layer. Probably operator error. It seems that I used to be able to check for duplicate entities on the same layer. Is that or was that possible, and if so, how do you do that. Current version is Max 21.2.
Thanks,
Warren

Bob P

The delete-duplicate-lines macro does what you need except for the same-layer requirement.  That could easily be added to the code though.
' DeleteDuplicateLines.d3m
' This simple macro removes duplicate lines the first two points of which lie on top of each other in the drawing
' This macro could take a LONG time to complete on a complicated drawing.

' Turn off Error Reporting
   Sys(0) = 0

Input "Tolerance for matching points:ENTER for .001 ", tol
if tol=0 then tol=.001

' Loop through all the objects in the drawing, populate progress indicator in status line
   for a = 1 to Sys(9)
   F$ = a/Sys(9)*100
   print "Working, Please Wait . . .", f$ , " % done, - ", sys(80), "duplicates found."


' Select the first object
    Entity a

' Determine if entity a is a line, if not, skip to next entity
    getattr a, type
    if type <> 1 then next a

' Get the point values for this object

      if Sys(1) > 1 then
         pointval OneX1 OneY1 OneZ1 1
         pointval OneX2 OneY2 OneZ2 2
         end if

' Loop through the rest of the objects

      c = a + 1
      for d = C to Sys(9)
            Entity d

' Get the point values for that object
            if Sys(1) > 1 then
               PointVal TwoX1 TwoY1 TwoZ1 1
               PointVal TwoX2 TwoY2 TwoZ2 2
           
' Compare Point Locations of the 2 Items
               if ((abs(OneX1-TwoX1)<tol AND abs(OneY1-TwoY1)<tol AND abs(OneZ1-TwoZ1)<tol) and (abs(OneX2-TwoX2)<tol AND abs(OneY2-TwoY2)<tol AND abs(OneZ2-TwoZ2)<tol)) then dup = 1
               if ((abs(OneX1-TwoX2)<tol AND abs(OneY1-TwoY2)<tol AND abs(OneZ1-TwoZ2)<tol) and (abs(OneX2-TwoX1)<tol AND abs(OneY2-TwoY1)<tol AND abs(OneZ2-TwoZ1)<tol)) then dup = 1
               If dup = 1 then

' Select the duplicate object
                  getattr d, type, select
                  if select = 0 then
                        select = 1
                        putattr d, type, select
                        f = f + 1
                        endif
                  dup = 0
                  endif
               endif
      next c
  next a


>Regenerate
{
}

Precision 0

print "Completed,", sys(80),  "duplicate entities found. "

Sys(1027) = 4 'Yes/No MessageBox style


Message "Press Enter to delete ", sys(80),  " lines,   N to keep"

If Sys(1028) = 6 Then

  ' Delete them
   >SelectDelete
   {
   }

>Regenerate
{
}
WClose

f$ = f
Sys(1027) = 0
Message "Finished !! " + f$ + " duplicate lines removed."

end if
End