Jump to content

selec dims and change linear dim scale


daisenson

Recommended Posts

Hi there,

 

I'm looking for a way to select all the dimensions in the drawing (model space) and change the linear dimension scale (usually from 50 or 100 to 1).

Any ideas of how to do this via lisp?

 

thanks

Link to comment
Share on other sites

Perhaps the LinearScaleFactor property?

 

(defun c:DimUpd ( / *error* _StartUndo _EndUndo doc ss )
 (vl-load-com)
 ;; © Lee Mac 2010

 (defun *error* ( msg )
   (and doc (_EndUndo doc))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ)
 )

 (defun _StartUndo ( doc ) (_EndUndo doc)
   (vla-StartUndoMark doc)
 )

 (defun _EndUndo ( doc )
   (if (= 8 (logand 8 (getvar 'UNDOCTL)))
     (vla-EndUndoMark doc)
   )
 )

 (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))

 (if (ssget "_X" '((0 . "*DIMENSION")))
   (progn
     (setq *scl*
       (cond
         (
           (getdist
             (strcat "\nSpecify Linear Scale Factor <"
               (rtos
                 (setq *scl* (cond ( *scl* ) ( 1.0 )))
               )
               "> : "
             )
           )
         )
         ( *scl* )
       )
     )          
     
     (_StartUndo doc)
     
     (vlax-for o (setq ss (vla-get-ActiveSelectionSet doc))
       (if (vlax-property-available-p o 'LinearScaleFactor)
         (vla-put-LinearScaleFactor o *scl*)
       )
     )

     (vla-delete ss)

     (_EndUndo doc)
   )
 )

 (princ)
)
           

Link to comment
Share on other sites

Thanks very much Lee Mac,

 

It really works. Now I'm having a second problem:

Im exporting the layout from paper space (scale 1:1) to model and then having to scale the whole drawing to the real scale (1:50). All the dimensions have the linear scale factor to 50 and the dim scale overall to 1. So when I scale the drawing I need to swap those values, I need the linear dim scale to be 1 and the dim scale overall to be 50. Is there a way of doing this?

 

Thanks again

Link to comment
Share on other sites

As a quick mod:

 

(defun c:DimUpd ( / *error* _StartUndo _EndUndo doc ss )
 (vl-load-com)
 ;; © Lee Mac 2010

 (defun *error* ( msg )
   (and doc (_EndUndo doc))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ)
 )

 (defun _StartUndo ( doc ) (_EndUndo doc)
   (vla-StartUndoMark doc)
 )

 (defun _EndUndo ( doc )
   (if (= 8 (logand 8 (getvar 'UNDOCTL)))
     (vla-EndUndoMark doc)
   )
 )

 (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))

 (if (ssget "_X" '((0 . "*DIMENSION")))
   (progn
     (setq *scl*
       (cond
         (
           (getdist
             (strcat "\nSpecify Linear Scale Factor <"
               (rtos
                 (setq *scl* (cond ( *scl* ) ( 1.0 )))
               )
               "> : "
             )
           )
         )
         ( *scl* )
       )
     )
     (setq *oscl*
       (cond
         (
           (getdist
             (strcat "\nSpecify Overall Scale Factor <"
               (rtos
                 (setq *oscl* (cond ( *oscl* ) ( 1.0 )))
               )
               "> : "
             )
           )
         )
         ( *oscl* )
       )
     )
     
     (_StartUndo doc)
     
     (vlax-for o (setq ss (vla-get-ActiveSelectionSet doc))
       (mapcar
         (function
           (lambda ( prop value )
             (if (vlax-property-available-p o prop)
               (vlax-put-property o prop value)
             )
           )
         )
         '(LinearScaleFactor ScaleFactor) (list *scl* *oscl*)
       )
     )

     (vla-delete ss)

     (_EndUndo doc)
   )
 )

 (princ)
)

Link to comment
Share on other sites

Thanks Lee,

I'm just thinking that since this has to be run through hundreds of dwg's with scriptpro, it would be optimal for the script to detect these 2 values (all the dims in each drawing share the same values for linear scale and dim e overal), store these two values and swop them. This way you wouldn't have to enter these 2 values

 

Thanks once again

Link to comment
Share on other sites

Try this

 

(defun c:DimUpd ( / *error* _StartUndo _EndUndo _SwapProps doc ss )
 (vl-load-com)
 ;; © Lee Mac 2010

 (defun *error* ( msg )
   (and doc (_EndUndo doc))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ)
 )

 (defun _StartUndo ( doc ) (_EndUndo doc)
   (vla-StartUndoMark doc)
 )

 (defun _EndUndo ( doc )
   (if (= 8 (logand 8 (getvar 'UNDOCTL)))
     (vla-EndUndoMark doc)
   )
 )

 (defun _SwapProps ( obj prop1 prop2 / tmp )
   (if (and (vlax-property-available-p obj prop1 t)
            (vlax-property-available-p obj prop2 t)
       )
     (progn (setq tmp (vlax-get-property obj prop1))
       (vlax-put-property obj prop1 (vlax-get-property obj prop2))
       (vlax-put-property obj prop2 tmp)
     )
   )
 )

 (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))

 (if (ssget "_X" '((0 . "*DIMENSION")))
   (progn      
     (_StartUndo doc)
     
     (vlax-for o (setq ss (vla-get-ActiveSelectionSet doc))
       (_SwapProps o 'LinearScaleFactor 'ScaleFactor)
     )

     (vla-delete ss)

     (_EndUndo doc)
   )
 )

 (princ)
)

Edited by Lee Mac
Link to comment
Share on other sites

Hi Lee,

 

I've tried the code and it is detecting the value for dim scale linear and applying it to dim scale overall, but it is not swaping those values: dim scale linear is staying the same and not changing.

 

Initial situation (values may change in each drawing):

dim scale overall:1

dim scale linear:50

 

After script should be:

dim scale overall:50

dim scale linear:1

 

Any way of solving this?

Is it also possible to scale the whole drawing by the value of dim scale overall?

 

Thanks in advance

Link to comment
Share on other sites

Thanks Lee, works a treat now!

 

Will try to figure out how to get the overall scale value into a variable and scale the whole drawing by this factor.

Link to comment
Share on other sites

Hi Lee,

 

I draw using modelspace and viewports on paper space (nothing new here).

But I need to deliver drawings with all their contents on model space, so I'm using exportlayout to do this.

The resulting drawings display the dimensions in with the following:

 

1. dim scale linear: as per the scale of the original viewport

2. dim scale overall: 1, as the resulting drawing is 1:1 scale

 

3. The text style used on the dimensions was "ISOCOP 2.5mm" with a text height of 2.5, but after the exportlayout it becomes 0, and all the dims change size.

 

Your lisp deals with 1 & 2. The overall value of text height in this style should be 2.5 x dimscale linear value. Is there a way to do this and then scale the whole drawing by this value?

 

 

Big thanks

Link to comment
Share on other sites

  • 1 year later...

I hate to resurect an old thread, but i have run into a hiccup. Great routine by the way. It works great! well, it did... I modified a portion of it to scale the dimensions based on a distance provided by the length of a line. It worked great, then all of a sudden it stopped working. I enter the command nothing happens, no error messages or anything...

Is there something wrong with this code?

 

 
(DEFUN C:DSC (/ VP DS TXT *error* doc ss)
   (vl-load-com)
    ;; © Lee Mac 2010
 (defun *error* ( msg )
   (and doc (_EndUndo doc))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ)
 )
 (defun _StartUndo ( doc ) (_EndUndo doc)
   (vla-StartUndoMark doc)
 )
 (defun _EndUndo ( doc )
   (if (= 8 (logand 8 (getvar 'UNDOCTL)))
     (vla-EndUndoMark doc)
   )
 )
 (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
 (if (ssget "_X" '((0 . "*DIMENSION")))
   (progn
  (SETQ VP (GETDIST "\nGet length of top edge of title block:"))
 (SETVAR "CMDECHO" 0)
 (SETQ TXT (* 0.0085 VP))
 (SETQ DS ( / TXT 0.25))
     (_StartUndo doc)
     
     (vlax-for o (setq ss (vla-get-ActiveSelectionSet doc))
       (mapcar
         (function
           (lambda ( prop value )
             (if (vlax-property-available-p o prop)
               (vlax-put-property o prop value)
             )
           )
         )
         '(LinearScaleFactor ScaleFactor) (list *scl* DS)
       )
     )
     (vla-delete ss)
     (_EndUndo doc)
  (command "dimscale" DS)
   )(princ)
 ))

Link to comment
Share on other sites

JPlanera,

 

You removed the prompt for the Linear Scale Factor, hence the variable *scl* is no longer defined in the code; I assume you want the Linear Scale Factor to be the same as the overall Scale Factor property for the Dimensions?

 

(defun c:DimUpd ( / *error* _StartUndo _EndUndo acdoc acsel vp ds )

   (defun *error* ( msg )
       (if acdoc (_EndUndo acdoc))
       (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
           (princ (strcat "\nError: " msg))
       )
       (princ)
   )

   (defun _StartUndo ( doc )
       (_EndUndo doc)
       (vla-StartUndoMark doc)
   )

   (defun _EndUndo ( doc )
       (if (= 8 (logand 8 (getvar 'UNDOCTL)))
           (vla-EndUndoMark doc)
       )
   )

   (setq acdoc (vla-get-ActiveDocument (vlax-get-acad-object)))
   (if
       (and
           (ssget "_X" '((0 . "*DIMENSION")))
           (progn
               (initget 2)
               (setq vp (getdist "\nGet length of top edge of title block:"))
           )
       )
       (progn
           (setq ds (* 0.034 VP))
           (_StartUndo acdoc)
           (vlax-for obj (setq acsel (vla-get-ActiveSelectionSet acdoc))
               (foreach prop '(LinearScaleFactor ScaleFactor)
                   (if (vlax-property-available-p obj prop t)
                       (vlax-put-property obj prop ds)
                   )
               )
           )
           (vla-delete acsel)
           (setvar 'DIMSCALE ds)
           (_EndUndo acdoc)
       )
   )
   (princ)
)
(vl-load-com)

Link to comment
Share on other sites

Yes, after messing with it a bit more, I caught that. Thank you for the response. As always, your code is a lot cleaner than mine! haha Keep up the good work, Lee!!

Link to comment
Share on other sites

  • 2 years later...

This is great Lee Mac! Would you mind modifying it so that is scales the whole drawing (using basepoint 0,0) at the scale referenced from the originating layout. I'm thinking it's the ScaleFactor in your code.

 

 

Thanks in advance!

Link to comment
Share on other sites

  • 2 weeks later...
  • 7 years later...

Resurecting a topic...

Does anyone know how to write a simmilar routine... it is quite simmilar:

 

I have made a routine that does a lot of things, it deletes all dimensions and dashed lines and asks for point input inside of a contour and copies the value of the area inside the boundary to the clipboard. Before doing that it flattens the drawing etc. It is somewhat long.

Now I need to run this routine, but stop the routine if the draiwing units are not millimeters and give an alert "Command is dismissed, drawing units are not in mm.", and also if any of the dimensions in the whole drawing have dim linear scale not equal to 1, to give an alert saying "Some dimensions are not in 1:1 scale. These dimensions will be selected." and select those dimensions. If the drawing units are mm, and all dimensions have dim scale linear equal to 1, then run the routine.

Help would be much appreciated.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...