Jump to content

Recommended Posts

Posted (edited)

Hi all!

 

Please, someone can help me with this? I make this following LISP for edit a block and erase solids and hatch, but I need click one by one.

 

I want make a window selection and then the LISP edit one by one alone.

 

(defun C:Clean()
(vl-load-com)
(cond ((and (setq ent (car (entsel "\nSelecione o Bloco: ")))
(eq (cdr (assoc 0 (entget ent))) "INSERT")
(setq NAME (vla-get-effectivename(vlax-ename->vla-object ent))))))
(command "-bedit" NAME)
(setq HT (ssget "all" '((0 . "HATCH"))))
(command "erase" HT "")
(setq SS (ssget "all" '((0 . "SOLID"))))
(command "erase" SS "")
(command "chprop" "all" "" "Color" "bylayer" "")
(command "bclose" "S")
(princ)
)

 

 

Thanks!

Edited by Marcelo Marani
Posted

A few suggestions maybe zoom in on each block or hatch and ask delete yes /no use as a yes any key as a no. You just need to use the following example code. This is not complete.

 

(sslength ht) ; this tells you how many objects
(repeat (sslength ht)) ;a loop that goes through all the object in the selection set
(ssname ht x) ; this retrieves the object based on the value of x start at 0
(command "erase" (ssname ht x) "") ; removes object
(entget (ssname ht 2)) ; look at 2nd object in HT use this for zooming etc

Posted

Thanks for reply BIGAL,

 

but I dont understand where I can place this codes....

 

For example, the client send me a file with many blocks with solids and hatchs inside of the block, and I need erase all solids and hatchs inside off all blocks...

Posted

Not tested, but try:

 

(defun C:Clean ( / bl ss i ent name h s )
 (vl-load-com)
 (setq bl (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))
 (while (not ss)
   (if (setq ss (ssget "_:L" '((0 . "INSERT"))))
     (progn
       (setq i -1)
       (while (setq ent (ssname ss (setq i (1+ i))))
         (setq name (vla-get-effectivename (vlax-ename->vla-object ent)))
         (if (eq (vla-get-isxref (vla-item bl name)) :vlax-false)
           (progn
             (command "_.bedit" name)
             (setq h (ssget "all" '((0 . "HATCH"))))
             (command "_.erase" h "")
             (setq s (ssget "all" '((0 . "SOLID"))))
             (command "_.erase" s "")
             (command "_.chprop" "all" "" "Color" "ByLayer" "")
             (command "_.bclose" "S")
           )
         )
       )
     )
     (prompt "\nEmpty sel.set... Select again...")
   )
 )
 (princ)
)

Posted

Also this, by Tharwat (updated to include "SOLID")

http://www.cadtutor.net/forum/showthread.php?80180-Deleting-Hatch-from-Blocks

 

 

(vl-load-com)
(defun c:Test (/ b o)
   ;;--- Tharwat 26.June.2013 ---;;  
   (or doc
       (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
   )
   (vlax-for b
             (vla-get-blocks
                 doc
             )
       (if (and
               (eq :vlax-false (vla-get-isLayout b))
               (eq :vlax-false (vla-get-isXref b))
           )
           (vlax-for o b
               (if [b][color=red](or[/color][/b]
                       (eq "AcDbHatch" (vla-get-objectname o))
                       [b][color=red](eq "AcDbSolid" (vla-get-objectname o))[/color][/b]
[b][color=red]                   )[/color][/b]
                   (vl-catch-all-apply 'vla-delete (list o))
               )
           )
       )
   )
   (vla-regen doc acAllViewports)
   (princ)
)

Posted
marko_ribar

Not tested, but try:

 

Thanks Marko_ribar... this works but edit all blocks in the drawing (around 1500) include block without hatchs and solids and get a "INTERNAL ERROR" and close AutoCad. (my fail dont explain better)

 

 

GP_

Also this, by Tharwat (updated to include "SOLID")

http://www.cadtutor.net/forum/showth...ch-from-Blocks

 

GP_

This work perfect! Thanks!

Posted

For edit blocks to change colors for "BYLAYER" is possible too?

Posted
For edit blocks to change colors for "BYLAYER" is possible too?

 

Add...

 

[color=slategray]................[/color]
[color=slategray]................[/color]
[color=slategray](vlax-for o b[/color]
[color=slategray]    (if (or[/color]
[color=slategray]            (eq "AcDbHatch" (vla-get-objectname o))[/color]
[color=slategray]            (eq "AcDbSolid" (vla-get-objectname o))[/color]
[color=slategray]        )[/color]
[color=slategray]        (vl-catch-all-apply 'vla-delete (list o))[/color]
       [color=red][b](vla-put-color o "256")[/b][/color]
[color=slategray]    )[/color]
[color=slategray])[/color]
[color=slategray]................[/color]
[color=slategray]................[/color]

Posted
For edit blocks to change colors for "BYLAYER" is possible too?

 

Try this one ...

 

(vl-load-com)
(defun c:Test (/ b o)
 ;;---     Tharwat 2014         ---;;
 (or doc (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))))
 (vlax-for b (vla-get-blocks doc )
   (if
     (and
       (eq :vlax-false (vla-get-isLayout b))
       (eq :vlax-false (vla-get-isXref b))
       )
     (vlax-for o b
       (if (or
             (eq "AcDbHatch" (vla-get-objectname o))
             (eq "AcDbSolid" (vla-get-objectname o))
             )
         (vl-catch-all-apply 'vla-delete (list o))
         (vl-catch-all-apply 'vla-put-color (list o AcBylayer))
         )
       )
     )
   )
 (vla-regen doc acAllViewports)
 (princ)
 )

Posted

Thanks! Work Perfect and very fast!

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...