Jump to content
minejash

Codes to Add Text only and no need leader..

Recommended Posts

Posted (edited)

hai, i need a small help.i have a working lisp routine which gives perpendicular line distance to main line when clicked on a place perpendicular, only thing i want to try and add is to remove the leader that adds and only add text without leader in position where i can click. pls reply if its possible... thanks:)

 

(defun c:Test ( / s p c a d)
 (if (and (setq s (car (entsel "\nPick a polyline :")))
        (or (= (cdr (assoc 0 (entget s))) "LWPOLYLINE")
            (alert "Invalid object! Please pick a polyline only.")
            )
        (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. <!>")
            )
        )
 (command "_.leader" "_non" p "\\" "" (strcat "CHAINAGE=3+0" (rtos (vlax-curve-getdistatpoint s c) 2 4)) "")
 )
(princ)
) (vl-load-com)

Edited by SLW210
Fixed Code Tags

Share this post


Link to post
Share on other sites

Try this :-

 

(defun c:Test (/ s p c a d)
 (if
   (and
     (setq s (car (entsel "\nPick a polyline :")))
     (or (= (cdr (assoc 0 (entget s))) "LWPOLYLINE")
  (alert "Invalid object! Please pick a polyline only.")
     )
     (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. <!>"
  )
     )
   )
    (entmakex
      (list
 '(0 . "text")
 '(100 . "AcDbEntity")
 '(67 . 0)
 '(370 . 13)
 '(100 . "AcDbText")
 (cons 10 p)
 (cons 40 2.5)			[color="red"]; Change text height here[/color]
 (cons 1
       (strcat "chainage=3+0"
	       (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)

Share this post


Link to post
Share on other sites

Thank u, it works good

 

but just want to know if its possible to select the text location manually, as this code lets the text at the point where i click for distance. Like the leader starts and then text location except no leader needed, only text. If possible it would be nice.

 

This code really helps a lot, thank you so much..

Share this post


Link to post
Share on other sites

also is it possible to continous the command after i select the polyline, like i select the polyline then after were ever i click it gives the distance to it, (like MULTIPLE command).

 

the current command ask for polyline after every click and length.. thanks:)

Share this post


Link to post
Share on other sites

Command is continuous in this code as per your requirement:

(defun c:Test (/ 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 2.5)		; Change text height here
    (cons 1
	  (strcat "chainage=3+0"
		  (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)

Share this post


Link to post
Share on other sites
also is it possible to continous the command after i select the polyline, like i select the polyline then after were ever i click it gives the distance to it, (like MULTIPLE command).

 

the current command ask for polyline after every click and length.. thanks:)

 

I've updated code above for continuous operation, check it

Share this post


Link to post
Share on other sites

Thank you so much. It works perfectly...:D

 

i didn't know how to change the code to simple text sting, thanks so much...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×