Community
AutoCAD Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Using expression to add amount to a linear dimension?

8 REPLIES 8
Reply
Message 1 of 9
Anonymous
1047 Views, 8 Replies

Using expression to add amount to a linear dimension?

Have several dimensions on a drawing and want to quickly add a set amount, say 50mm to every dimension. Been playing around with expressions and can't seem to find a way to do this. Anyone got any idea or will I just have to keep adding 50mm on myself and type that into text edit...

Regards
8 REPLIES 8
Message 2 of 9
Kent1Cooper
in reply to: Anonymous


@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.

Kent Cooper, AIA
Message 3 of 9
Anonymous
in reply to: Anonymous

Thanks Kent, shall test this out tomorrow. The reason for using it is; the company I work for does steel decking layouts. When the deck is on an angle it has to be cut on-site so we allow an extra 50mm for the cut.

Would you say using an expression like this would be the simplest way to do this?

Cheers
Message 4 of 9
Kent1Cooper
in reply to: Anonymous


@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

Kent Cooper, AIA
Message 5 of 9
Kent1Cooper
in reply to: Anonymous

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

Kent Cooper, AIA
Message 6 of 9
Anonymous
in reply to: Anonymous

Kent, been playing around with it today but to no joy. Trying to follow some online guides but it's not working out too well. Any guide you could recommend, or process?

Regards
Message 7 of 9
Kent1Cooper
in reply to: Anonymous


@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?

Kent Cooper, AIA
Message 8 of 9
Anonymous
in reply to: Anonymous

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.
Message 9 of 9
Kent1Cooper
in reply to: Anonymous


@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

Kent Cooper, AIA

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

Post to forums  

Forma Design Contest


AutoCAD Beta