LISP routine for setting the Linetype for a layer

LISP routine for setting the Linetype for a layer

CharlesF5B37
Advocate Advocate
821 Views
7 Replies
Message 1 of 8

LISP routine for setting the Linetype for a layer

CharlesF5B37
Advocate
Advocate

Hi all, 

 

I am hoping to create a LISP routine just to update the Linetype for a layer. Here is a Loom video of what I am trying to do . 

 

Not sure if its more complicated since the layer is on an XREF. 

 

I am using AutoCAD LT 2024, and I am just dipping my toes into using LISP routines. 

 

Thanks for any  help!

 

 

0 Likes
Accepted solutions (2)
822 Views
7 Replies
Replies (7)
Message 2 of 8

paullimapa
Mentor
Mentor
Accepted solution

here's a good on-line site to learn AutoLISP:

Learn AutoLISP for AutoCAD productivity | AfraLISP

The code to load the border2 linetype:

(if(not(tblsearch"LTYPE""BORDER2")) ; check if linetype is already loaded
 (if(zerop(getvar"measurement")) ; check what linetype file to load from
  (command-s"_.Linetype""_Load""Border2""acadlt.lin""")
  (command-s"_.Linetype""_Load""Border2""acadltiso.lin""")
 )
)

 The code to change the xref Layer to that linetype:

(command-s"_.Layer""_LT""Border2""Roof Layout|Plot Outline""""")

 


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

Kent1Cooper
Consultant
Consultant
Accepted solution

@paullimapa wrote:

....

 The code to change the xref Layer to that linetype:

(command-s"_.Layer""_LT""Border2""Roof Layout|Plot Outline""""")

If it's a linetype defined in acad.lin/acadiso.lin like that one, and if you assign it using a (command) or (command-s) or (vl-cmdf) function like that [not, for example, with (entmake) or (entmod) of the Layer object's entity data], the above or equivalent with the other functions is all you need.  You don't need to check whether it's in the drawing already, nor load it first -- the command will find it anyway.  [But there's one more Enter "" than needed at the end.]

 

Personally, I find it easier to read with some spaces, so adjacent double-quotes that look like Enter above, but are not, are clearer:

(command-s "_.Layer" "_LT" "Border2" "Roof Layout|Plot Outline" "")

 

Kent Cooper, AIA
0 Likes
Message 4 of 8

paullimapa
Mentor
Mentor

Thanks for pointing that out...nice how AutoCAD automatically loads the linetype when using the Layer command.

Unfortunately, if the linetype doesn't existing in the acadlt.lin or acadltiso.lin the command line shows the "Invalid option keyword" though the command still executes.


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

Kent1Cooper
Consultant
Consultant

@paullimapa wrote:

.... if the linetype doesn't existing in the acadlt.lin or acadltiso.lin the command line shows the "Invalid option keyword" though the command still executes.


There's a message about not having that linetype available, but it goes back to the main Layer prompt.  That's when the code feeds in the Layer name that was intended to have that linetype assigned to it, but of course that's not an acceptable input at that point, when it's expecting selection of an option.  So it gives that message, and goes back to the main Layer prompt again.  The final Enter "" then ends the command.  So it "executes" in the sense of getting to the end of the command without crashing, but of course it doesn't assign that linetype to that Layer.  It's all because the Layer command is capable of merely reporting invalid input, but continuing anyway, instead of quitting as many commands do when given invalid input.

Kent Cooper, AIA
Message 6 of 8

CharlesF5B37
Advocate
Advocate

Awesome, thank you.

 

Works wonderfully!

 

Next is can I update the LTSCALE in an XREF (Roof Layouts.dwg) to 1?

0 Likes
Message 7 of 8

paullimapa
Mentor
Mentor

You’ll have to open the xref and change that there


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

CharlesF5B37
Advocate
Advocate

Sounds good, thank you!

0 Likes