Making default value

Making default value

Muhammed.OPERA
Advisor Advisor
3,135 Views
14 Replies
Message 1 of 15

Making default value

Muhammed.OPERA
Advisor
Advisor

Hi everyone,

I'm writing a LISP which contains a variable Landing. I made a list of options to choose using  Initget function.

Then i used Getkword function with those values. Like that:

 

(initget 1 "0.26 0.27 0.28 0.29 0.30")
(setq Landing "0.26")
(setq Landing (getkword (strcat "\nEnter the landing distance (m): [0.26/0.27/0.28/0.29/0.30] <" Landing "> :")))

 

The trouble is when i hit enter button without choosing any value, here it should take the default value as it's defined 0.26 but it never happened.

it works only when i go up and down in the list of options and choose it.

 

Can you help me how can i make a value as default activated when i press enter without going up and down?

I tried to use cond and if like that :

(if (not Landing) (setq Landing "0.26")

(initget 1 "0.26 0.27 0.28 0.29 0.30")

(setq Landing

(cond

(

(getkword (strcat "\nEnter the landing distance (m): [0.26/0.27/0.28/0.29/0.30] <" Landing "> :"))

(Landing)

)

)

But it goes wrong.

 

Thanks for all 🙂

 


Muhammed Mamdouh (OPERA)
Structural Engineer, Instructor
Facebook |LinkedIn

EESignature

0 Likes
3,136 Views
14 Replies
Replies (14)
Message 2 of 15

Kent1Cooper
Consultant
Consultant

Try it this way, which doesn't need you to pre-set the Landing value, so that whatever other-than-0.26 value you have used previously will remain as the default:

 

(initget "0.26 0.27 0.28 0.29 0.30")

  ;; without the 1 -- allow Enter

(setq Landing

  (cond

    (getkword ; use value it gets if User types it in

      (strcat

        "\nEnter the landing distance (m): [0.26/0.27/0.28/0.29/0.30] <"

        (cond (Landing) ("0.26")); offer current value as default if present, otherwise 0.26

        "> :"

      ); strcat

    ); getkword

    (Landing); if User hits Enter at (getkword) [nil return], use prior value if present

    ("0.26"); use this value if User hits Enter with no prior value

  ); cond

); setq

Kent Cooper, AIA
Message 3 of 15

Ranjit_Singh
Advisor
Advisor

If you want to allow hitting enter then avoid setting bit 0 (value 1) in initget. That will prevent a {ENTER} response.

(setq landing "0.26"
       resp    (progn (initget "0.26 0.27 0.28 0.29 0.30")
                      (getkword (strcat "[0.26/0.27/0.28/0.29/0.30] <" landing ">: "))))
 (if (null resp)
  landing
  (setq landing resp))
Message 4 of 15

Muhammed.OPERA
Advisor
Advisor

Thanks @Ranjit_Singh @Kent1Cooper for your time and attention

I have tried the two cases but it didn't work Smiley Sad

Here is the full lisp till now (i'm working on it):

(defun C:OPERAStair()
;Making zero variables.
(setq Landing 0.00 Riser 0.00 Thickness 0.00 L1 0.00 L2 0.00 NoSteps 0 Point1 '(0 0)
Point2 '(0 0) Point3 '(0 0))
;Making layer
(command "layer" "new" "OPERA_Stair" "color" "red" "OPERA_Stair" "Ltype" "continuous" "OPERA_Stair" "LWeight" "0.35" "OPERA_Stair" "Make" "OPERA_Stair" "")
;Setting object properties into default ones.
(command "Color" "Bylayer" "")
(command "Linetype" "Set" "Bylayer" "")
(command "LWeight" "0.35")
;Asking for inputs.
(setq NoSteps (getint "\nEnter number of steps: "))
;Setting Landing distance.
(initget "0.26 0.27 0.28 0.29 0.30")
(setq Landing (getkword "\nEnter the landing distance (m): [0.26/0.27/0.28/0.29/0.30] <0.30> :"))
(if
(= Landing "0.26")
(setq Landing 0.26))
(if
(= Landing "0.27")
(setq Landing 0.27))
(if
(= Landing "0.28")
(setq Landing 0.28))
(if
(= Landing "0.29")
(setq Landing 0.29))
(if
(= Landing "0.30")
(setq Landing 0.30))
;Setting Riser distance.
(initget "0.14 0.15 0.16 0.17 0.18")
(setq Riser (getkword "\nEnter the riser distance (m): [0.14/0.15/0.16/0.17/0.18] <0.15> :"))
(setq RiserList (List 0.14 0.15 0.16 0.17 0.18))
(if
(= Riser "0.14")
(setq Riser (nth 1 RiserList)))
(if
(= Riser "0.15")
(setq Riser (nth 2 RiserList)))
(if
(= Riser "0.16")
(setq Riser (nth 3 RiserList)))
(if
(= Riser "0.17")
(setq Riser (nth 4 RiserList)))
(if
(= Riser "0.18")
(setq Riser (nth 5 RiserList)))
;Drawing starts here.
(Setq Point1 (getpoint "\nSpecify lower left corner of the section: "))
;Zooming area.
(setq Ptz1 Point1
Ptz2 (polar Ptz1 0 (* NoSteps Landing))
Ptz3 (polar Ptz2 (/ pi 2) (* NoSteps Riser))
Ptz4 (polar Ptz1 (* pi 1.25) 1)
Ptz5 (polar Ptz3 (* 0.25 pi) 1))
(command "Zoom" Ptz4 Ptz5)
;Repeat.
(repeat NoSteps
(setq Point2 (Polar Point1 (/ pi 2) Riser)
Point3 (polar Point2 0 Landing))
(command "PLine" Point1 Point2 Point3 "")
(setq Object1 (ssget "C" Point3 Point1))
(setq Object2 (entlast))
(command "Join" Object1 Object2 "")
;;(setq Object1 (ssget "w" Point1 Point3 '(List (cons 0 "PLINE") (cons 8 OPERA_Stair))))
;;(command "Join" (list Object1 Object1))
(setq Point1 Point3)
)
)

 

 


Muhammed Mamdouh (OPERA)
Structural Engineer, Instructor
Facebook |LinkedIn

EESignature

0 Likes
Message 5 of 15

_Tharwat
Advisor
Advisor

Hi,

 

Keep the variable Landing un-localized to be able to reset the value in the cond function statement.

 

(or Landing (setq Landing "0.26"))
(initget "0.26 0.27 0.28 0.29 0.30")
(setq Landing (cond ((getkword (strcat "\nEnter the landing distance (m): [0.26/0.27/0.28/0.29/0.30] <" Landing "> :")))
                    (Landing))
  )
Message 6 of 15

Kent1Cooper
Consultant
Consultant

A couple of things....

 

Don't do all those separate (if) tests for the Landing value, replacing text values from (getkword) with equivalent real-number values.  You can just do this, to cover any choice, without any  (if) function, much less a separate one for every potential value:

 

(setq Landing (atof Landing))

 

You can do the same with the Riser value, but if you have some reason to stick with your (nth)-based approach [why you're doing it differently from the Landing value, I can't imagine], you need to fix something:


(if
(= Riser "0.14")
(setq Riser (nth 1 RiserList)))

 

should be

 

(if
(= Riser "0.14")
(setq Riser (nth 0 RiserList)))

 

because 0 is the index number for the first item in a list, which in your list is the 0.14 value.

 

The current state of things doesn't seem to incorporate either of the other suggestions about the (getkword)/(cond) approaches.  Can you be more detailed about what you mean by "it didn't work"?

Kent Cooper, AIA
Message 7 of 15

john.uhden
Mentor
Mentor

Or even save it to the bulletin board for other drawngs in the same AutoCAD session.

Of course the symbol name could probably be more unique.

John F. Uhden

Message 8 of 15

Ranjit_Singh
Advisor
Advisor

@Muhammed.OPERA wrote:

Thanks @Ranjit_Singh @Kent1Cooper for your time and attention

I have tried the two cases but it didn't work Smiley Sad

Here is the full lisp till now (i'm working on it):

........ 


I would recommend using environment variables. See below code. No error trap and minimal testing.

(defun c:operastair  (/ dat landing nosteps object1 object2 point1 point2 point3 ptz1 ptz2 ptz3 ptz4 ptz5 resp riser thickness)
 (if (setq dat (getenv "landing"))
  (setq landing (atof dat))
  (progn (setenv "landing" "0.26") (setq landing 0.26)))
 (if (setq dat (getenv "riser"))
  (setq riser (atof dat))
  (progn (setenv "riser" "0.14") (setq riser 0.14)))
 (setq thickness 0.00
       nosteps 0
       point1 '(0 0)
       point2 '(0 0)
       point3 '(0 0))
 (command "layer" "new" "OPERA_Stair" "color" "red" "OPERA_Stair" "Ltype" "continuous" "OPERA_Stair" "LWeight" "0.35" "OPERA_Stair" "Make" "OPERA_Stair" "")
 (command "Color" "Bylayer" "")
 (command "Linetype" "Set" "Bylayer" "")
 (command "LWeight" "0.35")
 (setq nosteps (getint "\nEnter number of steps: "))
 (initget "0.26 0.27 0.28 0.29 0.30")
 (cond ((setq resp (getkword
                    (strcat "\nEnter the landing distance (m): [0.26/0.27/0.28/0.29/0.30] <" (getenv "landing") "> :")))
        (setenv "landing" resp)
        (setq landing (atof resp))))
 (initget "0.14 0.15 0.16 0.17 0.18")
 (cond ((setq resp (getkword
                    (strcat "\nEnter the riser distance (m): [0.14/0.15/0.16/0.17/0.18] <" (getenv "riser") "> :")))
        (setenv "riser" resp)
        (setq riser (atof resp))))
 (setq point1 (getpoint "\nSpecify lower left corner of the section: "))
 (setq ptz1 point1
       ptz2 (polar ptz1 0 (* nosteps landing))
       ptz3 (polar ptz2 (/ pi 2) (* nosteps riser))
       ptz4 (polar ptz1 (* pi 1.25) 1)
       ptz5 (polar ptz3 (* 0.25 pi) 1))
 (command "Zoom" ptz4 ptz5)
 (repeat nosteps
  (setq point2 (polar point1 (/ pi 2) riser)
        point3 (polar point2 0 landing))
  (command "PLine" point1 point2 point3 "")
  (setq object1 (ssget "C" point3 point1))
  (setq object2 (entlast))
  (command "Join" object1 object2 "")
  (setq point1 point3))
 (princ))

stairs_enviro_var.gif

 

Message 9 of 15

Kent1Cooper
Consultant
Consultant

Just to throw in another consideration:

 

In my experience, the riser height of steps is not  something we dictate in advance, but is determined as a result  of the floor-to-floor height, which is determined by things like block coursing, bearing plate depths, framing depths, sheathing and flooring thicknesses, etc.  We don't usually specify either the number of steps nor what the riser height is to be, but divide the structurally-determined floor-to-floor height by the smallest number of steps that will cover that distance at or below the maximum riser height allowed in the Code.

 

For a routine that draws Stair Sections that way, see Stairs.lsp, >here<.  Their web sub-page is mis-named -- it does sections as well as plans.  It asks for the floor-to-floor height, the maximum allowable riser height, and some other stuff, and it calculates the actual riser height needed to achieve that transition in the fewest number of code-compliant risers, and the number of those needed.  [It's in imperial units and uses defaults from the most common Building Code in the US, so you'll have to change defaults, as well as things like Layer names and colors, but the concept should translate easily enough.]  And it figures out some other things for you, such as a 2-run stair if needed [with some choices], a railing line, the difference between wood and steel-pan step profiles, etc.

Kent Cooper, AIA
Message 10 of 15

ВeekeeCZ
Consultant
Consultant

My contribution. I would like to keep the setting open for typing eg. ".28" or picking on the screen... or just a different value...

 

BTW in my country we're using this formula:  2*riser + landing = 630 mm 

 

 

(defun c:OperaStairs ( / NoSteps)

  (initget (+ 1 2 3))
  (setq NoSteps (getint "\nNumber of steps: "))

  (or *Landing*
      (setq *Landing* "0.30"))
  (initget "0.26 0.27 0.28 0.29 0.30")
  (setq *Landing* (vl-princ-to-string (cond ((getdist (strcat "\nLanding distance (m): [0.26/0.27/0.28/0.29/0.30] <" *Landing* ">: ")))
					    (*Landing*))))

  (or *Riser*
      (setq *Riser* "0.15"))
  (initget "0.14 0.15 0.16 0.17 0.18")
  (setq *Riser* (vl-princ-to-string (cond ((getdist (strcat "\nRiser distance (m): [0.14/0.15/0.16/0.17/0.18] <" *Riser* ">: ")))
					  (*Riser*))))

  (or (tblsearch "LAYER" "OPERA_Stair")
      (command "_.LAYER" "new" "OPERA_Stair" "color" "red" "OPERA_Stair" "LWeight" "0.35" "OPERA_Stair" ""))

  (if (setq pnt (getpoint "\nSpecify lower left corner of the section: "))
    (progn
      (vl-cmdf "_PLINE" "_none" pnt)
      (repeat NoSteps
	(vl-cmdf "_none" (strcat "@" *Landing* ",0")
		 "_none" (strcat "@0," *Riser*)))
      (vl-cmdf ""
	       "CHPROP" "_Last" "" "_Layer" "OPERA_Stair" "")))
  (princ)
)
Message 11 of 15

Muhammed.OPERA
Advisor
Advisor

Thanks verrrrrrrrry much for you all 🙂

@ВeekeeCZ @Kent1Cooper @Ranjit_Singh @john.uhden @_Tharwat

I really appreciate your very helpful comments and your concern 


Muhammed Mamdouh (OPERA)
Structural Engineer, Instructor
Facebook |LinkedIn

EESignature

0 Likes
Message 12 of 15

Muhammed.OPERA
Advisor
Advisor

I made it using :

(if
  (= riser nil)
  (setq riser "0.15")
)

It's greatly working with you help guys.

Thanks a lot. 


Muhammed Mamdouh (OPERA)
Structural Engineer, Instructor
Facebook |LinkedIn

EESignature

Message 13 of 15

ВeekeeCZ
Consultant
Consultant

One way or another... or another... or another... all with same result.

 

(if (= riser nil)
  (setq riser "0.15"))

(if (not riser)
  (setq riser "0.15"))

(if (null riser)
  (setq riser "0.15"))

(or riser
    (setq riser "0.15"))

 

 

0 Likes
Message 14 of 15

Kent1Cooper
Consultant
Consultant

@ВeekeeCZ wrote:

One way or another... or another... or another... all with same result. 


Another:

 

(setq riser (cond (riser) ("0.15")))

Kent Cooper, AIA
0 Likes
Message 15 of 15

john.uhden
Mentor
Mentor

"gonna getcha getcha getcha getcha..."

 

I have a strong suspicion that you are blonde.

 

Of course, being inferior, I like the OR version the best.

Though technically it should be (or (and (= (type riser) 'STR)(distof riser)) ...)

John F. Uhden

0 Likes