Jump to content

Recommended Posts

Posted

Hi All,

I was trying to write a function to draw the basic outline of staircase.

One or two times it worked perfectly for me. But after that it just draws some crap. Could anyone look into the code below and suggest something?

 

 

(defun c:Stp()

(setq Point (getpoint "\nPick a Point:"))
(setq Rise (getdist "\nEnter rise of each step:"))
(setq Tread (getdist "\nEnter tread of each step:"))
(setq Nos (getint "\nEnter number of steps:"))
(setq LandingAt (Getint "Number of steps in first flight:"))
(setq P1 (list (car Point) (cadr Point)))
(setq LandingLength (getdist "\nEnter Length of Landing:"))
(setq n 0)

(While (< n Nos) 
(if
 (<= n LandingAt)

 (Progn ;If True
   (Setq
     P2 (polar Point (GetRad 90) Rise)
     P3 (Polar P2 0 Tread)
   )
 )

 (progn ;Else
   (Setq
     P2 (polar Point (GetRad 90) Rise)
     P3 (Polar P2 (GetRad 180) Tread)
   )
 )
)
   (command "LINE" Point P2 P3 "")
   (Setq Point P3)
   (setq n (1+ n))
);While Ends
);STP Ends

;======================================::::::
;Function to Convert Degrees to Radians::::::
;======================================::::::

(defun GetRad(Ang)
(/ (* 3.14 Ang) 180)
)

Posted

My first idea without further looking (little time): localize your variables. Also turn of osnap when doing things like this.

Posted

It worked for me but you did not keep a space between the routine name and the following parens .

 

 (defun c:Stp()

 

Should be like this .

 

(defun c:Stp ()

 

(defun GetRad(Ang)

 

Should be

 

(defun GetRad (Ang)

Besides that , Please localize your arguments .

 

It's good practice buddy.

 

Regards,

 

Tharwat

Posted

Sure I will...

 

This is my 4th day after I started learning Autolisp seriously from scratch...

Hence any advices I would get here would be of great value..!!!

Thanks a lot... :)

Posted (edited)

Just had the urge to do this:

 

(defun c:Stp (/ Point Rise Tread Nos LandingAt P1 LandingLength n P2 P3 OsmodeOld)
 (setq Point       (getpoint "\nPick a Point:")
Rise       (getdist "\nEnter rise of each step:")
Tread       (getdist "\nEnter tread of each step:")
Nos       (getint "\nEnter number of steps:")
LandingAt     (Getint "\nNumber of steps in first flight:")
P1       (list (car Point) (cadr Point))
LandingLength (getdist "\nEnter Length of Landing:")
n       0
OsmodeOld     (getvar "OSMODE")
 ) ;_setq
 (setvar "OSMODE" 0)
 (While
   (< n Nos)
    (if
      (<= n LandingAt)
(Progn ;If True
  (Setq
    P2 (polar Point (GetRad 90) Rise)
    P3 (Polar P2 0 Tread)
  ) ;_setq
) ;_progn
(progn ;Else
  (Setq
    P2 (polar Point (GetRad 90) Rise)
    P3 (Polar P2 (GetRad 180) Tread)
  ) ;_setq
) ;_progn
    )
    (vl-cmdf "_.LINE" Point P2 P3 "")
    (Setq Point P3
   n (1+ n)
    ) ;_setq
 ) ;While Ends
 (setvar "OSMODE" OsmodeOld)
 (princ)
) ;STP Ends
 ;======================================::::::
 ;Function to Convert Degrees to Radians::::::
 ;======================================::::::
(defun GetRad (Ang)
 (/ (* 3.14 Ang) 180)
)
;|«Visual LISP© Format Options»
(120 2 2 2 nil "Ende von " 100 9 0 0 0 T T nil T)
;*** DO NOT add text below the comment! ***|;

Does it work like you want to?

Edited by MarcoW
Code edited
Posted

Still OSMODE was not set when I did it. I set it to '0' at the beginning and it it worked.

Thankyou MacroW for the revised code...!!

Posted

You are right, too much hurrie is no good, code above is updated.

Posted

Thankyou All,

I modified my code, atlast, like this;

(defun c:Stp (/ Point Rise Tread Nos LandingAt P1 LandingLength n P2 P3 OSM)
 (setq Point (getpoint "\nPick a Point:"))
 (Setq OSM (getvar "OSMODE"))
 (setvar "OSMODE" 0)
 (setq Rise (getdist "\nEnter rise of each step:")
	Tread (getdist "\nEnter tread of each step:")
	Nos (getint "\nEnter number of steps:")
	LandingAt (Getint "Number of steps in first flight:")
	LandingLength (getdist "\nEnter length of the landing:")
	P1 (list (car Point) (cadr Point))
	n 0
 ) ;_setq
 
 (setq LandingDrawn 0)
 
 (While (< n Nos)
   (if
     (<= n LandingAt)

     (Progn ;If True
(if
  (eq n LandingAt)
  (Progn
    (Setq
  	P2 (polar Point (GetRad 90) Rise)
  	P3 (Polar P2 0 LandingLength)
    ) ;_setq
         );Prgn Ends

         (progn
           (Setq
     P2 (polar Point (GetRad 90) Rise)
     P3 (Polar P2 0 Tread)
    ) ;_setq
         );Progn Ends

      );If Ends
     );Prgn Ends
     
     (progn ;Else
(Setq
  P2 (polar Point (GetRad 90) Rise)
  P3 (Polar P2 (GetRad 180) Tread)
  ) ;_setq
     ) ;_progn
   );If Ends

   (If
     (eq n LandingAt)
(Progn
      	(command "_.LINE" Point P2 P3 "")
	(setq Point P2)
	(Setq n (1+ n))

)
     	(progn
      	(command "_.LINE" Point P2 P3 "")
	(setq Point P3)
	(Setq n (1+ n))
)
   )
 ) ;While Ends
 
 (setvar "OSMODE" OSM)
 ) ;STP Ends
;======================================::::::
;Function to Convert Degrees to Radians::::::
;======================================::::::
(defun GetRad (Ang)
 (/ (* PI Ang) 180)
)

Posted

Okay.

 

But I would end with "(princ)" else ithe routine will return the OSMODE variable.

 

 
...
 (setvar "OSMODE" OSM)
[color=darkorange][b]  (princ)
[/b][/color]) ;STP Ends

 

Was fun to do, just a learner myself ;-)

Posted

This would avoid any mixing up with snap points .

 

(command "_.LINE" [color=red]"_non" [/color]Point [color=#ff0000]"_non" [/color]P2 [color=#ff0000]"_non"[/color] P3 "")

 

Tharwat

  • 12 years later...
Posted
On 25/01/2011 at 16:30, MarcoW said:

Just had the urge to do this:

 

 

(defun c:Stp (/ Point Rise Tread Nos LandingAt P1 LandingLength n P2 P3 OsmodeOld)
 (setq Point       (getpoint "\nPick a Point:")
Rise       (getdist "\nEnter rise of each step:")
Tread       (getdist "\nEnter tread of each step:")
Nos       (getint "\nEnter number of steps:")
LandingAt     (Getint "\nNumber of steps in first flight:")
P1       (list (car Point) (cadr Point))
LandingLength (getdist "\nEnter Length of Landing:")
n       0
OsmodeOld     (getvar "OSMODE")
 ) ;_setq
 (setvar "OSMODE" 0)
 (While
   (< n Nos)
    (if
      (<= n LandingAt)
(Progn ;If True
  (Setq
    P2 (polar Point (GetRad 90) Rise)
    P3 (Polar P2 0 Tread)
  ) ;_setq
) ;_progn
(progn ;Else
  (Setq
    P2 (polar Point (GetRad 90) Rise)
    P3 (Polar P2 (GetRad 180) Tread)
  ) ;_setq
) ;_progn
    )
    (vl-cmdf "_.LINE" Point P2 P3 "")
    (Setq Point P3
   n (1+ n)
    ) ;_setq
 ) ;While Ends
 (setvar "OSMODE" OsmodeOld)
 (princ)
) ;STP Ends
 ;======================================::::::
 ;Function to Convert Degrees to Radians::::::
 ;======================================::::::
(defun GetRad (Ang)
 (/ (* 3.14 Ang) 180)
)
;|«Visual LISP© Format Options»
(120 2 2 2 nil "Ende von " 100 9 0 0 0 T T nil T)
;*** DO NOT add text below the comment! ***|;

 

 

Does it work like you want to?

Hi can we do including rebar details using same lisp.????

Posted

What is this request for? "Enter Length of Landing".
There is no reaction to entering values.

Posted
14 hours ago, vk shetty said:

Hi can we do including rebar details using same lisp.????

 

Might be better to start a new thread unless the rebar refers to a staircase

Posted

So you want us to do the structural design of a concrete staircase yeah now worries 🤣😂

Posted

Please anyone can give the auto lisp code of this video .

 

Posted

Might be an idea to look at the website in the video, see if the LISP is available there?

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...