Jump to content

Ask for start chainage at every lisp command


Recommended Posts

hai, i need a small help.i have a working lisp routine which gives perpendicular line distance to main line, 

i want the the lisp to ask me every time i start the lisp that what chainage it should start and what i enter should change the numerical text in this command "" (strcat "CH=1+" "".

 

means, when i start the lisp and it asks for chainage then i enter 23 then it should out as "" (strcat "CH=23+" "".

 

and if possible the out put decimal can be changed to 3 decimals. now its coming in 4 decimals like 23+455.2565.

thank you..

pls reply if its possible... thanks

(defun c:Chi (/ s p c a d tp)
  (if
    (and (setq s (car (entsel "\nPick a polyline :")))
	 (or (= (cdr (assoc 0 (entget s))) "LWPOLYLINE")
	     (alert "Invalid object! Please pick a polyline only.")
	 )
    )
     (while
       (and
	 (setq
	   p (getpoint "\nSpecify point perpendicular to polyline :")
	 )
	 (setq c (vlax-curve-getclosestpointto s p))
	 (setq a (angle p c))
	 (not (grdraw p c 1 -1))
	 ;; rubber line in red colour.
	 (setq d (angle	'(0. 0. 0.)
			(vlax-curve-getfirstderiv
			  s
			  (vlax-curve-getparamatpoint s c)
			)
		 )
	 )
	 (or
	   (or (equal (rem (+ d (* pi 0.5)) (+ pi pi)) a 1e-4)
	       (equal (rem (+ d (* pi 1.5)) (+ pi pi)) a 1e-4)
	   )
	   (alert
	     "Picked point is not a perpendicular to picked polyline. <!>"
	   )
	 )
	 (setq tp (getpoint "\nSpecify Point for Text : "))
       )
	(entmakex
	  (list
	    '(0 . "text")
	    '(100 . "AcDbEntity")
	    '(67 . 0)
	    '(370 . 13)
	    '(100 . "AcDbText")
	    (cons 10 tp)
	    (cons 40 0.6)		; Change text height here
	    (cons 1
		  (strcat "CH=1+"
			  (rtos (vlax-curve-getdistatpoint s c) 2 4)
		  )
	    )
	    (cons 71 0)
	    (cons 72 0)
	    (cons 11 '(0 0 0))
	    '(100 . "AcDbText")
	    (cons 73 0)
	  )
	)
     )
  )
  (princ)
)
(vl-load-com)

thank you..

Link to post
Share on other sites
(defun c:Chi (/ s p c a d tp sch)
  (setq sch (getstring "\nSpecify start chainage : <0>"))			;"0" is set as the default value
  (if (= sch "")(setq sch "0"))
  (if
    (and (setq s (car (entsel "\nPick a polyline :")))
	 (or (= (cdr (assoc 0 (entget s))) "LWPOLYLINE")
	     (alert "Invalid object! Please pick a polyline only.")
	 )
    )
     (while
       (and
	 (setq
	   p (getpoint "\nSpecify point perpendicular to polyline :")
	 )
	 (setq c (vlax-curve-getclosestpointto s p))
	 (setq a (angle p c))
	 (not (grdraw p c 1 -1))
	 ;; rubber line in red colour.
	 (setq d (angle	'(0. 0. 0.)
			(vlax-curve-getfirstderiv
			  s
			  (vlax-curve-getparamatpoint s c)
			)
		 )
	 )
	 (or
	   (or (equal (rem (+ d (* pi 0.5)) (+ pi pi)) a 1e-4)
	       (equal (rem (+ d (* pi 1.5)) (+ pi pi)) a 1e-4)
	   )
	   (alert
	     "Picked point is not a perpendicular to picked polyline. <!>"
	   )
	 )
	 (setq tp (getpoint "\nSpecify Point for Text : "))
       )
	(entmakex
	  (list
	    '(0 . "text")
	    '(100 . "AcDbEntity")
	    '(67 . 0)
	    '(370 . 13)
	    '(100 . "AcDbText")
	    (cons 10 tp)
	    (cons 40 0.6)		; Change text height here
	    (cons 1
		  (strcat "CH=" sch "+"
			  (rtos (vlax-curve-getdistatpoint s c) 2 3)			;3 instead of 4 to specify precision
		  )
	    )
	    (cons 71 0)
	    (cons 72 0)
	    (cons 11 '(0 0 0))
	    '(100 . "AcDbText")
	    (cons 73 0)
	  )
	)
     )
  )
  (princ)
)
(vl-load-com)

There's surely a better way to do it, but this works for me.

 

  • Thanks 1
Link to post
Share on other sites

thank you so much, it works perfectly.

 

also is it possible to change the chainage start if the polyline length exceeds 1000. means if the chainage is 23 and i got CH=23+999.856 it adds 1  o 23 in next meter , like 24+000.000
thanks you

Link to post
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
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...