Jump to content

Lisp for selecting hatches based on scale


toberino

Recommended Posts

Hello all,

I have a very monotonous task of cleaning up my backgrounds sent from architects prior to designing the structure. Currently to select the hatches properly and only the ones that I want to delete I have to invoke the quick select, select hatch from the object type, then scale, then type the scale from the properties, and then the value (which is usually 1, 24, 42, 70) depending on which arch I get them from and how they set up their plans.

I would like to automate this task and select all of the different scales in one swoop (lisp). And maybe even delete them too. Anyone have a routine that does something like this?

 

Here is the bottom line;

What I am trying to acheive is a routine that I only have to run once.

That will,

unlock all of the layers

turn on all of the layer

thaw all of the layers

 

delete all of the sheets

detach all of the xref's

 

select and delete certain hatches based off of their pattern scale. (because select similar does not work)

 

AND.....set layer to "0" and insert a point on location 0,0,0:shock:

 

AND...PURGE everything ....and -PURGE everything....:shock:

 

So..just a small request is all.:ouch:

 

Don't be :shock:

 

Okay, I got the first five steps.

So far it will unlock, turn on, and thaw.

And it will delete the sheets and detach the xref's.

The hatch is probably going to be the one to stump me.

 

:D:D:D:D:D:D

 

Looks like it will be an SSGET for the hatching. Now to get the filtering right.

Edited by toberino
Link to comment
Share on other sites

  • Replies 25
  • Created
  • Last Reply

Top Posters In This Topic

  • toberino

    12

  • Tharwat

    8

  • ttray33y

    5

  • danglar

    1

Hello all,

I have a very monotonous task of cleaning up my backgrounds sent from architects prior to designing the structure. Currently to select the hatches properly and only the ones that I want to delete I have to invoke the quick select, select hatch from the object type, then scale, then type the scale from the properties, and then the value (which is usually 1, 24, 42, 70) depending on which arch I get them from and how they set up their plans.

I would like to automate this task and select all of the different scales in one swoop (lisp). And maybe even delete them too. Anyone have a routine that does something like this?

 

Here is the bottom line;

What I am trying to acheive is a routine that I only have to run once.

That will,

unlock all of the layers

turn on all of the layer

thaw all of the layers

 

delete all of the sheets

detach all of the xref's

 

select and delete certain hatches based off of their pattern scale. (because select similar does not work)

 

AND.....set layer to "0" and insert a point on location 0,0,0:shock:

 

AND...PURGE everything ....and -PURGE everything....:shock:

 

So..just a small request is all.:ouch:

 

Don't be :shock:

 

Okay, I got the first five steps.

So far it will unlock, turn on, and thaw.

And it will delete the sheets and detach the xref's.

The hatch is probably going to be the one to stump me.

 

:D:D:D:D:D:D

 

Looks like it will be an SSGET for the hatching. Now to get the filtering right.

 

(defun C:test(/ ent count)
 (setvar "cmdecho" 0)
 (setq ent(ssget "X" (list(cons 0 "HATCH")(cons 41 [b][i]13[/i][/b]))))
;; line above change 13 with the value of your hatch
 (if (and ent (> (sslength ent) 0))
   (progn
     (setq count(sslength ent))
     (command "ERASE" ent "")
  (command "-xref" "D" "*" "")
  (command "-layer" "U" "*" "T" "*" "set" "0" "")
  (command "-purge" "all" "*" "n")
  ;;reserve for removal of sheet (i have no idea) 

     (alert (strcat "Erased " (itoa count) " Entities."))

   )
 )
 (setvar "cmdecho" 1)
 (princ)
)
(princ "\n Type test.")
(princ)

 

try this bro, however i have no idea how to delete sheet(s), also i'm not sure about "insert point" part.

Edited by ttray33y
Link to comment
Share on other sites

(defun C:test(/ ent count)
 (setvar "cmdecho" 0)
[color="red"]  (setq ent(ssget "X" (list(cons 0 "HATCH")(cons 41 [b][i]13[/i][/b]))))
;; line above change 13 with the value of your hatch
 (if (and ent (> (sslength ent) 0))
   (progn
     (setq count(sslength ent))
     (command "ERASE" ent "")[/color]
  (command "-xref" "D" "*" "")
  (command "-layer" "U" "*" "T" "*" "set" "0" "")
  (command "-purge" "all" "*" "n")
  ;;reserve for removal of sheet (i have no idea) 

     (alert (strcat "Erased " (itoa count) " Entities."))

   )
 )
 (setvar "cmdecho" 1)
 (princ)
)
(princ "\n Type test.")
(princ)

 

try this bro, however i have no idea how to delete sheet(s), also i'm not sure about "insert point" part.

 

Awesome!!!!

I have a couple of questions...see red above. Is that all of the hatch portion? I can piece things together but lack the brain power currently to force myself to learn it.

 

I figured out the delete all sheets part.

(vl-load-com)
(defun C:DELETESHEETS ()
 (vlax-for Layout (vla-get-Layouts (vla-get-ActiveDocument (vlax-get-acad-object)))
   (if	(/= (vla-get-Name Layout) "Model")
     (vla-Delete Layout)
   )
 )
)

 

I would like to narrow down the portion of the hatching so that I can get it modified just right for all of the hatches.

Link to comment
Share on other sites

Awesome!!!!

I have a couple of questions...see red above. Is that all of the hatch portion? I can piece things together but lack the brain power currently to force myself to learn it.

 

I figured out the delete all sheets part.

(vl-load-com)
(defun C:DELETESHEETS ()
 (vlax-for Layout (vla-get-Layouts (vla-get-ActiveDocument (vlax-get-acad-object)))
   (if	(/= (vla-get-Name Layout) "Model")
     (vla-Delete Layout)
   )
 )
)

 

I would like to narrow down the portion of the hatching so that I can get it modified just right for all of the hatches.

 

a short answer yes, oh i so you wanted to delete layout.. ehehehe

Link to comment
Share on other sites

(defun C:test(/ ent count)
 (setvar "cmdecho" 0)
 (setq ent(ssget "X" (list(cons 0 "HATCH")(cons 41 [b][i]13[/i][/b]))))
;; line above change 13 with the value of your hatch
 (if (and ent (> (sslength ent) 0))
   (progn
     (setq count(sslength ent))
     (command "ERASE" ent "")
  (command "-xref" "D" "*" "")
  (command "-layer" "U" "*" "T" "*" "set" "0" "")
  (command "-purge" "all" "*" "n")
  ;;reserve for removal of sheet (i have no idea) 

     (alert (strcat "Erased " (itoa count) " Entities."))

   )
 )
 (setvar "cmdecho" 1)
 (princ)
)
(princ "\n Type test.")
(princ)

 

try this bro, however i have no idea how to delete sheet(s), also i'm not sure about "insert point" part.

 

Okay. New question.

Eliminating all of the "other" stuff, including the alert. Would you be so kind to only show the hatch selection and not delete it in the end? I will have multiple hatch scales (1, 2, 24, 42, etc.) that I would like to also be selected at the same time. I have OCD so I need to see what has been selected prior to hitting the delete key so I would like it to only select all of them in one command and then I will delete after I have verified the correct selections.

 

Thanks again for the help!

Link to comment
Share on other sites

Okay. New question.

Eliminating all of the "other" stuff, including the alert. Would you be so kind to only show the hatch selection and not delete it in the end? I will have multiple hatch scales (1, 2, 24, 42, etc.) that I would like to also be selected at the same time. I have OCD so I need to see what has been selected prior to hitting the delete key so I would like it to only select all of them in one command and then I will delete after I have verified the correct selections.

 

Thanks again for the help!

 

just remove "X" including quotes

  (setq ent(ssget [color="red"]"X"[/color] (list(cons 0 "HATCH")(cons 41 13))))

Link to comment
Share on other sites

So here is what I have scrapped together so far.....and it works. I am sure it is not the most efficient code but it works. It seems to just blast through the routine so a couple of pauses to slow it down may be in order at some point. Maybe a break after selecting the hatches and an approval to delete would be neat. And a approval for the purge too. But this can be done later.

(Defun C:ArchWipe ()
(command "-LAYER" "U" "*" "")
(Command "-Layer" "On" "*" "")
(Command "-Layer" "Thaw" "*" "On" "*" "")
(command "-layer" "U" "*" "T" "*" "set" "0" "")

 (vlax-for Layout (vla-get-Layouts (vla-get-ActiveDocument (vlax-get-acad-object)))
   (if	(/= (vla-get-Name Layout) "Model")
     (vla-Delete Layout)
   )
 )
)
(ssget "X" (list (cons 0 "HATCH")))
(setq sset (ssget "P"))
(sssetfirst sset sset)
(princ)
)
(command "ERASE" ent "")
(command "-xref" "D" "*" "")
(command "-purge" "all" "*" "n")
)

When I invoke this routine inside the Block Editor it returns a message that says "Converting (command) calls to (command-s) is recommended." and it does not run the routine. Is it just as simple as adding the -s and would it work the same?

And, I just noticed something else now. The hatch selection doesn't always happen during the routine and when I come out of the appload dialog it starts up immediately and select all of the hatches. Something is definitely out of order.

 

Thanks ttray33y for the quick throw together of some code to get me going.

Edited by toberino
Link to comment
Share on other sites

So here is what I have scrapped together so far.....and it works. I am sure it is not the most efficient code but it works. It seems to just blast through the routine so a couple of pauses to slow it down may be in order at some point. Maybe a break after selecting the hatches and an approval to delete would be neat. And a approval for the purge too. But this can be done later.

(Defun C:ArchWipe ()
(command "-LAYER" "U" "*" "")
(Command "-Layer" "On" "*" "")
(Command "-Layer" "Thaw" "*" "On" "*" "")
(command "-layer" "U" "*" "T" "*" "set" "0" "")

 (vlax-for Layout (vla-get-Layouts (vla-get-ActiveDocument (vlax-get-acad-object)))
   (if	(/= (vla-get-Name Layout) "Model")
     (vla-Delete Layout)
   )
 )
)
(ssget "X" (list (cons 0 "HATCH")))
(setq sset (ssget "P"))
(sssetfirst sset sset)
(princ)
)
(command "ERASE" ent "")
(command "-xref" "D" "*" "")
(command "-purge" "all" "*" "n")
)

When I invoke this routine inside the Block Editor it returns a message that says "Converting (command) calls to (command-s) is recommended." and it does not run the routine. Is it just as simple as adding the -s and would it work the same?

And, I just noticed something else now. The hatch selection doesn't always happen during the routine and when I come out of the appload dialog it starts up immediately and select all of the hatches. Something is definitely out of order.

 

Thanks ttray33y for the quick throw together of some code to get me going.

 

(defun C:ArchWipe (/ ent )
 (setvar "cmdecho" 0)
 (setq ent(ssget (list(cons 0 "HATCH"))))
 (if (and ent (> (sslength ent) 0))
   (progn
(command "-LAYER" "U" "*" "")
(Command "-Layer" "On" "*" "")
(Command "-Layer" "Thaw" "*" "On" "*" "")
(command "-layer" "U" "*" "T" "*" "set" "0" "")

   )
 )
 (setvar "cmdecho" 1)
 (princ)
 (command "erase" ent "")
 (command "-xref" "D" "*" "")
   (vlax-for Layout (vla-get-Layouts (vla-get-ActiveDocument (vlax-get-acad-object)))
   (if	(/= (vla-get-Name Layout) "Model")
     (vla-Delete Layout)
   )
 )
 (command "-purge" "all" "*" "n")	
)
(princ)

 

purge wont work inside block editor.

Link to comment
Share on other sites

(defun C:ArchWipe (/ ent )
 (setvar "cmdecho" 0)
 (setq ent(ssget (list(cons 0 "HATCH"))))
 (if (and ent (> (sslength ent) 0))
   (progn
............................
 (setvar "cmdecho" 1)
 .......................
 (command "-purge" "all" "*" "n")	
)
(princ)

 

 

@ ttray33y , a few comments in general if you are interested and don't mind .

 

You set the system variable cmdecho and reset it back in the wrong place besides that , you assumed that the user's setting for it is 1 and it could be zero .

Your ssget function could be shortened as shown below besides that , you can include the if function with the ssget function instead of adding it below with many checks if the selection set is correct .

 

One more advise is to include the filter of LOCKED layers with the ssget function since that intended to erase the selected objects or at any other modification that might be required .

 

(if (setq ent (ssget "_:L" '((0 . "HATCH"))))
 ;;; ................ and so on

Link to comment
Share on other sites

@ ttray33y , a few comments in general if you are interested and don't mind .

 

You set the system variable cmdecho and reset it back in the wrong place besides that , you assumed that the user's setting for it is 1 and it could be zero .

Your ssget function could be shortened as shown below besides that , you can include the if function with the ssget function instead of adding it below with many checks if the selection set is correct .

 

One more advise is to include the filter of LOCKED layers with the ssget function since that intended to erase the selected objects or at any other modification that might be required .

 

(if (setq ent (ssget "_:L" '((0 . "HATCH"))))
 ;;; ................ and so on

 

thanks for the heads-up.

Link to comment
Share on other sites

thanks for the heads-up.

Not a problem .

 

I see that the title of the thread is to select hatches based on their scales , so to build on that request you need to use the DXF 41 as you may be interested to get info in this regard HERE

Link to comment
Share on other sites

Not a problem .

 

I see that the title of the thread is to select hatches based on their scales , so to build on that request you need to use the DXF 41 as you may be interested to get info in this regard HERE

 

That is where I started but once I found a routine that will select all hatches "only" with one command then I changed the direction of it.

Link to comment
Share on other sites

That is where I started but once I found a routine that will select all hatches "only" with one command then I changed the direction of it.

 

Best of luck ,

 

Do you still need any help with this thread ?

Link to comment
Share on other sites

Best of luck ,

 

Do you still need any help with this thread ?

 

Busy day today. Yes. I still have test out what ttray33y posted but i won't be able to until tomorrow.

Link to comment
Share on other sites

So this is what I have and it is logical order of how the steps should proceed. It selects the hatches as I exit the appload dialog which it shouldn't do. I don't really know what to do or how to organize it to work properly. Can anyone help me out, please?

(Defun C:ArchWipe ()
(command "-LAYER" "U" "*" "")
(Command "-Layer" "On" "*" "")
(Command "-Layer" "Thaw" "*" "On" "*" "")
(command "-layer" "U" "*" "T" "*" "set" "0" "")

 (vlax-for Layout (vla-get-Layouts (vla-get-ActiveDocument (vlax-get-acad-object)))
   (if	(/= (vla-get-Name Layout) "Model")
     (vla-Delete Layout)
   )
 )
)
(ssget "X" (list (cons 0 "HATCH")))
(setq sset (ssget "P"))
(sssetfirst sset sset)
(princ)
)
(command "ERASE" ent "")
(command "-xref" "D" "*" "")
(command "-purge" "all" "*" "n")
)

Link to comment
Share on other sites

So this is what I have and it is logical order of how the steps should proceed. It selects the hatches as I exit the appload dialog which it shouldn't do. I don't really know what to do or how to organize it to work properly. Can anyone help me out, please?

 

 

You want to enable the user to select the needed hatches or you want to delete this part from the program ?

Link to comment
Share on other sites

You want to enable the user to select the needed hatches or you want to delete this part from the program ?

 

I want it to select and delete the hatches please. But after I run the routine.

Link to comment
Share on other sites

Replace the following .

 

This

(Defun C:ArchWipe ()

With this .

(Defun C:ArchWipe (/ sset)

And this .

 

(ssget "X" (list (cons 0 "HATCH")))
(setq sset (ssget "P"))
(sssetfirst sset sset)
(princ)
)

With this .

(if (setq sset (ssget "_X" '((0 . "HATCH"))))
 (command "_.erase" [color=red]sset [/color]"")
 )

Link to comment
Share on other sites

Replace the following .

 

This

(Defun C:ArchWipe ()

With this .

(Defun C:ArchWipe (/ sset)

 

And this .

 

(ssget "X" (list (cons 0 "HATCH")))
(setq sset (ssget "P"))
(sssetfirst sset sset)
(princ)
)

With this .

(if (setq sset (ssget "_X" '((0 . "HATCH"))))
 (command "_.erase" ent "")
 )

 

(Defun C:ArchWipe (/ sset)
(command "-LAYER" "U" "*" "")
(Command "-Layer" "On" "*" "")
(Command "-Layer" "Thaw" "*" "On" "*" "")
(command "-layer" "U" "*" "T" "*" "set" "0" "")

 (vlax-for Layout (vla-get-Layouts (vla-get-ActiveDocument (vlax-get-acad-object)))
   (if	(/= (vla-get-Name Layout) "Model")
     (vla-Delete Layout)
   )
 )
)
(if (setq sset (ssget "_X" '((0 . "HATCH"))))
 (command "_.erase" ent "")
 )
[color="red"](command "ERASE" ent "")[/color]
(command "-xref" "D" "*" "")
(command "-purge" "all" "*" "n")
)

So I should be able to erase the red above since it seems to be included in the ssget for the hatch.?

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