Jump to content

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


minejash

Recommended Posts

hai, i need 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)

 

CHHHH.JPG

  • Like 1
Link to comment
Share on other sites

1 hour ago, minejash said:

hai, i need 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)

 

CHHHH.JPG

may be you need offset text also.

CH=:4+676.422

off=xx.xx

E=

N=

Link to comment
Share on other sites

I don't know how to join the lisp codes, i wanted the cords with the existing changes i am getting, thats why. Please see the screen shots. thanks.

Link to comment
Share on other sites

You will have to replace the entire entmakex " Text" section I would suggest as you are learning you would be better of using (command "leader" that is what I was suggesting, did you find any code when you googled ? As you get more experienced entmakex is a lot faster but requires more input and easier to get wrong.

Link to comment
Share on other sites

@BIGALi got the coordinates lisp, but i got no idea about Lisp codes and how to modify it properly. that's the problem. ill share the coordinates with leader lisp here. don't know how to combine the 2 lisps together..😔

 

;cord-ldr.lsp
; x,y Coordinates on Leader Lines

(defun C:CR (/ PNT1 P1X P1Y STDY DY PTXT )
    (setq PNT1 (getpoint "\nPick coordinate point: "))
    (setq P1X (car pnt1)) ;x coord
    (setq P1Y (cadr pnt1)) ;y coord
    (setq STDX (rtos P1X 2 3))
    (setq STDY (rtos P1Y 2 3))
    ;(setq COORD (strcat "E=" STDX "\nN=" STDY))
    (setq PTXT (getpoint "\nPick text location: "))
    (command "leader" PNT1 PTXT "" (strcat "E=" STDX)
      (strcat "N=" STDY) "")
    (princ)) ; end

 

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