Change in lisp to get E,N Coordinates added to CH

Change in lisp to get E,N Coordinates added to CH

mint09
Enthusiast Enthusiast
2,907 Views
7 Replies
Message 1 of 8

Change in lisp to get E,N Coordinates added to CH

mint09
Enthusiast
Enthusiast

hai, i need a small help.i have a working lisp routine which gives perpendicular line distance to main pline when clicked on a place perpendicular, all i want to add is the leader at the where i click and Easting and Northing and CH. and also instead of TEXT i need MText position where i can click. pls reply if its possible.

 

i've added a screenshot for reference ..... thanks

 

(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)
0 Likes
Accepted solutions (2)
2,908 Views
7 Replies
Replies (7)
Message 2 of 8

mint09
Enthusiast
Enthusiast

can anyone help please?? i dont know how to change it.

0 Likes
Message 3 of 8

ВeekeeCZ
Consultant
Consultant
Accepted solution

No wonder... No dwg, no help... 

 

Try this... 

(entmakex
	  (list
	    '(0 . "Mtext")
	    '(100 . "AcDbEntity")
	    '(67 . 0)
	    '(370 . 13)
	    '(100 . "AcDbMText")
	    (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
			  "\nE=" (rtos (car p) 2 3)
			  "\nN=" (rtos (cadr p) 2 3)
		  )
	    )
	    ;(cons 71 0)
	    ;(cons 72 0)
	    ;(cons 11 '(0 0 0))
	    ;'(100 . "AcDbText")
	    ;(cons 73 0)
	  )
	)
Message 4 of 8

mint09
Enthusiast
Enthusiast

Thank you, its working well, Just one help if possible. how to add leader to it? i've tried to change it but keeps getting error..

this is what ive changed in it. pls check, i just want the texts with leader..

(defun c:Chin (/ s p c a d tp sch PTXT )
  (setq sch (getstring "\nSpecify start chainage : <0>"))			;"0" is set as the default value
...
...
...
(entmakex
	  (list
	    '(0 . "Mtext")
	    '(100 . "AcDbEntity")
	    '(67 . 0)
	    '(370 . 13)
	    '(100 . "AcDbMText")
	    (cons 10 tp)
	    (cons 40 0.6)		; Change text height here
	    (cons 1
		  (command "leader" p PTXT "" (strcat "CH=" sch "+"
			  (rtos (vlax-curve-getdistatpoint s c) 2 3)			;3 instead of 4 to specify precision
			  "\nE=" (rtos (car p) 2 3)
			  "\nN=" (rtos (cadr p) 2 3) "")
		  )
	    )
	    ;(cons 71 0)
	    ;(cons 72 0)
	    ;(cons 11 '(0 0 0))
	    ;'(100 . "AcDbText")
	    ;(cons 73 0)
	  )
	)
...
...

keeps getting error..

Thanks @ВeekeeCZ 

0 Likes
Message 5 of 8

dbhunia
Advisor
Advisor

Try this way.....

 

(defun c:Chi (/ s p c a d tp sch)
(setvar "cmdecho" 0)
  (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 : "))
       )
		(command "_.QLEADER" c p tp 1 
				(strcat "CH=" sch "+" (rtos (vlax-curve-getdistatpoint s c) 2 3))
				(strcat "E=" (rtos (car p) 2 3))
				(strcat "N=" (rtos (cadr p) 2 3))
				""
		)
		(vlax-put-property (vlax-ename->vla-object (entlast)) 'height 0.6);;; Text Height 0.6
     )
  )
  (setvar "cmdecho" 1)
  (princ)
)
(vl-load-com)

Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 6 of 8

mint09
Enthusiast
Enthusiast

thanks, it is working but is it possible to change the leader vertex to 2? . its giving a 3 vertex leader and the leader line is starting from the centerline, not the line perpendicular where i pick. Please check the screenshot i have attached.

 

Thank you for all helps.. @dbhunia @ВeekeeCZ 

0 Likes
Message 7 of 8

dbhunia
Advisor
Advisor
Accepted solution

For.....

 


@mint09 wrote:

thanks, it is working but is it possible to change the leader vertex to 2? . its giving a 3 vertex leader and the leader line is starting from the centerline, not the line perpendicular where i pick. Please check the screenshot i have attached.

 

Thank you for all helps.. @dbhunia @ВeekeeCZ 


 

Change the line....

(command "_.QLEADER" c p tp 1 

To.....

(command "_.QLEADER" p tp "" 1

 

 



Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 8 of 8

mint09
Enthusiast
Enthusiast

Thank you so much, its working perfect, saves me a lot of time.  Thanks a lot...

 

i've attached the lisp in case anyone gets it useful. it gives coordinates and chainage(perpendicular to chainage line).

0 Likes