Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Delete all solid hatches

33 REPLIES 33
SOLVED
Reply
Message 1 of 34
kameron1967
31523 Views, 33 Replies

Delete all solid hatches

Hi guys,

 

I would like to be able to go into a drawing and delete all solid hatches from all layers.  Is this possible?  Thank you kindly. 🙂

 

Kameron

33 REPLIES 33
Message 2 of 34
Lee_Mac
in reply to: kameron1967

The following will delete all solid hatches from all layouts and from within blocks & nested blocks (nested to any level):

 

(defun c:delsolhat ( / d )
    (vlax-for b (vla-get-blocks (setq d (vla-get-activedocument (vlax-get-acad-object))))
        (if (= :vlax-false (vla-get-isxref b))
            (vlax-for o b
                (if (and (= "AcDbHatch" (vla-get-objectname o))
                         (= "SOLID" (strcase (vla-get-patternname o)))
                         (vlax-write-enabled-p o)
                    )
                    (vla-delete o)
                )
            )
        )
    )
    (vla-regen d acallviewports)
    (princ)
)
(vl-load-com) (princ)

 

Tags (1)
Message 3 of 34
Lee_Mac
in reply to: kameron1967

Alternatively, for primary hatches only (in all layouts):

 

(defun c:delsolhat ( / i s )
    (if (setq s (ssget "_X" '((0 . "HATCH") (2 . "SOLID"))))
        (repeat (setq i (sslength s)) (entdel (ssname s (setq i (1- i)))))
    )
    (princ)
)

 

Message 4 of 34
kameron1967
in reply to: Lee_Mac

Awesome, Lee. I'll give them a try and will let you know. 🙂

 

Update:  I tried it and it did not appear to have removed the solid hatches.  I listed it and it shows solid.  My guess is that it's truly a solid, not a solid hatch. Is it possible to update your routine to also include a solid?  Thanks again Lee!

Message 5 of 34
kameron1967
in reply to: kameron1967

Lee, the solid does not have z dimensions.  I think it was converted from other 3D software.  Anyways, I was able to do a quick selection, but then I'd have to specify its exact layer in order to delete them and there are at least 20 layers that have these 3D solid acting as hatches.

 

Thank you sir.

Message 6 of 34
Lee_Mac
in reply to: kameron1967

kameron1967 wrote:

Update:  I tried it and it did not appear to have removed the solid hatches.  I listed it and it shows solid.  My guess is that it's truly a solid, not a solid hatch. Is it possible to update your routine to also include a solid?  Thanks again Lee!

 

To clarify: there should be nothing wrong with the posted code based on the original request. The two supplied programs will successfully remove all solid hatches from all layouts of a drawing, as described in the two posts.

 

From what you have described, it would seem that the issue is the objects you need to delete are not hatches, but rather solids.

 

I would suggest using either the SSX or FILTER commands to make the appropriate selection, and then erase the active selection.

Message 7 of 34
Kent1Cooper
in reply to: kameron1967


@kameron1967 wrote:

... I was able to do a quick selection, but then I'd have to specify its exact layer in order to delete them ....



I don't think that's the case.  You should be able to get into QSELECT, and in the Object type: section, pull down the list and select the appropriate kind of Solid, and in the Operator: section, pull it down and pick Select All.  It should find all of them regardless of Layer [or color, or....] -- hit the Delete button or type E for Erase.

Kent Cooper, AIA
Message 8 of 34
kameron1967
in reply to: Lee_Mac

You're absolutely right, Lee. Your nicely written routines (both) worked like a charm on solid hatches. Thank you, those would come in handy as well! 🙂

I will do as you suggested.
Message 9 of 34
kameron1967
in reply to: Kent1Cooper

Ken1Cooper - you're right. I was able to do a select all, so that works. Thanks. I miscommunicated about the hatching. So both you and Lee came up with the solutions. Thanks a lot gents! Kudos to you both! 🙂
Message 10 of 34
Anonymous
in reply to: Lee_Mac

Hello everyone, 
I tried using the lisp mentioned ,
only that removes only the
hatches and solids remain , you have a solution ?
Mirco

Message 11 of 34
pbejse
in reply to: Anonymous


@Anonymous wrote:
Hello everyone, 
I tried using the lisp mentioned ,
only that removes only the
hatches and solids remain , you have a solution ?
Mirco


From
(= "SOLID" (strcase (vla-get-patternname o)))
to (= "_SOLID" (strcase (vla-get-patternname o)))

 

But the code from this thread will Delete ALL solid hatch.  I could've sworn i replied to your psot on another Forum [ CTT ] where you're asking for solid hatch inside blocks only.

 

Message 12 of 34
owitzki
in reply to: pbejse

Can you also include in this apps deleting all dimensions?

Message 13 of 34
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:
....that removes only the hatches and solids remain , you have a solution ?
....

Yes, an old post....

 

If you're still out there, welcome to these Forums!  By "solids" that remain, do you mean 3D Solids, or the 2D ones made with the SOLID command?  It would be a simple matter to add an appropriate entity type to the selection part.

Kent Cooper, AIA
Message 14 of 34
owitzki
in reply to: owitzki

Please also add set all colors 'bylayer'?

 

Thanks a lot!

 

Kudos to the experts, the routine above alone helps me a lot. Even better if all dimensions be deleted & set all layer color bylayer! cheers!

Message 15 of 34
Kent1Cooper
in reply to: owitzki


@owitzki wrote:

Can you also include in this apps deleting all dimensions?


Welcome to these Forums!

 

Do you mean to delete all Dimensions along with all Solid Hatch patterns?  Or are you looking for something to delete all Dimensions only?

 

It gets a little more complicated, because the ObjectName VLA Property [the "AcDbHatch" part in @Lee_Mac's code] varies among different types of Dimensions, but I believe at least they all end with "Dimension."  If you want Dimensions along with Solid Hatches, try this modification [untested]:

....
                (if
                  (and
                    (or
                      (and ; Solid Hatches:
                        (= "AcDbHatch" (vla-get-objectname o))
                        (= "SOLID" (strcase (vla-get-patternname o)))
                      ); and
                      (wcmatch (vla-get-objectname o) "*Dimension")
                    ); or
                    (vlax-write-enabled-p o)
                  ); and
                  (vla-delete o); then
                ); if
....
Kent Cooper, AIA
Message 16 of 34
Kent1Cooper
in reply to: owitzki


@owitzki wrote:

Please also add set all colors 'bylayer'?

....


Adding a line to my previous Reply should do it:

 

                  ); and
                  (vla-delete o); then
                  (vla-put-Color o 256); else
                ); if
....
Kent Cooper, AIA
Message 17 of 34
owitzki
in reply to: Kent1Cooper

Yes please, along with solid hatch and solid entity if not too much... Smiley Happy tnx

Message 18 of 34
owitzki
in reply to: Kent1Cooper

It works seamlessly! Thanks

Message 19 of 34
Anonymous
in reply to: kameron1967

Is it possible to modify this code, so that for example only solid hatches in White is deleted ?


 


 

Message 20 of 34
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:

Is it possible to modify this code, so that for example only solid hatches in White is deleted ? 

 


Welcome to these Forums!

 

Do you mean such objects that are white because that is the color of the Layer they are drawn on [and their color is BYLAYER]. or those that are white for being given a color override [their color is 7]?  Either can be done pretty easily, but it makes a difference.

Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report