Jump to content

Script to select and delete block not working


pixel8er

Recommended Posts

Hi everyone

 

This simple script to select and delete the COS_DWGS_STATUS dynamic block from a series of drawings is not working. Any ideas?

 

(command "erase" (SSGET "X" '((0 . "INSERT") (2 . "COS_DWGS_STATUS" ))) "")

 

Thanks

Paul

Edited by pixel8er
Link to comment
Share on other sites

You will need to check for dynamic block

 

a block and dynamic has 2 names you can look at

 

dynamic block

EffectiveName (RO) = "bolt"

Name = "*U200"

 

std block

EffectiveName (RO) = "NORTHN"

Name = "NORTHN"

 

This has no error checking and will delete all.

(defun delblock ( / ss x)
(setq ss (SSGET "X" '((0 . "INSERT"))))
(repeat (setq x (sslength ss))
(setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
(if (= (vla-get-EffectiveName obj) "COS_DWGS_STATUS")
(vla-delete obj)
)
)
(princ)
)
(delblk)

Link to comment
Share on other sites

Thanks BIGAL, Champion! That worked perfectly. Just needed to adjust the function definition.

 

 

 

This has no error checking and will delete all.

(defun delbl[b][color="red"]oc[/color][/b]k ( / ss x)
(setq ss (SSGET "X" '((0 . "INSERT"))))
(repeat (setq x (sslength ss))
(setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
(if (= (vla-get-EffectiveName obj) "COS_DWGS_STATUS")
(vla-delete obj)
)
)
(princ)
)
(delblk)

Link to comment
Share on other sites

Dont forget the last one or make a C:delblock

 

Me personally pick the block get its effective name then run the code no need for hard coded block name. Error check added to make sure it was a block.

 

(defun delblock ( / ss x effname)
 (if   (and 
         (setq obj (vlax-ename->vla-object (car (entsel "\nPick block/s to delete "))))
         (= (vla-get-objectname obj) "AcDbBlockReference")
         )
 (progn
   (setq effname (vla-get-EffectiveName obj))
   (setq ss (SSGET "X" '((0 . "INSERT"))))
   (repeat (setq x (sslength ss))
       (setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
         (if (= (vla-get-EffectiveName obj) effname)
           (vla-delete obj)
         )
       )
   )
 (alert "you did not pick a block")
 )
(princ)
)
(delblock)

Edited by BIGAL
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...