I used to know the basics of AutoLISP , but have forgotten and need assistance

I used to know the basics of AutoLISP , but have forgotten and need assistance

HullDrafter
Advocate Advocate
953 Views
5 Replies
Message 1 of 6

I used to know the basics of AutoLISP , but have forgotten and need assistance

HullDrafter
Advocate
Advocate

I am in need of several LISP routines and would prefer to l;earn again so if you can point me in the direction of websites to learn from, I would appreciate it. 

As to why I need this information, I am pretty good with scripts. I would like to convert these over to LISP routines, but...

We work in various scales in model space (Don't ask);

 

Script #1:

cannoscale 1:20
dimasz 2.8
dimtxt 2
dimse1 on
dimse2 on
dimtdec 1
dimgap 1
textstyle Romans
textsize 2

 

The second one deals with xrefs and settings would want them to have (This is the generic script):

cmdecho 0
Layer LW Default *|*
C 253 *|*Topo* L Hidden2 *|*Topo*
C 253 *|*Xref*
C 253 *|*Fenc* L Continuous *|*Fenc*
C 253 *|*dtch* L Continuous *|*dtch*
C 253 *|*swlk* L Continuous *|*swlk*
C 253 *|*mons* L Continuous *|*mons*
C 253 *|*majr* L Continuous *|*majr*
C 253 *|*minr* L Continuous *|*minr*
C 254 *|*scale L Continuous *|*scale
C 253 *|*Traffic* L Continuous *|*Traffic*
C 2 *|Exel* L Continuous *|Exel*
C 2 *|Exel* L Continuous *|Exel*
C 21 *|*prop* L Continuous *|*prop*
C 15 *|*esmt* L Hidden *|*esmt*
C 15 *|*ease* L Hidden *|*ease*
C 8 *|*Bldg* L Continuous *|*BLDG*
C 8 *|*pvmt* L Continuous *|*pvmt*
C 81 *|*Envr* L Continuous *|*Envr*
C 81 *|*Lscp* L Continuous *|*Lscp*
C 81 *|*plant* L Continuous *|*plant*
C 81 *|*tree* L Continuous *|*tree*
C 83 *|*Feat* L Continuous *|*Feat*
C 3 *|*BNDY* L Phantom2 *|*BNDY*
C 193 *|*Gutter* L Continuous *|*Gutter*
C 193 *|*Wall* L Continuous *|*Wall*
C 253 *|Fo* L Continuous *|Fo*
C 13 *|*Road*
C 1 *|*Road*Face
C 8 *|*Road*Back
C 8 *|*Bw* L Continuous *|*Bw*
C 1 *|*Fc* L Continuous *|*Fc*
C 1 *|*Tc* L Continuous *|*Tc*
C 8 *|*Bc* L Continuous *|*Bc*
C 2 *|*Util* L Continuous *|*Util*
C 253 *|WD* L XW *|WD*
C 140 *|Prwd* L W *|Prwd*
C 140 *|*Wat* L W *|*Wat*
C 140 *|*Wtr* L W *|*Wtr*
C 140 *|*Irr* L IRR *|*Irr*
C 140 *|*Rw* L W *|*Rw*
C 140 *|*Dw* L W *|*Dw*
C 253 *|*grad* L Continuous *|*grad*
C 21 *|Prgs* L XGAS *|Prgs*
C 1 *|*Stlt* L Continuous *|*Stlt* P N *|*Stlt*
C 1 *|*Light L Continuous *|*Light P N *|*Light
C 30 *|*SS* L SS *|*SS*
C 43 *|*SD* L SD *|*SD*
C 43 *|*strm* L SD *|*strm*
C 253 *|*Strc* L Continuous *|*Strc*
C 253 *|*Prkg* L Continuous *|*Prkg*
C 50 *|*cntr*
C 50 *|*center*
C 253 *|*tx
C 253 *|*txt*
C 253 *|*text*
C 253 *|*no* P N *|*no*
C 253 *|*tics P N *|*tics
C 253 *|*anno
C 254 *|*Patt
C 254 *|*Patt*
C 85 *|*L-Patt*
C 81 *|*L-Wall*
C 254 *|*Ha
C 254 *|*Htch*
C 254 *|*Hatch*
C 253 *|*Const* P N *|*Const*
C 253 *|Ex* L Hidden2 *|EX*
C 253 *|*-E L Hidden2 *|*-E
C 253 *EX*|* L Hidden2 *EX*|*
C 254 *|*Demo*
C 254 *|*A-Plan*
C 8 *|*A-Plan-Wall
C 254 *|*-NPLT L Continuous *|*-NPLT P N *|*-NPLT

cmdecho 1

 

Thank you for your time.

 

0 Likes
Accepted solutions (3)
954 Views
5 Replies
Replies (5)
Message 2 of 6

cadffm
Consultant
Consultant
Accepted solution

The  first thing is not much more than your script files, you can send the same commands via command lisp function.

 

CECOLOR

3

 

(Command "CECOLOR" "3")

 

Not really programming, but send by lisp to the commandline.

 

For learning lispfunctions

Afralisp homepage and others

and every time your help F1 too

Sebastian

Message 3 of 6

doaiena
Collaborator
Collaborator
Accepted solution

Setting variables can be easily done with the "setvar" function:

(setvar "dimtxt" 2)

You can check the current value of a variable with the "getvar" function:

(getvar "dimtxt")
2

As for the layer commands - just type "-layer" in the command line and follow the prompts. For instance, this will create a new layer named "test":
(command "_.-layer" "_n" "test" "")

The empty double quotes "" inside a command function stand for an ENTER. If you follow the prompts and observe what you are pressing to get the required results, you will quickly get the hang of it, and easily automate the "-layer" command.

Some resources on AutoLisp: resources 

0 Likes
Message 4 of 6

Sea-Haven
Mentor
Mentor
Accepted solution

Your layers could be created from a file using a defun that makes layers, you just need a seperator like a , or space.

 

layername col lt th

layername col lt th

layername col lt th

layername col lt th

 

This would save adding all the layers names to a lisp. I would make the "layer make: a library routine so it could be used in any program you use, I have 40 lisps but only 1 layercheck defun. (laychk lay col lt) just loads the library routine at start up or demand load.

 

(if (not laychk)(Load "layercheck"))

 

 

0 Likes
Message 5 of 6

HullDrafter
Advocate
Advocate

I have accepted all three as solutions, as they all have giving insight into directions I hadn't thought to take with AutoLISP, I completely forgot about AfraLISP and I never loaded a Library of routines, I always loaded all of the routines. I tell my co-workers AutoCAD can do more, I should listen to my own words. Thank you for the information, I have several new avenues to follow up. 

As a side note, I knew about F1. 

0 Likes
Message 6 of 6

Kent1Cooper
Consultant
Consultant

On your Layer settings, you can shorten that whole thing quite a lot by taking advantage of the fact that the same Layer option can be applied to any number of comma-separated Layer names [or wildcard Layer name groups] collectively:

cmdecho 0
Layer
LW Default *|*
C 253 *|*Topo*,*|*Xref*,*|*Fenc*,*|*dtch*,*|*swlk*,*|*mons*,*|*majr*,*|*minr*,*|*Traffic*,*|*Strc*,*|*Prkg*,*|*tx,*|*txt*,*|*text*,*|*no*,*|*tics,*|*anno,*|*Const*,*|Ex*,*|*-E,*EX*|*,*|Fo*,*|WD*,*|*grad*
C 254 *|*scale,*|*Ha,*|*Patt,*|*Patt*,*|*Htch*,*|*Hatch*,*|*Demo*,*|*A-Plan*,*|*-NPLT
C 2 *|Exel*,*|*Util*
C 21 *|*prop*,*|Prgs*
C 15 *|*esmt*,*|*ease*
C 8 *|*Bldg*,*|*pvmt*,*|*Road*Back,*|*Bw*,*|*Bc*,*|*A-Plan-Wall
C 81 *|*Envr*,*|*Lscp*,*|*plant*,*|*tree*,*|*L-Wall*
C 83 *|*Feat*
C 3 *|*BNDY*
C 193 *|*Gutter*,*|*Wall*
C 13 *|*Road*
C 1 *|*Road*Face,*|*Fc*,*|*Tc*,*|*Stlt*,*|*Light
C 140 *|Prwd*,*|*Wat*,*|*Wtr*,*|*Irr*,*|*Rw*,*|*Dw*
C 30 *|*SS*
C 43 *|*SD*,*|*strm*
C 50 *|*cntr*,*|*center*
C 85 *|*L-Patt*
L Hidden2 *|*Topo*,*|EX*, *|*-E,*EX*|*
L Continuous *|*Fenc*,*|*dtch*,*|*swlk*,*|*mons*,*|*majr*,*|*minr*,*|*scale,*|*Traffic*,*|Exel*,*|Exel*,*|*prop*,*|*BLDG*,*|*pvmt*,*|*Envr*,*|*Lscp*,*|*plant*,*|*tree*,*|*Feat*,*|*Gutter*,*|*Wall*,*|Fo*,*|*Bw*,*|*Fc*,*|*Tc*,*|*Util*,*|*grad*,*|*Stlt*,*|*Light,*|*Strc*,*|*Prkg*,*|*-NPLT
L Hidden *|*esmt*,*|*ease*
L Phantom2 *|*BNDY*
L XW *|WD*
L W *|Prwd*,*|*Wat*,*|*Wtr*,*|*Rw*,*|*Dw*
L IRR *|*Irr*
L XGAS *|Prgs*
L SS *|*SS*
L SD *|*SD*,*|*strm*
P N *|*Stlt*,*|*Light,*|*no*,*|*tics,*|*Const*,*|*-NPLT
cmdecho 1

So you need only one  Linetype option for each linetype involved, only one  Color option for each color involved, and only one  Plot-Not option, rather than calling for those options in different combinations separately over and over again for every Layer name [or wildcard Layer name group].  That reduces occurrences of the word "Continuous" from 32  to only 1, and of the number 253 from 24  to only 1, etc.

 

[I hope, but don't guarantee, that I did all the cutting/pasting without losing anything in the transfer....]

Kent Cooper, AIA
0 Likes