LookiLisp to Hatch multiple objects on multiple layers as single hatch per layer

LookiLisp to Hatch multiple objects on multiple layers as single hatch per layer

zasanil
Advocate Advocate
1,525 Views
4 Replies
Message 1 of 5

LookiLisp to Hatch multiple objects on multiple layers as single hatch per layer

zasanil
Advocate
Advocate

Hello,

I've searched and couldn't find precisely what I was looking for here.

I would like to take a selection set, which has multiple objects across multiple layers, and cycle through each layer creating a single hatch of only the selected objects on that layer. Then it would go to he next layer and hatch only what was selected for that layer, etc.

It would use the current hatch setup that I have which for my case is a solid hatch, normal island detection, scale 1, color by layer and hatch by layer. If anyone has seen a routine like this please let me know.

Thanks

 

Dan Nicholson C.I.D.
PCB Design Engineer
0 Likes
Accepted solutions (1)
1,526 Views
4 Replies
Replies (4)
Message 2 of 5

Kent1Cooper
Consultant
Consultant
Accepted solution

@zasanil wrote:

....

I would like to take a selection set, which has multiple objects across multiple layers, and cycle through each layer creating a single hatch of only the selected objects on that layer. Then it would go to he next layer and hatch only what was selected for that layer, etc.

 

....

Try this [very lightly tested, and without the usual enhancements yet]:

 

(defun C:HBL (/ ss n laylist); = Hatch By Layer
  (prompt "\nTo Hatch objects collectively for each included Layer,")
  (if (setq ss (ssget))
    (progn ; then
      (repeat (setq n (sslength ss))
        (if (not (member (setq layname (cdr (assoc 8 (entget (ssname ss (setq n (1- n))))))) laylist))
          (setq laylist (cons layname laylist))
        ); if
      ); repeat
      (foreach layname laylist
        (sssetfirst nil ss); pre-select all for filtered implied-selection below
        (command
          "_.hatch" "_solid" (ssget "_I" (list (cons 8 layname))) "" ""
          "_.chprop" "_last" "" "_layer" layname ""
        ); command
      ); foreach
    ); progn
  ); if
); defun

I thought it should work with one less Enter [""] at the end of the Hatch command, but it seems to want two of them -- that may be affected by your version, so if it doesn't work, the first thing I'd try is removing one of those.

Kent Cooper, AIA
Message 3 of 5

zasanil
Advocate
Advocate

It runs and it looks like its doing something to each layer, but when it finishes running, there is nothing there. I tried it both ways (with and without the second set of quotes). I made sure to check for fill-on also.

 

Dan Nicholson C.I.D.
PCB Design Engineer
0 Likes
Message 4 of 5

Kent1Cooper
Consultant
Consultant

@zasanil wrote:

It runs and it looks like its doing something to each layer, but when it finishes running, there is nothing there. I tried it both ways (with and without the second set of quotes). I made sure to check for fill-on also.

 


Then I suggest doing this:

 

(command "_.hatch")

 

to get the same operational version of the command that the AutoLisp is getting [certain things are different even in the -Hatch command-line version from the (command)-function version, at least in some versions of AutoCAD], and take note of exactly what it's asking for and in what order, and supply appropriate answers to those prompts.

Kent Cooper, AIA
Message 5 of 5

zasanil
Advocate
Advocate

It's working now.

I change

(ssget "_I" (list (cons 8 layname)))

to read

(ssget "_P" (list (cons 8 layname)))

and it seems to have fixed it.

Thank you Kent!

Dan Nicholson C.I.D.
PCB Design Engineer
0 Likes