I used to know some Autolisp, but looking for help with a Lisp routine

I used to know some Autolisp, but looking for help with a Lisp routine

HullDrafter
Advocate Advocate
1,210 Views
3 Replies
Message 1 of 4

I used to know some Autolisp, but looking for help with a Lisp routine

HullDrafter
Advocate
Advocate

I can still create Scripts, but a supervisor would like a Lisp routine. 

Also, because some people didn't understand the last time I asked, I don't have control of my autocad, or rather any part of the computer except when I save my scripts in my "C" drive. I absolutely cannot download anything..

 

Now to the main event. I am posting one of my Scripts, it is called generic. If you can get me started on how to convert/ recreate this as an Autolisp routine, I will finish it. This script is designed to change properties in XREFs loaded into our drawings. I have 5 more just like it. Well, maybe not so big on a couple. 

 

Generic.scr: 

cmdecho 0
Layer LW Default *|*
C 253 *|*Topo* L Hidden2 *|*Topo*
C 253 *|*Survey* L Hidden2 *|*Survey*
C 253 *|*Xref*
C 253 *|*tx
C 253 *|*txt*
C 253 *|*text*
C 253 *|*anno
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 *|*no* P N *|*no*
C 253 *|*tics P N *|*tics
C 254 *|*Patt
C 254 *|*Patt*
C 85 *|*L-Patt*
C 254 *|*I-Wall*
C 81 *|*L-Wall*
C 255 *|*Ha
C 255 *|*Htch*
C 255 *|*Hatch*
C 253 *|*Const* P N *|*Const*
C 255 *Arch*|*
C 255 *|*Demo*
C 255 *|*RCP*
C 255 *|*Col*
C 255 *|*A-Plan*
C 255 *|*A-Unit*
C 254 *|*Furn*
C 254 *|*Fixt*
C 254 *|*Ovhd*
C 254 *|*Glaz*
C 254 *|*Detl*
C 254 *|*Roof*
C 254 *|*Wheel*
C 254 *|*Strip*
C 254 *|*Sign*
C 254 *|*Eqpm*
C 254 *|*Hral*
C 254 *|*bike*
C 254 *|*A-Plan-Wall*
C 253 *|*A-Plan-Wall
C 254 *|*-NPLT L Continuous *|*-NPLT P N *|*-NP
C 253 *|Ex* L Hidden2 *|EX*
C 253 *|*-E L Hidden2 *|*-E
C 253 *EX*|* L Hidden2 *EX*|*
cmdecho 1

 

As I said, I am pretty good with Scripts, but I have forgotten what little I knew about Lisp routines.

 

HullDrafter

0 Likes
Accepted solutions (1)
1,211 Views
3 Replies
Replies (3)
Message 2 of 4

cadffm
Consultant
Consultant
Accepted solution

You can translate it 1:1 into one or more (command ..) expressions,

it has nothing to do with programming, but the commands are

started thru lisp then, instead thru *.scr files.

 

If you like to learn programming and not just controle autocad commands like in your script - this is a longer way.

 

I write one more sample like in this other post:

 

cmdecho 0
Layer LW Default *|*
C 253 *|*Topo* L Hidden2 *|*Topo*
C 253 *|*Survey* L Hidden2 *|*Survey*

 

(command "cmdecho" "0")
(command "Layer" "LW Default" "*|*"
"C" "253" "*|*Topo*" "L" "Hidden2" "*|*Topo*"
"C" "253 *|*Survey*" "L"  "Hidden2" "*|*Survey*"

"" ;<-- between " is the commandline input and this line "" sends no input, so it's ONLY an ENTER hit.

)

Sebastian

Message 3 of 4

Sea-Haven
Mentor
Mentor

For me I use a text file and just read it easier than adding to the lisp, I would use a csv file as you have indicated, colour, layername, linetype.  I have something but its column delimited I will rewrite next time as  csv.

 

Lee-mac.com has a parse csv which will read the file creating a list then its as simple as

 

; thanks to www.Lee-mac.com Parse csv for this defun
(defun csv->lst ( str / pos )
(if (setq pos (vl-string-position 44 str)) ; note 44 is ,
    (cons (substr str 1 pos) (csv->lst (substr str (+ pos 2))))
    (list str)
    )
)

(defun mklays ( / lst lays fo )
(setq fo (Open "D:\\Acadtemp\\Alanlay.txt" "R"))
(setq lst '())
(while (setq newl (read-line fo))
(setq lst (cons (csv->lst newl) lst))
)
(close fo)
(repeat (setq x (length lst))
(setq lays (nth (setq x (- x 1)) lst))
(command "-layer" "m" (nth 1 lays) "c" (nth 0 lays) "" "Lt" (nth 2 lays) "" "")
)
(alert "layers have been created")
(princ)
)
(mklays)

 

253,Fenc,Continuous
253,dtch,Continuous
253,swlk,Continuous
253,mons,Continuous
253,majr,Continuous

 

0 Likes
Message 4 of 4

HullDrafter
Advocate
Advocate

Thank you for this. I hate to say it, I can understand this over the other suggestion, but I know they are both LISP. I need to find my AutoLISP books, but currently don't have a clue where they are and I try to get away from the 'puter when I arrive home. Thank you both for your suggestions. Also, I forgot about Lee-Mac, thank you for the reminder

0 Likes