Jump to content

Help me on Aligning text with line angle


amb2301

Recommended Posts

Hi Friends,

i need the text to get aligned automatically to the line angle as shown in

attached sample1.dwg, text 1 should be always at top of the line & remaining(text 2,text 3 etc.,) all should fall below to that line. Please help me.

 

Thanks in Advance.

sample 1.dwg

Link to comment
Share on other sites

Not quite the answer but look at the dump of mtext

Application (RO) = #

; Height = 30.0

; Layer = "CABLE_UNDERGROUND_ANNO"

; LineSpacingDistance = 50.0

; LineSpacingFactor = 1.0

; LineSpacingStyle = 1

; Linetype = "ByLayer"

; LinetypeScale = 1.0

; Lineweight = -1

; Normal = (0.0 0.0 1.0)

; ObjectName (RO) = "AcDbMText"

; PlotStyleName = "Color_1"

; Rotation = 0.0

; StyleName = "Standard"

; TextString = "24FIB SPSP DSLT\\P1356.00m \\PDXVL_FT2:1-12 \\PBD:13-24 \\P"

; Width = 0.0

the mtext or text has a height, top left is known spacing is known

next read the string and get 1st line number of characters so a new insert point can be worked out

place Mtext and rotate

 

; this can be done in a couple of ways is step 1. 
; done purposely as pick two points not a line
(defun C:T2pts ( / pt1 pt2 ang tobj vlobj)
(SETQ PT1 (GETPOINT "\nPick 1st pt" ))
(SETQ PT2 (GETPOINT "\nPick 2nd pt" ))
(setq ang (angle pt1 pt2))
(SETQ TOBJ (ENTSEL "\nPick Text"))
(setq vlobj (vlax-ename->vla-object (car tobj)))
(vlax-put-property vlobj "Rotation" ang)
)
(C:T2pts)

 

step 2 have to have a think about that.

Link to comment
Share on other sites

Nice one Dadgad adding lee's code to pre-aligning the text as requested would be very powerful. It may be worthwhile to look at a few options in placing the mtext other than the standard 9 and just middle of 1st line. Plus maybe a few more like bottom line. Need some time to have a go. Thinking Grrr's matrix dcl.

Link to comment
Share on other sites

Time

 

(defun c:demo (/ _theAngle ent_str ent_line M&L Topoint MT_data ang prop)

 ;;			pBe Feb 2018			;;
 ;;			CADTutor				;;

[color="blue"]  (defun _theAngle (en / param pts)
   (setq	param (vlax-curve-getParamAtPoint
		   (Car en)
		   (vlax-curve-getclosestpointto
			(Car en)
			(trans (cadr en) 1 0)
		   ) ;_ end of vlax-curve-getclosestpointto
		 ) ;_ end of vlax-curve-getParamAtPoint
   ) ;_ end of setq
   (setq	pts
	 (mapcar '(lambda (p)
			  (trans (vlax-curve-getPointAtParam (Car en) p) 1 0)
			) ;_ end of lambda
		    (list (fix param) (1+ (fix param)))
	 ) ;_ end of mapcar
   ) ;_ end of setq
   (angle (car pts) (cadr pts))
 )[/color] ;_ end of defun

 (while
   (and
 (setq ent_str (Car (entsel "\nSelect Mtext")))
 (Setq ent_line (entsel "\nSelect LWPolyline/Line"))
 (setq M&L (mapcar 'vlax-ename->vla-object
			    (list ent_str (Car ent_line))
		 ) ;_ end of mapcar
 ) ;_ end of setq
 (vl-every '(lambda	(o p)
		    (wcmatch (vla-get-objectname o) p)
		  ) ;_ end of lambda
		 M&L
		 '("AcDbMText" "AcDbLine,AcDbPolyline")
 ) ;_ end of vl-every
   ) ;_ end of and
(progn
  (setq Topoint (vlax-curve-getclosestpointto
			   (car ent_line)
			   (cadr ent_line)
			 ) ;_ end of vlax-curve-getclosestpointto
  ) ;_ end of setq
  (setq M&L	 (Car M&L)
	   MT_data (mapcar
			   '(lambda (p) (vlax-get M&L p)
			    ) ;_ end of lambda
			   '("AttachmentPoint" "Height" "LineSpacingDistance")
			 ) ;_ end of mapcar
  ) ;_ end of setq
  (setq ang ([b][color="blue"]_theAngle [/color][/b]ent_line))


  (Foreach prop '("Rotation" "AttachmentPoint" "InsertionPoint")
    (apply  'vlax-put
	 (vl-list*  M&L
	   (Assoc prop
		(list
		  (list "Rotation"
			   (setq ang (if (and (> ang (/ pi 2))
							  (<= ang (* pi 1.5))
						  ) ;_ end of and
						(+ ang pi) ang
					   ) ;_ end of if
			   ) ;_ end of setq
		  ) ;_ end of list
		  (list "AttachmentPoint"
			   (vl-some '(lambda (v)
						(if (member (car MT_data) v) (car v)
						) ;_ end of if
					   ) ;_ end of lambda
					  '((1 4 7) (2 5  (3 6 9))
			   ) ;_ end of vl-some
		  ) ;_ end of list
		  (list "InsertionPoint"
			   (polar	Topoint
					(+ ang (/ pi 2.0))
					(+ (Cadr MT_data)
					   (* 0.5 (- (caddr MT_data) (Cadr MT_data))
					   ) ;_ end of *
					) ;_ end of +
			   ) ;_ end of polar
		  ) ;_ end of list
		) ;_ end of list
	   ) ;_ end of Assoc
	 ) ;_ end of vl-list*
    ) ;_ end of apply
  ) ;_ end of Foreach
) ;_ end of progn
 ) ;_ end of if
 (princ)

)

 

EDIT: Modified to work on Lwpolyline/Line

Edited by pBe
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...