I'm having a problem with a callback error on a lisp i'm trying to piece together. I would like to get the dimscale of a drawing and then apply it to an attribute when a client border is inserted. I have a lisp that will change the attribute to what I want, and I have the code to get the DIMSCALE, but I can't seem to get them to work together.
Initially, when I type (getvar "dimscale") it will return the dimscale. i.e. 1.0, 24.0, 48.0 I would like for it to only show the number and not the ".0" portion of it. This may not be possible, I am not certain. This code is probably garbage, but if anyone has any tips on getting this achieved it would be appreciated. I had initially thought to setq a as the dimscale, and then try to aply that to the -attedit command, but had no luck. It now just says DIMSCALE where I want the number to go.
(defun C:iddim ( / a )
(vl-load-com)
(setq a (substr (getvar "dimscale")1 2))
(command "-attedit" "y" "*" "TITLESCALE" "" "-999999,-999999" "999999,999999" "" "v" "r" "DIMSCALE" "")
(princ)
)
Solved! Go to Solution.
Solved by Jason.Piercey. Go to Solution.
@CSM_MAI wrote:
Initially, when I type (getvar "dimscale") it will return the dimscale. i.e. 1.0, 24.0, 48.0 I would like for it to only show the number and not the ".0" portion of it. This may not be possible, I am not certain.
One way to drop the decimal point
(rtos (getvar "dimscale") 4 0)
How about using a field? For example:
(defun c:iddim ( / i s ) (if (setq s (ssget "_X" '((0 . "INSERT") (66 . 1)))) (repeat (setq i (sslength s)) (foreach a (vlax-invoke (vlax-ename->vla-object (ssname s (setq i (1- i)))) 'getattributes) (if (= "TITLESCALE" (strcase (vla-get-tagstring a))) (vla-put-textstring a "%<\\AcVar dimscale \\f \"%lu2%pr0\">%") ) ) ) ) (princ) ) (vl-load-com) (princ)
You may need to regen the drawing to update the field.
I had thought about using fields, but the client is pretty adamant about not adding items such as fields to their borders. They have programs that end up extracting the data from the title block once submitted to them and potential conflicts could arise from that, (so they say).
OK, in that case, in my code change:
(vla-put-textstring a "%<\\AcVar dimscale \\f \"%lu2%pr0\">%")
To:
(vla-put-textstring a (rtos (getvar 'dimscale) 2 0))
Thanks, for the ratios helped out. I changed the 4 to a 2 for decimal units, and it change the attribute when the command was activated.
(defun C:iddim ( / a )
(vl-load-com)
(setq a (rtos (getvar "dimscale") 2 0))
(command "-attedit" "y" "*" "TITLESCALE" "" "-999999,-999999" "999999,999999" "" "v" "r" a "")
(princ)
)