LISP suchen und löschen

Hallo zusammen,

ich habe folgenden LISP Code:

(defun c:fogl ()
(command "_.erase" (ssget "all" '((0 . "SOLID"))))
(command "_.erase" (ssget "_X" '((0 . "INSERT") (2 . "`*U*"))) "")
)

Leider funktioniert das so nicht richtig, sollte es in der Zeichnung keine SOLID's geben,
wird der Code abgebrochen. Wie erreiche ich es, dass trotz fehlender SOLID's auch die
undefinierten Blöcke gelöscht werden?

Gruß
Klaus

Comments

  • ....

    (defun c:fogl ()
    (command "_.erase" (ssget "all" '((0 . "SOLID"))))
    (command "_.erase" (ssget "_X" '((0 . "INSERT") (2 . "`*U*"))) "")
    )

    Unfortunately, this does not work properly if there are no SOLIDs in the drawing, the code will be aborted. How do I achieve that despite the lack of SOLID's also the undefined blocks are deleted? ....
    When you enter only the third line of code, on the Command line, does that successfully remove undefined blocks? It doesn't do that for me in v17. In fact, it causes problems, so that I have to re-start Bricscad. I don't know why.

    But if I remove that line, and replace it with (command "zoom" "all"), then fogl just zooms to all with no problem. I have the 2D version of Bricscad, so my files have no Solids in them.
  • Try adding some IF statements to your LISP to check whether a selection set has been created before attempting to run the command.
    (defun c:fogl ( / sset_solid sset_insert)
    	; For ssget options see Lee Mac's http://www.lee-mac.com/ssget.html
    
    	; SSget All will select all objects except those on frozen layers.
    	(setq sset_solid (ssget "all" '((0 . "SOLID"))))
    	(if sset_solid ; if the sset is not nil
    		(command "_.ERASE" sset_solid "") ; then run our command
    		(princ "\nNo SOLIDS found") ; otherwise print a message
    	)
    
    	(setq sset_insert (ssget "_X" '((0 . "INSERT") (2 . "`*U*"))))
    	(if sset_insert ; if the sset is not nil
    		(command "_.ERASE" sset_insert "") ; then run our command
    		(princ "\nNo Anonymous Blocks found") ; otherwise print a message
    	)
     (prin1)
    )

    Regards,
    Jason Bourhill
    BricsCAD V23 Ultimate
    CAD Concepts