Jump to content

Sequential Layer naming + Lisp noob questions (example included)


Esteban_CAD

Recommended Posts

Hi All

 

Firstly, many thanks to everyone who contributes to this site, it is an immensely helpful source of info.

 

I have been using AutoCAD for many years and have recently started to play around with AutoLISP to try and streamline some repetitive commands, I can generally construct simple routines but have bitten off more than I can chew with this one.

 

I would like to write a LISP that will create layers within an open drawing based on a proposed buildings max story height while factoring in the possibility of a basement floor and/or split ground floor (upper/Lower). The layer names are floor specific and would be as follows:

 

x =floor number (-1 = Basement, 0 =Ground, 1 = First etc)

NLP x Walls

NLP x Windows

NLP x Rooms

NLP x Balcs

NLP x Detailing

(one set of layers per floor)

 

Setq: user inputs

basement (Yes/No)

Splitgrnd (Yes/No)

floorno (numeric value based on total number of floors)

 

Setq: program

floornoabsolute (based on user inputs to return number of top floor)

 

n.b. I appreciate that the routine is probably cumbersome and could be streamlined but please ignore this for now as I am using it as a teaching aid and will learn how to do this in due course, for now I would just like to know a few things that I am struggling with.

 

My LISP so far:

(defun c:NLPADDLAYERSTEST ( / floorno basement splitgrnd floornoabsolute)

(initget 1 "Yes No")

(setq basement (getkword "\nDoes the Scheme have a basement? (Yes/No): ")

)

(cond

((= basement "Yes") (command "layer" "n" "NLP -1 Walls" "n" "NLP -1 Windows" "n" "NLP -1 Rooms" "n" "NLP -1 Balcs" "n" "NLP -1 Detailing" ""))

)

(initget 1 "Yes No")

(setq splitgrnd (getkword "\nIs the ground floor split into upper and lower? (Yes or No): ")

)

(if (= splitgrnd "Yes")

(command "layer" "n" "NLP 0U Walls" "n" "NLP 0U Windows" "n" "NLP 0U Rooms" "n" "NLP 0U Balcs" "n" "NLP 0U Detailing" "n" "NLP 0L Walls" "n" "NLP 0L Windows" "n" "NLP 0L Rooms" "n" "NLP 0L Balcs" "n" "NLP 0L Detailing" "")

(command "layer" "n" "NLP 0 Walls" "n" "NLP 0 Windows" "n" "NLP 0 Rooms" "n" "NLP 0 Balcs" "n" "NLP 0 Detailing" "")

)

(initget 1)

(setq floorno (getreal "\nHow many stories in the proposed scheme? (max if multiple buildings): ")

floornoabsolute (cond

((and (= basement "No") (= splitgrnd "No") ("!floorno"-1)))

((and (= basement "Yes") (= splitgrnd "Yes") ("!floorno"-3)))

((and (= basement "Yes") (= splitgrnd "No") ("!floorno"-2)))

((and (= basement "No") (= splitgrnd "Yes") ("!floorno"-2)))

)

Unwritten part of program

)

)

 

Question 1

 

In the floornoabsolute set of conditions what would be the correct syntax in order to have the program return a value of floorno - number. As you can see I have it as ("!floorno"-2) but beleive that is incorrect.

 

Question 2

 

Would the following be the correct way to set a value for floornoabsolute? (excluding the fact that the part from the previous question is wrong)

(setq floornoabsolute (cond

((and (= basement "No") (= splitgrnd "No") ("!floorno"-1)))

((and (= basement "Yes") (= splitgrnd "Yes") ("!floorno"-3)))

((and (= basement "Yes") (= splitgrnd "No") ("!floorno"-2)))

((and (= basement "No") (= splitgrnd "Yes") ("!floorno"-2)))

)

 

Question 3

As I am still learning my initial approach to the rest of the code was going to be; set up a text file/s with the layer names in and have the program follow it until x(floor number) = floornoabsolute. The reason for this is I don't know enough yet to decipher any posts pertaining to Sequential numbering LISPs.

 

Is there a relatively simple way to tell the program to create a set of layers, lets say NLP x walls, where x starts at 1 and progresses sequentially until x= floornoabsolute?

 

Thanks in advance for any help.

 

Regards

 

Steve

Link to comment
Share on other sites

Look into repeat

 

(setq num (getint "Number of floors"))
(setq x (+ num 1))
(repeat  num
(setq fl (rtos (setq x (- x 1))2 0))
(command "-layer" "m" (strcat "NPL" fl "Walls") "m" (strcat "NPL" fl "Windows") "")
)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...