Lisp routine to rotate dimension text 90 degree to the dimension line

CNinBC
Advocate
Advocate

Lisp routine to rotate dimension text 90 degree to the dimension line

CNinBC
Advocate
Advocate

Hi Everyone, is there a lisp routine to rotate the dimension text 90 degree to the dimension line when placing the dimension? so that the CAD user can dimension the lane width without rotate the ucs. Thanks.

 

Capture.PNG

0 Likes
Reply
Accepted solutions (1)
2,736 Views
9 Replies
Replies (9)

CodeDing
Advisor
Advisor

@CNinBC ,

 

I will need some further explanation to better understand your request.

- Are you just wanting a special command that will always create a dimension with text parallel to the road lines?

- How is your dim style setup? (is text "Horizontal" or "Aligned with dimension line"?)

- Your dimension circled in your image has no dimension lines, ticks, or arrows.. Does this mean you only want to show the distance and not the dimension?

 

Best,

~DD


Need AutoLisp help? Try my custom GPT 'AutoLISP Ace':
https://chat.openai.com/g/g-Zt0xFNpOH-autolisp-ace
0 Likes

dlanorh
Advisor
Advisor

Try this

 

(defun c:dimtext90 ( / obj pt1 pt2 ang)
  (setq obj (vlax-ename->vla-object (car (entsel "\nSelect Aligned Dim : ")))
        pt1 (vlax-get obj 'extline1point)
        pt2 (vlax-get obj 'extline2point)
        ang (+ (angle pt1 pt2) (* pi 0.5))
  )
  (vlax-put-property obj 'textrotation ang)
);end_defun  

I am not one of the robots you're looking for

0 Likes

CNinBC
Advocate
Advocate

Thanks for your reply, please see my respond attached below in red.

@CodeDing wrote:

@CNinBC ,

 

I will need some further explanation to better understand your request.

- Are you just wanting a special command that will always create a dimension with text parallel to the road lines? Yes

- How is your dim style setup? (is text "Horizontal" or "Aligned with dimension line"?) can be either one

- Your dimension circled in your image has no dimension lines, ticks, or arrows.. Does this mean you only want to show the distance and not the dimension? correct, i only need to show the dimension text for the lane width.

 

Best,

~DD


 

0 Likes

CNinBC
Advocate
Advocate

Thanks @dlanorh , your lisp routine works, however, i wish this can be done when placing the dimension, instead of create the dimension and then rotate it.

0 Likes

dlanorh
Advisor
Advisor
I don't think it is possible when placing the text, with the standard dimension dialogue. It is possible if someone writes a custom lisp to place the dimension.

I am not one of the robots you're looking for

0 Likes

CNinBC
Advocate
Advocate

Thanks @dlanorh, I modified your lisp routine slightly to consider the readable angle of the dimension text. 

(defun c:dimtext90 ( / obj pt1 pt2 ang)
  (setq obj (vlax-ename->vla-object (car (entsel "\nSelect Aligned Dim : ")))
        pt1 (vlax-get obj 'extline1point)
        pt2 (vlax-get obj 'extline2point)
        ang (if (> (angle pt1 pt2) pi) (+ (angle pt1 pt2) (* pi 0.5)) (- (angle pt1 pt2) (* pi 0.5)))
  )
  (vlax-put-property obj 'textrotation ang)
);end_defun
0 Likes

ВeekeeCZ
Consultant
Consultant

Little different version. 

 

(defun c:DimAlignedVert ( / en)
  (command "_.DIMALIGNED" pause pause "@")
  (setq en (entlast))
  (setpropertyvalue en "TextRotation" (+ (angle (list (getpropertyvalue en "XLine1Point/X")
						      (getpropertyvalue en "XLine1Point/Y"))
						(list (getpropertyvalue en "XLine2Point/X")
						      (getpropertyvalue en "XLine2Point/Y")))
					 (* pi 0.5)))
  (command-s "_.DIMTEDIT" en)
  (princ)
  )

I tried to use (getpropertyvalue)... it's not as nice as I hoped... but it works. Anyhow, this is not what this idea is about.

0 Likes

CNinBC
Advocate
Advocate

Thanks @ВeekeeCZ , if this program can maintain dimension readable, that will be perfect.


@ВeekeeCZ wrote:

Little different version. 

 

(defun c:DimAlignedVert ( / en)
  (command "_.DIMALIGNED" pause pause "@")
  (setq en (entlast))
  (setpropertyvalue en "TextRotation" (+ (angle (list (getpropertyvalue en "XLine1Point/X")
						      (getpropertyvalue en "XLine1Point/Y"))
						(list (getpropertyvalue en "XLine2Point/X")
						      (getpropertyvalue en "XLine2Point/Y")))
					 (* pi 0.5)))
  (command-s "_.DIMTEDIT" en)
  (princ)
  )

I tried to use (getpropertyvalue)... it's not as nice as I hoped... but it works. Anyhow, this is not what this idea is about.


 

0 Likes

CNinBC
Advocate
Advocate
Accepted solution

I also modified the code to consider the readable angle. Thanks everyone.

 

(defun c:DimAlignedVert ( / en)
  (command "_.DIMALIGNED" pause pause "@")
  (setq en (entlast))
	(setq DimAngle (angle (list (getpropertyvalue en "XLine1Point/X") (getpropertyvalue en "XLine1Point/Y")) (list (getpropertyvalue en "XLine2Point/X") (getpropertyvalue en "XLine2Point/Y"))))
	(if (> DimAngle pi) (Setq DimAngle (+ DimAngle (* pi 0.5))) (setq DimAngle (- DimAngle (* pi 0.5))))
  (setpropertyvalue en "TextRotation" DimAngle)
  (command-s "_.DIMTEDIT" en)
  (princ)
  )
0 Likes