Staircase section

Staircase section

Philip-John
Advocate Advocate
495 Views
6 Replies
Message 1 of 7

Staircase section

Philip-John
Advocate
Advocate

I got a lisp routine to draw staircase section with given details like thread width, riser height, number of steps and starting point. But sometimes it works and sometimes it draws straight lines. Please help.

 

(defun c:STAIRSEC ()
(prompt "\nDraw Stair Section Routine: Please follow the prompts...")

;; Ask for tread width
(setq tread-width (getreal "\nEnter tread width: "))

;; Ask for riser height
(setq riser-height (getreal "\nEnter riser height: "))

;; Ask for number of steps
(setq num-steps (getint "\nEnter number of steps: "))

;; Ask for starting point
(setq start-point (getpoint "\nEnter starting point: "))

;; Set initial x, y coordinates
(setq x (car start-point)
y (cadr start-point))

;; Loop through each step and draw
(repeat num-steps
;; Calculate points for the tread and riser
(setq tread-end (list (+ x tread-width) y))
(setq riser-top (list (+ x tread-width) (+ y riser-height)))

;; Draw tread
(command "LINE" (list x y) tread-end "")

;; Draw riser
(command "LINE" tread-end riser-top "")

;; Update x and y for the next step
(setq x (+ x tread-width))
(setq y (+ y riser-height))
)

;; Notify completion
(prompt "\nStair section completed!")
(princ)
)

0 Likes
496 Views
6 Replies
Replies (6)
Message 2 of 7

ВeekeeCZ
Consultant
Consultant

If something is "sometimes" more or less unpredictable, it indicates running OSNAPS. Try this setting... and see...

 

eekeeCZ_0-1738142790819.png

 

Message 3 of 7

cadffm
Consultant
Consultant

Hi,

 

it' the (setvar 'Osnapcoord 1) setting. [F1]

 

>(command "LINE" tread-end riser-top "")

If running osnaps ON, the line command will use them, if osnapcoords are set to 2 (or 0, a funny nightmare for users)

 

Would works with every setting, osnap NONE: (command "LINE" "non" tread-end "non" riser-top "")

Sebastian

Message 4 of 7

Kent1Cooper
Consultant
Consultant

A common practice is to save the current Object Snap mode(s) setting, turn it off, do the work of the routine, and then set it back.

(setq osm (getvar 'osmode))
(setvar 'osmode 0)
....  do your thing  ....
(setvar 'osmode osm)

You can also include *error* handling to ensure that it gets reset if there is an error in the "do your thing" part.  You will find many examples of that in this Forum -- search for:

(defun *error*

Both osm [or whatever variable name you prefer] and *error* should go in the localized variables list.

Kent Cooper, AIA
Message 5 of 7

Philip-John
Advocate
Advocate

All solutions are working..

Thank you all for your immediate response..

0 Likes
Message 6 of 7

Kent1Cooper
Consultant
Consultant

If you're interested in a far more sophisticated routine for this, check out STAIRS.lsp >here<.  [A lot of routines on that site have not been downloadable recently, but this one still is.]  See my comment there -- it's not just about plans as in their topic heading.  The STAIRSEC command defined in it will do what you're after.

Since floor-to-floor heights are usually a result of combined structural components [masonry coursing, joist depths, floor sheathing and finish thicknesses, etc.], it doesn't ask for a riser height, but instead for the floor-to-floor and the maximum riser height [offering typical code values as default for that and some other things], and it calculates the needed riser height for the minimum number of steps to traverse that floor-to-floor distance.  And it draws a top-of-handrail line, will do angled risers, wood-stair profile, lets you do one- or two-run, etc.  See the details in the file.

Kent Cooper, AIA
0 Likes
Message 7 of 7

scot-65
Advisor
Advisor

@Philip-John 

 

Upsetting a user's "Magic Number" is frustrating to the user.

 

The preferred method is to suppress the OSMODE by adding 16384 to the value and subtracting when finished. If something goes wrong, the user can simply click on the OSNAP icon in the tray area or press [F3].

 

scot65_0-1738276721653.png

 

;set:
 (if (< (getvar "OSMODE") 16384) (setvar "OSMODE" (+ (getvar "OSMODE") 16384)))

;reset and inside *error*:
 (if (> (getvar "OSMODE") 16384) (setvar "OSMODE" (- (getvar "OSMODE") 16384)))

 

As a standard practice to minimize the upsetting, allow the user to make selections with OSMODE to their liking. Once the user makes the selection the execution begins. In the execution part of the program is where to turn on and off OSMODE.

 

The program structure as you show above does not test if all user input is valid. Errors WILL occur.

 

Try nesting the execution part inside an IF statement:

 

(if (and tread-width riser-height num-steps start-point)

 (progn

  ;...

  ;add 16384

  ;command

  ;command

  ;subtract 16384

  ;...

 );progn

 (alert "Program canceled due to error between keyboard and chair. ")

);if

 


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes