Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
CNinBC
2737 Views, 9 Replies

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

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

9 REPLIES 9
Message 2 of 10
CodeDing
in reply to: CNinBC

@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
Message 3 of 10
dlanorh
in reply to: CNinBC

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

Message 4 of 10
CNinBC
in reply to: CodeDing


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


 

Message 5 of 10
CNinBC
in reply to: dlanorh

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.

Message 6 of 10
dlanorh
in reply to: CNinBC

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

Message 7 of 10
CNinBC
in reply to: dlanorh

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
Message 8 of 10
ВeekeeCZ
in reply to: CNinBC

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.

Message 9 of 10
CNinBC
in reply to: ВeekeeCZ

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.


 

Message 10 of 10
CNinBC
in reply to: ВeekeeCZ

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)
  )

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report