@Anonymous wrote:
....want to quickly add a set amount, say 50mm to every dimension. ....
I confess to being really curious as to why someone would want to do that -- seems kind of dangerous -- but....
Lightly tested, for that specific value, and assuming millimeters are the drawing unit:
(defun C:Plus50 (/ dimss n dimdata)
; = override linear Dimension content with measured length Plus 50 drawing units
(if (setq dimss (ssget ":L" '((0 . "DIMENSION"))))
(repeat (setq n (sslength dimss))
(setq dimdata (entget (ssname dimss (setq n (1- n)))))
(if (wcmatch (substr (cdr (assoc 100 (reverse dimdata))) 5 5) "Align,Rotat")
; linear types only [not Angular, Ordinate, Radius, Diameter, etc.]<--- allow Ordinate/Radius/Diameter?
(entmod ; override
(subst
(cons 1 (rtos (+ (cdr (assoc 42 dimdata)) 50))); new text override
(assoc 1 dimdata); original text content ["" if default]
dimdata
); subst
); entmod
); if
); repeat
); if
); defun
It could be made more generic, to ask the User for the amount they want to add, rather than having that built in, but first see whether it works.
@Anonymous wrote:
....
Would you say using an expression like this would be the simplest way to do this?
....
Yes, something like it. You can't do it via something like the Properties box or Text Editor except individually, and for that you'd need to calculate your own override text for each one. You can't have the default text content changed accordingly except by actually stretching all of them out by that amount, although the argument can certainly be made that that's just what you should do -- show the sheet at its actual size with the overage -- then you wouldn't need something like this. Another advantage of that approach is that if you need to change the sizes of things [column spacings, etc.], and you do that by Stretching, the text content of these Dimensions will update accordingly, which it will not if overridden with something like the Plus50 routine.
I say "something like" it, because there is almost always more than one way to accomplish just about anything. In this case, it can be done with slightly less code using VLA methods:
(vl-load-com); if needed
(defun C:Plus50 (/ dimss n dimobj)
; = override linear Dimension content with measured length Plus 50 drawing units
(if (setq dimss (ssget ":L" '((0 . "DIMENSION"))))
(repeat (setq n (sslength dimss))
(setq dimobj (vlax-ename->vla-object (ssname dimss (setq n (1- n)))))
(if (wcmatch (substr (vla-get-ObjectName dimobj) 5 5) "Align,Rotat")
; linear types [not Angular, Ordinate, Radius, Diameter, etc.]<--- allow some of those?
(vla-put-TextOverride
dimobj
(rtos (+ (vla-get-Measurement dimobj) 50)); new text override
); vla-put-...
); if
); repeat
); if
); defun
.... Another advantage of that approach is that if you need to change the sizes of things [column spacings, etc.], and you do that by Stretching, the text content of these Dimensions will update accordingly, which it will not if overridden with something like the Plus50 routine.
Apropos of the issue of actual vs. overage size, if there's room within your Dimensions for longer text content, try this approach:
(defun C:Plus50 (/ dimss n dimobj)
; = override linear Dimension content with measured length Plus 50 drawing units
(if (setq dimss (ssget ":L" '((0 . "DIMENSION"))))
(repeat (setq n (sslength dimss))
(setq dimobj (vlax-ename->vla-object (ssname dimss (setq n (1- n)))))
(if (wcmatch (substr (vla-get-ObjectName dimobj) 5 5) "Align,Rotat")
; linear types [not Angular, Ordinate, Radius, Diameter, etc.]<--- allow some of those?
(vla-put-TextOverride
dimobj
(strcat ; new text override
"<> [+ trim allowance = " ; <> = actual measurement
(rtos (+ (vla-get-Measurement dimobj) 50))
"]"
); strcat
); vla-put-...
); if
); repeat
); if
); defun
That would at least update the "real" Dimension if Stretched, though to also update the trim-allowance dimension you'd still need to run the routine again.
@Anonymous wrote:
Kent, been playing around with it today but to no joy. ....
In case it has anything to do with the occasional quirks of copying and pasting code causing problems, try loading the .lsp file in the attached .zip file. The Plus50 command just adds 50 drawing units to the text content, and the Plus50alt command shows the actual measurement with the bracketed trim allowance suffix.
If those don't work, can you be more specific about what "no joy" means? What happens that you don't expect? What doesn't happen that you do expect? Are there any messages?
@Anonymous wrote:
Works perfectly with the lisp file, however where would I edit in the script to round it up to the nearest whole number. For example I have a measurement of 6088.0388, when using the command it becomes 6138.0388. I want it to become 6138/6139.
To round it to the nearest whole number [up or down as appropriate], you can change this [in both routines]:
(rtos (+ (vla-get-Measurement dimobj) 50)); new text override
to this:
(itoa (fix (+ (vla-get-Measurement dimobj) 50.5))); new text override
EDIT: or, come to think of it:
(rtos (+ (vla-get-Measurement dimobj) 50) 2 0); new text override
If you want to always round upward only, this is one way:
(itoa
(fix
(+
(vla-get-Measurement dimobj)
(if (= (rem (vla-get-Measurement dimobj) 1.0) 0.0) 50 51); round up any except whole value
); +
); fix
); itoa
Can't find what you're looking for? Ask the community or share your knowledge.