Creating layout tabs from template with LISP

Creating layout tabs from template with LISP

thomas.schive
Enthusiast Enthusiast
3,490 Views
4 Replies
Message 1 of 5

Creating layout tabs from template with LISP

thomas.schive
Enthusiast
Enthusiast

Hello! 

 

My flow chart is basically like this - ask the user for which kind of drawing he/she wants and then which sheet size. Accordingly, this kind of drawing setup and sheetsize shall be created by using layers > template and grabbing it from an existing file that has the desired layouts put. 

One issue I have is that when I am proposing a (setq) to be a path to the existing dwg file, the program somehow cuts out my "/" and/or where there are spaces. Any way around this problem?

 

The code is pretty much like this (+ a "main program" to run the functions accordingly):

 

(defun inserttab ( / )
(setq filnavn "C:\Users\myuser\Desktop\import.dwg") ;;dwg path?
(cond

((and (= tegning "B")(= arkstr "A1"))
(progn (setq lnavn "BA1")
(arkimport)))
((and (= tegning "B")(= arkstr "A3"))
(progn (setq lnavn "BA3")
(arkimport)))
)
)

 

(defun arkimport ( / )
(command "layout" "t" filnavn lnavn)
(command "layout" "set" lnavn)
(command "zoom" "extents")
(print (strcat filnavn " " lnavn))
)

 

(defun typetegning ( / )
(setq tegning
(progn (initget "B C1 C2 F U")
(getkword "Which kind of drawing? [B/C1/C2/F/U]:"))
)
(print tegning)
);_ defun

(defun sheetsize ( / )
(setq arkstr
(progn (initget "A1 A3")
(getkword "Which sheet size? [A1/A3]:"))
)
(print arkstr)
);_ defun

 

I believe the problem is relating to the (setq filnavn)-path, because when i ask the program (! filnavn) it cuts out some parts of the link. 

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

SeeMSixty7
Advisor
Advisor
Accepted solution

The backslash is an escape char in AutoLISP so you will need to use the escape char followed by the char you want so your setq would look like this

 

(setq filnavn "C:\\Users\\myuser\\Desktop\\import.dwg") ;;dwg path?

 

or flip it an use the forward slash.

 

(setq filnavn "C:/Users/myuser/Desktop/import.dwg") ;;dwg path?

Message 3 of 5

cadffm
Consultant
Consultant

Backslash is the initial character for string control codes,

if you like to have a backslash in a string, you have to quote the backslash, similar to " in Strings.

 

(alert "1/n2")

(alert "1//2)

(alert "a\tb\tc")

(alert "so \"cute\"")

 

For file pathes you can use the SLASH instead the double-Backslashs

D:\\

D:/

both will work

Sebastian

0 Likes
Message 4 of 5

Sea-Haven
Mentor
Mentor

Lisp has a nasty in that in certain situation a space in a directory name will cause a failure of the file path particularly if using a forward slash, VBA does not have the same problem.

 

and/or where there are spaces

0 Likes
Message 5 of 5

Sea-Haven
Mentor
Mentor

Would it not be easier to make separate dwgs for A-A1 A-A3 etc and use Insert into layout, are the sheets actually different ? Our A1 was just plotted at 1:2 for A3 so only had 1 title block. 

 

Our survey team has a round 12 title blocks for land legal details but a project may only use around 3-4 depending on project. So just pick from a dcl list 1 required.

0 Likes