LISP - breaking unhandy entities

Hello there!

i'm working on an interface to read out entity information from .dwg drawings. On the LISP side of the interface to be exact. Now there are certain entities which are problematic to read out,  or just slow to read or difficult to read on the Delphi side of the interface.
To avoid These entities but still retrieve their information, I simply explode them to more simple entities. The routine works pretty fine on everything directly in the modelspace, but it gets problematic when something is capsuled in a block/insert. Now since I can't directly edit blocksin BricsCAD I work around it with the refedit-command, but I seem to handle it the wrong way.

[code]
(defun breakUnhandyEntities (/ entName entity entTyp explode)
 (foreach entName (Blk_ENameLstNstd "*Model_Space")
  (if (setq entity(entget entName))
   (if (setq entTyp(cdr(assoc 0 entity)))
    (if(wcmatch entTyp "INSERT,3DSOLID,REGION,SURFACE,BODY,MTEXT,DIMENSION,POLYLINE")
     (cond
      ((= entTyp "INSERT")
       (command "._REFEDIT" (list entName (trans(cdr(assoc 10 entity))(cdr(assoc 210 entity)) 0)) "_ok" "_all" "_yes")
       (explodeByObject(list '((100 . "ACDBMODELERGEOMETRY"))'((100 . "ACDBMODELERGEOMETRY"))'((100 . "ACDBMODELERGEOMETRY"))'((100 . "ACDBMODELERGEOMETRY"))'((100 . "ACDBPOLYLINE"))'((100 . "ACDBPOLYGONMESH"))'((100 . "ACDBMLINE"))'((100 . "ACDBDIMENSION"))'((100 . "ACDB2DPOLYLINE"))'((100 . "ACDB3DPOLYLINE"))'((100 . "ACDBMTEXT"))))
       (command "._REFCLOSE" "")
       ;(return) ;;;?
      )
      ((wcmatch entTyp "3DSOLID,BODY,SURFACE,REGION")           
       (explodeByObject(list '((100 . "ACDBMODELERGEOMETRY"))'((100 . "ACDBMODELERGEOMETRY"))'((100 . "ACDBMODELERGEOMETRY"))'((100 . "ACDBMODELERGEOMETRY"))))
       ; (return)
      )
      ((wcmatch entTyp "MTEXT,DIMENSION,POLYLINE")
       (command "._EXPLODE" entName)
       ; (return)
      )
     )
    
    )
   )
  )
 )
) ;;; ende breakUnhandyEntities
;;; -
(defun explodeByObject (objLst / explode)
 (foreach explode objLst
  (if (setq insSet (ssget "x" explode))
   (command "._EXPLODE" insSet)
  )
 )
);;; ende explodeByObject
;;; -
[/code]

Now I assume the error to be in the (= entTyp "INSERT") case but it might aswell be the explodeByObject function itself.

Thank you for your help in advance.

And before I forget it: I'm actually german, but I post this on the international forum to read a wider range of people, so please excouse, if I make some grammar and spelling misstakes.

Comments

  • Hello Steven,

    "Gruß aus Heidelberg" ....
    I am using English to reach a wider audience...like you...
    So i would take a more hierarchical way to explode the entities !
    First you explode the "Containers" the Block Inserts until you don't have any of them in the Drawing,
    because they can contain everything,  themselves NESTED and 3DSOLIDS, REGIONs, SURFACEs, BODies, MTEXT, DIMENSIONs, POLYLINEs etc
    >>>>Then the SOLID3D entities, they can contain Surfaces, Bodies,  Regions ....
    >>>>>>>>Then the Surfaces because they may contain Bodies...
    >>>>>>>>>>>>Then the Bodies...
    >>>>>>>>>>>>>>>>>Then Regions
    >>>>>>>>>>>>>>>>>>>>>> at Last ALL other entities
    Here is a little Autolisp Routine :

    [code]
    ; Simplify  Entities...

    (defun C:SENT ( / ssBlockIns ssSol3D ssSurf3D ssBody ssRegion ssRest)

     ; 1.  find ALL INSERTS and recursively explode them and their NESTED INSERTS !

     (while (setq ssBlockIns (ssget "X" (list (cons 0 "INSERT"))))
      (command "._EXPLODE" ssBlockIns)
     
      )

     ; 2. find ALL 3D SOLIDS and explode them !

     (while (setq ssSol3D (ssget "X" (list (cons 0 "3DSOLID"))))
      (command "._EXPLODE" ssSol3D)
     
      )

     ; 3  find ALL SURFACES and explode them (also those from previously exploded Solids) !

     (while (setq ssSurf3D (ssget "X" (list
                                       (cons -4  "                                   (cons 0 "SURFACE")
                                       (cons 0 "LOFTEDSURFACE")
                                       (cons 0 "SWEPTSURFACE")
                                       (cons 0 "PLANESURFACE")
                                       (cons 0 "REVOLVEDSURFACE")
                                       (cons -4  "OR>")
                                       )
                                  )
                  )
      (command "._EXPLODE" ssSurf3D)
     
      )

     ; 4  find ALL BODIES and explode them (also those from previously exploded 3D SOLIDS AND SURFACES) !

     (while (setq ssBody (ssget "X" (list (cons 0 "BODY"))))
      (command "._EXPLODE" ssBody)
      )

     ; 5 find ALL REGIONS and explode them...

     (while (setq ssRegion (ssget "X" (list (cons 0 "REGION"))))
      (command "._EXPLODE" ssRegion)
      )

     ; 6. find ALL MTEXT, DIMENSION, POLYLINE and explode them ...

     (while (setq ssRest (ssget "X" (list
                                     (cons -4  "                                 (cons 0 "MTEXT")
                                     (cons 0 "LWPOLYLINE")
                                     (cons 0 "DIMENSION")
                                     (cons -4  "OR>")
                                     )
                                )
                  )
      (command "._EXPLODE" ssRest)
      )

     )
    [/code]

    I hope this works

    Regards
    (mit freundlichem Gruß )

  • OOPS,
    The Surfaces code is somehow not complete, an error by pasting ....
    So again the correct code :

    ; Simplify  Entities...

    (defun C:SENT ( / ssBlockIns ssSol3D ssSurf3D ssBody ssRegion ssRest)

     ; 1.  find ALL INSERTS and recursively explode them and their NESTED INSERTS !

     (while (setq ssBlockIns (ssget "X" (list (cons 0 "INSERT"))))
      (command "._EXPLODE" ssBlockIns)
     
      )

     ; 2. find ALL 3D SOLIDS and explode them !

     (while (setq ssSol3D (ssget "X" (list (cons 0 "3DSOLID"))))
      (command "._EXPLODE" ssSol3D)
     
      )

     ; 3  find ALL SURFACES and explode them (also those from previously exploded Solids) !

     (while (setq ssSurf3D (ssget "X" (list
                                       (cons -4  "                                   (cons 0 "SURFACE")
                                       (cons 0 "LOFTEDSURFACE")
                                       (cons 0 "SWEPTSURFACE")
                                       (cons 0 "PLANESURFACE")
                                       (cons 0 "REVOLVEDSURFACE")
                                       (cons -4  "OR>")
                                       )
                                  )
                  )
      (command "._EXPLODE" ssSurf3D)
     
      )

     ; 4  find ALL BODIES and explode them (also those from previously exploded 3D SOLIDS AND SURFACES) !

     (while (setq ssBody (ssget "X" (list (cons 0 "BODY"))))
      (command "._EXPLODE" ssBody)
      )

     ; 5 find ALL REGIONS and explode them...

     (while (setq ssRegion (ssget "X" (list (cons 0 "REGION"))))
      (command "._EXPLODE" ssRegion)
      )

     ; 6. find ALL MTEXT, DIMENSION, POLYLINE and explode them ...

     (while (setq ssRest (ssget "X" (list
                                     (cons -4  "                                 (cons 0 "MTEXT")
                                     (cons 0 "LWPOLYLINE")
                                     (cons 0 "DIMENSION")
                                     (cons -4  "OR>")
                                     )
                                )
                  )
      (command "._EXPLODE" ssRest)
      )

     )
  • I see again errors in the code...
    The symbols  (cons -4  "") dont get properly copied ...
    So please find the code in the attachment :

    SENT.LSP

  • This problem has also been posted @ theswamp:
    http://www.theswamp.org/index.php?topic=44885.0

    @ Konstantin: You could also use a single while loop with a single, long, ssget filter. You would then not have to worry about the order.
  • @ Roy : Yes of course...
    But i wanted to stick on order just to make things explicit !
    It is good to know what contains what in the database particularly by destructive exploding operations...
This discussion has been closed.