Display full version of the post: Lisp - layer, command

Kajito
14.11.2013, 22:56
Hi guys,
I'd like to ask you for help with following. I'd say it is a fairly easy task if you know basics of LISP progamming ( I don't unfortunately :). I've been trying to search on the net but couldnt find any answer somehow.I need a lisp routine that would set a layer (say Hatch1), and start the hatch command. As "simple" as that ;).I've changed job recently and this company is using to different layers for hatch (hatch and shade). Therefore solutions like flay or new command with associated shortcut or alias will not work as it will alwys set the same layer.Thank you very much for any solutions and suggestions.Kajito

John Connor
15.11.2013, 12:24
This will set the layer.  As for the Hatch command itself is there any other criteria that has to be met?  Ex. - pattern to be used.(defun c:test ()
(command "_.layer" "_set" "hatch1" "")
(princ)
)
John Connor2013-11-15 12:35:38

John Connor
15.11.2013, 12:40
Example of a hatch lisp routine (by GHarvey) that sets the layer and calls out which hatch pattern will be used and specifies the hatch pattern will be applied to an object.(defun c:iso ()
(command "-layer" "S" "hatch" "")
(command "-hatch" "Properties" "ANSI37" 6 0 pause)
(command "-layer" "S" "object" "")
(princ)
)

Kent Cooper
15.11.2013, 14:43
I would recommend using the Make option rather than Set, because if the Layer does not exist in the drawing, it won't be able to be set current.  The Make option will also make it current, and will turn it on if it's off.  And I would recommend including a Thawing of the Layer before Making or Setting it, because if it's frozen, it won't be able to be made current; the Thaw option won't care whether the Layer exists yet or not.
 
(defun C:HATCH1 ()
  (command
    "_.layer" "_thaw" "HATCH1" "_make" "HATCH1" ""
    "_.hatch" ; or "_.bhatch" if preferred
  )
)
 
That will leave you in the Hatch command, to complete as you like.
 
If you want a particular pattern, you can build that into the Hatch command, or you can first use (setvar 'hpname "WHATEVER") and make it the current pattern before calling up the command.  The same approach can also be used for other Hatch options, such as the scale and angle.

Kajito
16.11.2013, 19:05
Thank you guys soo much for your help. Exactly what I needed.