Hatching via LSP

Hatching via LSP

joe_kohli
Advocate Advocate
1,126 Views
9 Replies
Message 1 of 10

Hatching via LSP

joe_kohli
Advocate
Advocate

I want to create a command button to control a custom hatch. What should my program look like in a LSP? Below is all I have got to. I'm trying my best to learn LSP code but it is taking more time than I thought. I need it to place the hatch under layer "NOT IN SERVICE" and the hatch type to be ANSI37. So when I have a shape that I need to fill with hatch, simply press the command button in the Tool Palette and it will hatch the area selected.

 

(defun c:hatch (/)
(command

"-layer" "set" "NOT IN SERVICE" ""

)
)

 

 

0 Likes
Accepted solutions (1)
1,127 Views
9 Replies
Replies (9)
Message 2 of 10

paullimapa
Mentor
Mentor

Looks similar to this


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 10

pendean
Community Legend
Community Legend

@joe_kohli Are you aware of this system variable by chance? No need to ever get into Layer command for example

pendean_0-1718652670154.png

 

 

AND... these others will help you make quick selections too

pendean_1-1718652760100.pngpendean_2-1718652807728.pngpendean_3-1718652828669.png

 

pendean_4-1718652854879.png

 

and more

https://help.autodesk.com/view/ACD/2025/ENU/index.html?guid=GUID-B94870E7-49CE-4BB0-A978-382A38E1FED...

0 Likes
Message 4 of 10

Kent1Cooper
Consultant
Consultant

@joe_kohli wrote:

....

(defun c:hatch (/)
(command

"-layer" "set" "NOT IN SERVICE" ""

)
)


In addition to @pendean 's information about Hatch-related System Variables, I would suggest that you not use "hatch" as the command name, unless you always want all Hatch patterns on that Layer and in that pattern and so on.  Use a command name that's appropriate to what you want this custom situation used for, for example:

 

(defun C:HATCHNIS ()

  (setvar 'hplayer "NOT IN SERVICE")

  (setvar 'hpname "ANSI37")

  ;  ... ETC. ... [angle, scale, whatever]

  (command "_.hatch"); leave you in it

)

 

Or if you really always want all Hatch patterns the same, and want to use the HATCH command name, you should build in an UNDEFINE command for HATCH before defining the command name differently.

Kent Cooper, AIA
0 Likes
Message 5 of 10

joe_kohli
Advocate
Advocate

Ok, so this is the code that I am using and it is working quite well. I added a command to my tool palette that allows me to select an area and hatch it with the settings I am accustomed to. I know there is probably a better way but I think this will suffice for my needs. 

 

(defun c:HatchNIS (/ la)
(setq la (getvar "clayer"))
(command "-layer" "S" "NOT IN SERVICE" "")
(command "-hatch" "Properties" "ANSI37" 1 0 pause "")
(setvar "clayer" la)
(princ)
)

 

My problem is that when I hatch the area it does not bring the hatch above all objects with the parameter cloud. I believe this is because I am missing "Associative" - "Ignore Island Detection". How can I add this feature to the code?

joe_kohli_0-1719429962607.png

 

 

0 Likes
Message 6 of 10

paullimapa
Mentor
Mentor

Hpassoc controls hatch associativity

So you can save the current setting, set it to what you want, then do hatch and restore to original setting

You can also include after hatch creation to bring the last object to the front like examples here

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 7 of 10

paullimapa
Mentor
Mentor

also consider HpDrawOrder


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 8 of 10

joe_kohli
Advocate
Advocate

I would rather just have it in the LSP instead of having it in the settings of Autocad.

0 Likes
Message 9 of 10

Kent1Cooper
Consultant
Consultant
Accepted solution

Associativity and Island detection are two independent settings.  Try this:

(command
  "_.-hatch" "_advanced" "_island" "_no" "" ""
  "_properties" "ANSI37" 1 0 "_select" pause "" ""
)

[There are probably some different sequences of options that can get you there, including via BHATCH rather than HATCH.]

Kent Cooper, AIA
0 Likes
Message 10 of 10

joe_kohli
Advocate
Advocate

Kent, that worked!!

0 Likes