LISP solution for Dimension Conversion problem

LISP solution for Dimension Conversion problem

Anonymous
Not applicable
2,101 Views
4 Replies
Message 1 of 5

LISP solution for Dimension Conversion problem

Anonymous
Not applicable

I've been trying to build a LISP routine that combines the concepts I found in these 2 posts:

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-to-change-color-of-dimensions-w...

https://forums.autodesk.com/t5/autocad-2013-2014-2015-2016-2017/how-to-convert-aligned-dimension-to-...

 

What I would like, is to convert an aligned dimension to a linear dimension, which the *.lsp referenced in the latter does accomplish, but it also eliminates information in the Text override attribute of the object.  Here is my current butchered version of that *.lsp:

 

(defun c:ChangeDimObject (/ ss Ent EntData Pt1 Pt2 Pt3 ocmd omode olay odim)
; Redraw dimension that were drawn as aligned as rotated on correct layer, and with correct dimension style.

(defun dtr (deg) (* (/ deg 180.0) pi))
(setq ocmd (getvar "cmdecho"))
(setvar "cmdecho" 0)
(command "_.undo" "_end")
(command "_.undo" "_begin")
(setq omode (getvar "osmode"))
(setvar "osmode" 0)
(setq olay (getvar "clayer"))
(setq odim (getvar "dimstyle"))
(setq dom (ssget '((1. "*<>*")))
(if (setq ss (ssget '((0 . "DIMENSION"))))
(while (setq Ent (ssname ss 0))
(setq EntData (entget Ent))
(if (not (member '(100 . "AcDbRotatedDimension") EntData))
(progn
(setq Pt1 (cdr (assoc 13 EntData)))
(setq Pt2 (cdr (assoc 14 EntData)))
(setq Pt3 (cdr (assoc 11 EntData)))
(if (< (car Pt1) (car Pt2))
(command "_.ucs" "_3" Pt1 Pt2 (polar Pt1 (+ (/ pi 2) (angle Pt1 Pt2)) 5))
(command "_.ucs" "_3" Pt2 Pt1 (polar Pt2 (+ (/ pi 2) (angle Pt2 Pt1)) 5))
)
(setvar "clayer" (cdr (assoc 8 EntData)))
(command "_.dimstyle" "_r" (cdr (assoc 3 EntData)))
(entdel Ent)
(command "_.dim" "_horizontal" (trans Pt1 0 1) (trans Pt2 0 1) (trans Pt3 0 1) "dom" "_exit")
(command "_.ucs" "_p")
)
)
(ssdel Ent ss)
)
)
(command "_.dimstyle" "_r" odim)
(command "_.undo" "_end")
(setvar "clayer" olay)
(setvar "osmode" omode)
(setvar "cmdecho" ocmd)
(command "ddeit" dom)
(princ)
)

 

I am really grabbing at straws on my own; I greatly appreciate any help.

 

Thanks,

Dan

0 Likes
Accepted solutions (1)
2,102 Views
4 Replies
Replies (4)
Message 2 of 5

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

....
(setq dom (ssget '((1. "*<>*")))
....
(command "_.dim" "_horizontal" (trans Pt1 0 1) (trans Pt2 0 1) (trans Pt3 0 1) "dom" "_exit")
....


Without digging too deeply, I notice a couple of things.

 

In the first line quoted above, there should be a space between the 1 and the period.  And be aware that this will find Dimensions whose override text includes the measured distance, but will not find any with fully-overridden text content.

 

In the second line, I think you need to specify the Text option before giving it the replacement text, and before the third point.  And "dom" is certainly not going to be the text content you want, and without the quotation marks is a selection set, not a text string.  Try something like this:

 

(command "_.dim" "_horizontal" (trans Pt1 0 1) (trans Pt2 0 1)

  "_text" (cdr (assoc 1 EntData))

  (trans Pt3 0 1) "_exit"

)

 

BUT look at the Dimension sequence doing it manually -- it varies with the version of AutoCAD you're using [the above doesn't work in 2017, for instance], and you may want Dimlinear, or Dimhorizontal, or something, and using those, probably don't need the "exit" at the end.

Kent Cooper, AIA
Message 3 of 5

Anonymous
Not applicable

You got me where I needed to go! Thank you!

 

I did need the full overrides and had to delete the first line without proper syntax for the second "ssget" anyway.

 

Also, changed the command to "_dimlinear" placed the "_text" generation where the manual process was asking for it, and it works!

 

If you don't mind, what was it about (setq dom (ssget '(( 1 . "*<>*"))) that found only the overrides that build upon the measurement rather than the full overrides? Would this be any and all overrides: '(( 1 . "*"))?  

 

Also, what was I missing that would allow me to define 2 variables w/ ssget?

 

My eye for lisp just isn't there, yet.

 

Thanks again,

Dan

0 Likes
Message 4 of 5

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

... what was it about (setq dom (ssget '(( 1 . "*<>*"))) that found only the overrides that build upon the measurement rather than the full overrides? Would this be any and all overrides: '(( 1 . "*"))?  

 

Also, what was I missing that would allow me to define 2 variables w/ ssget?

....


The <> part represents the measured distance [or angle for angular Dimensions].  Any Dimension with text override that includes the measured distance will have that in its text content [as stored in entity data -- it doesn't appear that <> way in the drawing].  The text-content 1-code entry contains nothing at all [an empty string, ""] if there is no override but only the measured distance -- it doesn't contain "<>".

 

The asterisk wildcard stands for anything or nothing, which is why "*<>*" finds things containing the measured distance whether there's anything before or after or both, but doesn't require both.  So if you use ( 1 . "*") it will also find Dimensions without any override [that is, with nothing in that string].  You would want to look for at least one character, of any variety, which you can do with (1 . "*?*").

 

If I understand your last question quoted above correctly, you can put more than one characteristic to filter for into a single (ssget) filter list [that's why it's referred to as the filter list ]:

 

(if (setq ss (ssget '((0 . "DIMENSION") (1 . "*?*"))))

Kent Cooper, AIA
Message 5 of 5

Anonymous
Not applicable

You have been a great help.

 

Thanks again,

Dan

0 Likes