Cannot Delete Duplicate Objects

Cannot Delete Duplicate Objects

scarroll
Explorer Explorer
5,022 Views
17 Replies
Message 1 of 18

Cannot Delete Duplicate Objects

scarroll
Explorer
Explorer

I am new to LISP and was hoping someone could help with this issue I have.  I have a large and complex 3D design with overlapping identical 3D blocks.  Is there any way to scan through the content of the file and delete the duplicate 3D blocks all at once.  OVERKILL does not work and it would take way too long to manually delete the duplicates.

Any help is appreciated

 

These are scaffold tubes modeled in 3D blocks with basic construction lines to allow for snap points. 

0 Likes
Accepted solutions (1)
5,023 Views
17 Replies
Replies (17)
Message 2 of 18

devitg
Advisor
Advisor

Please upload sample.dwg 

 

 

 

Message 3 of 18

DannyNL
Advisor
Advisor
Accepted solution

Can you clarify what you mean by duplicate blocks?

Because in your question you mention 'overlapping' as well as 'duplicate'.

 

To me duplicate suggests two blocks with the same name and inserted on exactly the same insertion point. If so, this would not be too difficult to program. If they do not share the same insertion point but actually only partially overlap, this will be a lot more difficult.

Message 4 of 18

scarroll
Explorer
Explorer

They are the same block inserted in the same way on the same insertion point. 

0 Likes
Message 5 of 18

devitg
Advisor
Advisor

please , upload a sample,dwg

0 Likes
Message 6 of 18

scarroll
Explorer
Explorer

I cant do that devitg.

0 Likes
Message 7 of 18

cadffm
Consultant
Consultant
I am pretty sure you can create a sample what is alowed to uploud.

If not. We have the knowledge, you have the data, and now?

There are not two identical blockreferences of one block.. but what is the difference?
Please select one double pair (= two) of blockreferences, use command LIST and post the result [F2].

Sebastian

0 Likes
Message 8 of 18

DannyNL
Advisor
Advisor

Try this.....not mother's finest, but had to hurry since my weekend is on.

So also only limited tested Smiley Happy

 

Only blocks that match ALL properties from the list (RBD_PropertyList) will be deleted.

 

(defun c:RemBlkDup (/ RBD_Selection RBD_BlockInsertion RBD_PointList RBD_PropertyList RBD_MainValueList RBD_CheckValueList RBD_DeleteList)
   (if
      (setq RBD_Selection (ssget "_X" (list '(0 . "INSERT")(cons 410 (getvar "CTAB")))))
      (progn
         (foreach RBD_Item (ssnamex RBD_Selection)
            (setq RBD_BlockInsertion (vlax-safearray->list (vlax-variant-value (vla-get-InsertionPoint (setq RBD_BlockObject (vlax-ename->vla-object (cadr RBD_Item)))))))
            (if
               (not (setq RBD_PointFound (assoc RBD_BlockInsertion RBD_PointList)))               
               (setq RBD_PointList (cons (list RBD_BlockInsertion RBD_BlockObject) RBD_PointList))
               (setq RBD_PointList (subst (append RBD_PointFound (list RBD_BlockObject)) RBD_PointFound RBD_PointList))
            )
         )
         (setq RBD_PropertyList
            (list
               "EffectiveName"           "InsertionPoint"          "Rotation"                "XEffectiveScaleFactor"
               "XScaleFactor"            "YEffectiveScaleFactor"   "YScaleFactor"            "ZEffectiveScaleFactor"
               "ZScaleFactor"
            )
         )
         (foreach RBD_PointItem RBD_PointList
            (foreach RBD_Block (cdr RBD_PointItem)
               (if
                  (not (vl-position RBD_Block RBD_DeleteList))
                  (progn
                     (setq RBD_MainValueList (mapcar '(lambda (RBD_Property) (if (= (type (setq RBD_Value (vlax-get-property RBD_Block RBD_Property))) 'VARIANT) (vlax-safearray->list (vlax-variant-value RBD_Value)) RBD_Value)) RBD_PropertyList))
                     (foreach RBD_CheckBlock (cddr RBD_PointItem)
                        (setq RBD_CheckValueList (mapcar '(lambda (RBD_Property) (if (= (type (setq RBD_Value (vlax-get-property RBD_Block RBD_Property))) 'VARIANT) (vlax-safearray->list (vlax-variant-value RBD_Value)) RBD_Value)) RBD_PropertyList))
                        (if
                           (not (vl-some 'null (mapcar '(lambda (RBD_MainValue RBD_CheckValue) (equal RBD_MainValue RBD_CheckValue)) RBD_MainValueList RBD_CheckValueList)))
                           (setq RBD_DeleteList (cons RBD_CheckBlock RBD_DeleteList))
                        )
                     )
                  )
               )
            )
         )
         (if
            RBD_DeleteList
            (progn
               (vla-StartUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
               (foreach RBD_Block RBD_DeleteList
                  (vla-Delete RBD_Block)
               )
               (vla-EndUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
            )
         )
      )
   )
   (princ)
)
Message 9 of 18

scarroll
Explorer
Explorer

CADffm I cannot give you a dwg due to my companies policies, but here is the results from my LIST with two duplicates on the same snap point:

 

Command: LIST
2 found

BLOCK REFERENCE Layer: "SLH70"
Space: Model space
Handle = 5bc
Block Name: "SLH70"
Anonymous Name: "*U22"
at point, X= 33.5438 Y= 9.0186 Z= 12.0177
X scale factor: 1.0000
Y scale factor: 1.0000
rotation angle: 0
Z scale factor: 1.0000
InsUnits: Millimeters
Unit conversion: 0.0394
Scale uniformly: No

0 Likes
Message 10 of 18

scarroll
Explorer
Explorer

DannyNL what is this?

0 Likes
Message 11 of 18

DannyNL
Advisor
Advisor

What is what?

You are asking for a LISP to remove duplicate blocks and that is what that code is for Smiley Happy

0 Likes
Message 12 of 18

scarroll
Explorer
Explorer

So, we are on the right path! Thank you very much for your help!! I tried the code you wrote and it is deleting the duplicates but its also deleting some items all together and some duplicate components remain. Is it possible to include with in the code 'if qty>1' to remove those components?   Could you help with these two items in the coding?   Thanks once again for all your help DannyNL!

0 Likes
Message 13 of 18

scarroll
Explorer
Explorer

@DannyNLAny luck with what I had brought up last post? 

0 Likes
Message 14 of 18

DannyNL
Advisor
Advisor

I've been quite busy the last weeks and did not have time to monitor the forum each day, so I'd missed your last question. But the code should do exactly as you are requesting and should only remove duplicates and leave one (so the qty>1 is already in effect).

 

BUT is does check on all those properties as included in the code and if one of those properties does not match, it will not be considered a duplicate. 

It is also difficult to test a routine with no example drawing from your side. I know you'd mentioned you are not able to provide one, but that does mean I need to create one myself and with those the code does work. So I'm not able to tell why in your case it sometimes works and sometimes it doesn't, without being able to check the blocks/objects on which the routine fails.

0 Likes
Message 15 of 18

Anonymous
Not applicable

Hi Sir, I have the same issue, multiple blocks in the same base point but different names. 

 

Is there any way to kill duplicate blocks. 

Message 16 of 18

karpki
Advocate
Advocate

Hi Danny

 

Could you please help.

Is it possible to recode your LISP a bit to find and delete duplicated hatches not blocks ? I'm too new in coding to make it myself.

Hathes are made by same boudary, could be in same or different layers and colours. They are not visible often cause have same hatch style and angle

 

Thank you in advance

BRegards

0 Likes
Message 17 of 18

kirkwj
Explorer
Explorer

It doesn't seem to be responding to "rotation" If the blocks have the same insertion point and one is at 0 rotation, one at 270, one at 180 and one at 90 it deletes 3 and leaves only one. It should leave them all as they are at different rotations.

0 Likes
Message 18 of 18

lee.pellegrin
Enthusiast
Enthusiast

Have you considered using selection cycling?

0 Likes