Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Need Help : Lisp to draw slope line

  1. #1
    Member
    Join Date
    2013-03
    Posts
    2
    Login to Give a bone
    0

    Default Need Help : Lisp to draw slope line

    Hi all,

    Is their any Lisp routine to draw slope line from multiple line in X-Y plane.

    routine:
    1. input slope in %
    2. select line/lines from X-Y plane
    then draw slope lines (rise in Z axis, run any X & Y axis) as shown in attached screenshot.

    Thank you,
    Attached Images Attached Images

  2. #2
    I could stop if I wanted to
    Join Date
    2002-08
    Posts
    231
    Login to Give a bone
    0

    Default Re: Need Help : Lisp to draw slope line

    This?

    Code:
    (defun errlsp (ch)
    	(cond
    		((eq ch "Function cancelled") nil)
    		((eq ch "quit / exit abort") nil)
    		((eq ch "console break") nil)
    		(T (princ ch))
    	)
    	(setvar "cmdecho" v1)
    	(setvar "orthomode" v2)
    	(setvar "osmode" v3)
    	(setvar "blipmode" v4)
    	(setvar "snapang" v5)
    	(setq *error* olderr)
    	(princ)
    )
    (defun C:SLOPE ( / v1 v2 v3 v4 v5 d_pc flag p_o p_f dlt_x d olderr)
    	(setq v1 (getvar "cmdecho")
    	      v2 (getvar "orthomode")
    	      v3 (getvar "osmode")
    	      v4 (getvar "blipmode")
    	      v5 (getvar "snapang")
    	)
    	(setvar "cmdecho" 0)
    	(setvar "orthomode" 0)
    	(setvar "blipmode" 0)
    	(setq olderr *error* *error* errlsp)
    	(initget 1)
    	(setq d_pc (getreal "\nGive value of slope in en % ?: "))
    	(initget 8)
    	(setq p_o (getpoint "\nStart point: "))
    	(if (eq p_o ()) (setq p_o (getvar "lastpoint")))
    	(initget "In With")
    	(if (eq (getkword "\nSlope[In/With] XY plane <In>: ") "With")
    		(setq flag T)
    		(progn
    			(setvar "snapang" (atan (/ d_pc 100.0)))
    			(setvar "orthomode" 1)
    			(setq flag nil)
    		)
    	)
    	(initget 41)
    	(setq p_f (getpoint p_o "\nEnd Point: "))
    	(setvar "osmode" (+ 16384 (rem (getvar "osmode") 16384)))
    	(if flag
    		(progn
    			(setq dlt_x (sqrt (+ (* (- (car p_o) (car p_f)) (- (car p_o) (car p_f))) (* (- (cadr p_o) (cadr p_f)) (- (cadr p_o) (cadr p_f))))))
    			(setq d (* dlt_x (/ (sin (atan (/ d_pc 100.0))) (cos (atan (/ d_pc 100.0))))))
    			(setq p_f (list (car p_f) (cadr p_f) (+ (caddr p_o) d)))
    			(command "_.line" p_o p_f "")
    			
    		)
    		(progn
    			(setq dlt_x (- (car p_f) (car p_o)))
    			(setq d (/ dlt_x (cos (atan (/ d_pc 100.0)))))
    			(command "_.line" p_o (polar p_o (atan (/ d_pc 100.0)) d) "")
    		)
    	)
    	(setvar "cmdecho" v1)
    	(setvar "orthomode" v2)
    	(setvar "osmode" v3)
    	(setvar "blipmode" v4)
    	(setvar "snapang" v5)
    	(setq *error* olderr)
    	(prin1)
    )

  3. #3
    topomav
    Guest
    Login to Give a bone
    0

    Default Re: Need Help : Lisp to draw slope line

    Hi, Bruno Valsecchi. I know that the post is old, but what the "With" do in this code. I can not understand it. Can you explain me ?
    Thanks

  4. #4
    I could stop if I wanted to
    Join Date
    2002-08
    Posts
    231
    Login to Give a bone
    0

    Default Re: Need Help : Lisp to draw slope line

    Slope[In/With] XY plane:

    "In" : The angle is calculated in the plane XY. (2D)
    "With" : The angle is calculate with the plane XY; -> therefore in the plane XZ (if points are in 3D)

  5. #5
    topomav
    Guest
    Login to Give a bone
    0

    Default Re: Need Help : Lisp to draw slope line

    I try the code and I deactivate the 3d . But i see that this code works works correct with (+/- to the slope) only for left to right. If I want to go down from right to left I have to write 5% not -5% and this confiuse a little. Is it possible to work for the bothe sides with -% dor down and +% for up?

    Thanks


    Code:
    (defun errlsp (ch)
    	(cond
    		((eq ch "Function cancelled") nil)
    		((eq ch "quit / exit abort") nil)
    		((eq ch "console break") nil)
    		(T (princ ch))
    	)
    	(setvar "cmdecho" v1)
    	(setvar "orthomode" v2)
    	(setvar "osmode" v3)
    	(setvar "blipmode" v4)
    	(setvar "snapang" v5)
    	(setq *error* olderr)
    	(princ)
    )
    (defun C:SLP ( / v1 v2 v3 v4 v5 d_pc flag p_o p_f dlt_x d olderr)
    	(setq v1 (getvar "cmdecho")
    	      v2 (getvar "orthomode")
    	      v3 (getvar "osmode")
    	      v4 (getvar "blipmode")
    	      v5 (getvar "snapang")
    	)
    	(setvar "cmdecho" 0)
    	(setvar "orthomode" 0)
    	(setvar "blipmode" 0)
    	(setq olderr *error* *error* errlsp)
    	(initget 1)
    	(setq d_pc (getreal "\nGive value of slope in en % ?: "))
    	(initget 8)
    	(setq p_o (getpoint "\nStart point: "))
    	(if (eq p_o ()) (setq p_o (getvar "lastpoint")))
    	;(initget "In With")
    	;(if (eq (getkword "\nSlope[In/With] XY plane <In>: ") "With")
    		(setq flag T)
    		(progn
    			(setvar "snapang" (atan (/ d_pc 100.0)))
    			(setvar "orthomode" 1)
    			(setq flag nil)
    		)
    	;)
    	(initget 41)
    	(setq p_f (getpoint p_o "\nEnd Point: "))
    	(setvar "osmode" (+ 16384 (rem (getvar "osmode") 16384)))
    	(if flag
    		(progn
    			(setq dlt_x (sqrt (+ (* (- (car p_o) (car p_f)) (- (car p_o) (car p_f))) (* (- (cadr p_o) (cadr p_f)) (- (cadr p_o) (cadr p_f))))))
    			(setq d (* dlt_x (/ (sin (atan (/ d_pc 100.0))) (cos (atan (/ d_pc 100.0))))))
    			(setq p_f (list (car p_f) (cadr p_f) (+ (caddr p_o) d)))
    			(command "_.line" p_o p_f "")
    			
    		)
    		(progn
    			(setq dlt_x (- (car p_f) (car p_o)))
    			(setq d (/ dlt_x (cos (atan (/ d_pc 100.0)))))
    			(command "_.line" p_o (polar p_o (atan (/ d_pc 100.0)) d) "")
    		)
    	)
    	(setvar "cmdecho" v1)
    	(setvar "orthomode" v2)
    	(setvar "osmode" v3)
    	(setvar "blipmode" v4)
    	(setvar "snapang" v5)
    	(setq *error* olderr)
    	(prin1)
    )

  6. #6
    topomav
    Guest
    Login to Give a bone
    0

    Default Re: Need Help : Lisp to draw slope line

    Perhaps we can add an option like this to set the direction. Because is easy every time to say for example (-2% for down ) and (2% for up) for the bouth sides

    Code:
    (initget "A->B  B<-A")
    Thanks

  7. #7
    topomav
    Guest
    Login to Give a bone
    0

    Default Re: Need Help : Lisp to draw slope line

    Hi Bruno.Valsecchi. I try to change the code but something is going wrong. Can you help?


    Code:
    (defun errlsp (ch)
    	(cond
    		((eq ch "Function cancelled") nil)
    		((eq ch "quit / exit abort") nil)
    		((eq ch "console break") nil)
    		(T (princ ch))
    	)
    	(setvar "cmdecho" v1)
    	(setvar "orthomode" v2)
    	(setvar "osmode" v3)
    	(setvar "blipmode" v4)
    	(setvar "snapang" v5)
    	(setq *error* olderr)
    	(princ)
    )
    (defun C:SLP ( / v1 v2 v3 v4 v5  d_pc flag p_o p_f dlt_x d olderr)
    	(setq v1 (getvar "cmdecho")
    	      v2 (getvar "orthomode")
    	      v3 (getvar "osmode")
    	      v4 (getvar "blipmode")
    	      v5 (getvar "snapang")
    	)
    	(setvar "cmdecho" 0)
    	(setvar "orthomode" 0)
    	(setvar "blipmode" 0)
    	(setq olderr *error* *error* errlsp)
    	(initget 1)
    	(setq d_pc (getreal "\nGive value of slope in en % ?: "))
    	(initget 8)
    	(setq p_o (getpoint "\nStart point: "))
    	(if (eq p_o ()) (setq p_o (getvar "lastpoint")))
    	(initget "A->B B<-A")
    	(if (eq (getkword "\nSlope[A->B/B<-A] XY plane <A->B>: ") "B<-A")
    		(setq flag T)
    		(progn
    			(setvar "snapang" (atan (/ d_pc 100.0)))
    			(setvar "orthomode" 1)
    			(setq flag nil)
    		)
    	)
    	(initget 41)
    	(setq p_f (getpoint p_o "\nEnd Point: "))
    	(setvar "osmode" (+ 16384 (rem (getvar "osmode") 16384)))
    		(progn
    			(setvar "snapang" (atan (/ (- d_pc) 100.0)))
    			(setvar "orthomode" 1)
    			(setq flag nil)
    		)
    	(setvar "cmdecho" v1)
    	(setvar "orthomode" v2)
    	(setvar "osmode" v3)
    	(setvar "blipmode" v4)
    	(setvar "snapang" v5)
    	(setq *error* olderr)
    	(prin1)
    )
    Thanks

  8. #8
    topomav
    Guest
    Login to Give a bone
    0

    Default Re: Need Help : Lisp to draw slope line

    Any options? Only for 2d

  9. #9
    I could stop if I wanted to
    Join Date
    2002-08
    Posts
    231
    Login to Give a bone
    0

    Default Re: Need Help : Lisp to draw slope line

    Quote Originally Posted by Razor View Post
    Hi Bruno.Valsecchi. I try to change the code but something is going wrong. Can you help?


    Thanks
    A simpler version with (grread) to meet your wish: in 2D and the sign of the slope with respect to the starting point.

    Code:
    (defun C:SLP ( / var_snap pt_start slope key pt_key pt_end)
      (setq var_snap (getvar "SNAPANG"))
      (initget 8)
      (setq pt_start (getpoint "\nStart point: "))
      (if (eq pt_start ()) (setq pt_start (getvar "LASTPOINT")))
      (initget 1)
      (setq slope (getreal "\nGive value of slope in en % ?: "))
      (princ "\nEnd Point: ")
      (while (and (setq key (grread T 4 0)) (/= (car key) 3))
        (cond
          ((eq (car key) 5)
            (setq pt_key (cadr key))
            (redraw)
            (if (< (car pt_key) (car pt_start))
              (setvar "SNAPANG" (- pi (atan (* slope 0.01))))
              (setvar "SNAPANG" (atan (* slope 0.01)))
            )
            (grdraw pt_start (setq pt_end (polar pt_start (getvar "SNAPANG") (distance pt_start pt_key))) 7)
          )
        )
      )
      (redraw)
      (setvar "SNAPANG" var_snap)
      (setvar "LASTPOINT" pt_end)
      (entmake
        (list
          (cons 0 "LINE")
          (cons 100 "AcDbEntity")
          (cons 67 (if (eq (getvar "CVPORT") 2) 0 1))
          (cons 410 (if (eq (getvar "CVPORT") 2) "Model" (getvar "CTAB")))
          (cons 8 (getvar "CLAYER"))
          (cons 100 "AcDbLine")
          (cons 10 (trans pt_start 1 0))
          (cons 11 (trans pt_end 1 0))
          (cons 210 (trans '(0 0 1) 1 0 T))
        )
      )
      (prin1)
    )

  10. #10
    topomav
    Guest
    Login to Give a bone
    0

    Default Re: Need Help : Lisp to draw slope line

    Hi thanks for the reply,I add osmode 521 to give the option to snap on Endpoints, Node and Nearest at the End Point , but the snap is enabled but don't snap any ware in the drawing (for the end point). Why?


    Code:
      (setvar "OSMODE" 521) ; enpoint, node,nearest
    
    and at the end to return 
      (setvar "OSMODE" 13) ;End ,center,node

    Code:
    (defun C:SLP ( / var_snap pt_start slope key pt_key pt_end)
      (setq var_snap (getvar "SNAPANG"))
      (initget 8)
      (setq pt_start (getpoint "\nStart point: "))
      (if (eq pt_start ()) (setq pt_start (getvar "LASTPOINT")))
      (initget 1)
      (setq slope (getreal "\nGive value of slope in en % ?: "))
      (setvar "OSMODE" 521) ; enpoint, node,nearest
      (princ "\nEnd Point: ")
      (while (and (setq key (grread T 4 0)) (/= (car key) 3))
        (cond
          ((eq (car key) 5)
            (setq pt_key (cadr key))
            (redraw)
            (if (< (car pt_key) (car pt_start))
              (setvar "SNAPANG" (- pi (atan (* slope 0.01))))
              (setvar "SNAPANG" (atan (* slope 0.01)))
            )
            (grdraw pt_start (setq pt_end (polar pt_start (getvar "SNAPANG") (distance pt_start pt_key))) 7)
          )
        )
      )
      (redraw)
      (setvar "SNAPANG" var_snap)
      (setvar "LASTPOINT" pt_end)
      (entmake
        (list
          (cons 0 "LINE")
          (cons 100 "AcDbEntity")
          (cons 67 (if (eq (getvar "CVPORT") 2) 0 1))
          (cons 410 (if (eq (getvar "CVPORT") 2) "Model" (getvar "CTAB")))
          (cons 8 (getvar "CLAYER"))
          (cons 100 "AcDbLine")
          (cons 10 (trans pt_start 1 0))
          (cons 11 (trans pt_end 1 0))
          (cons 210 (trans '(0 0 1) 1 0 T))
        )
      )
      (prin1)
      (setvar "OSMODE" 13) ;End ,center,node
    )
    Thanks

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 13
    Last Post: 2014-07-01, 02:23 PM
  2. Replies: 2
    Last Post: 2012-07-13, 09:04 PM
  3. Draw line lisp
    By rphillips.137763 in forum AutoLISP
    Replies: 3
    Last Post: 2012-06-21, 02:05 PM
  4. Replies: 3
    Last Post: 2007-05-23, 11:44 AM
  5. How to draw double slope roof and structure (moved here)
    By fantastic in forum Revit Architecture - General
    Replies: 1
    Last Post: 2003-06-18, 11:28 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •