Lisp code to change the overall scale for all dimension objects and styles

Lisp code to change the overall scale for all dimension objects and styles

GeryKnee
Advocate Advocate
5,317 Views
14 Replies
Message 1 of 15

Lisp code to change the overall scale for all dimension objects and styles

GeryKnee
Advocate
Advocate

Hello,

I need a lisp code to globaly change the overall scale to a variable (interface) parameter value for all dimension objects and dimension styles of a drawing file.

Gery.

0 Likes
Accepted solutions (1)
5,318 Views
14 Replies
Replies (14)
Message 2 of 15

pbejse
Mentor
Mentor

@GeryKnee wrote:

Hello,

I need a lisp code to globaly change the overall scale to a variable (interface) parameter value for all dimension objects and dimension styles of a drawing file.

Gery.


Hows that again? are you referring to system variable DIMSCALE?

 

 

0 Likes
Message 3 of 15

GeryKnee
Advocate
Advocate

I'm afraid, not.

Suppose i have a dim object <<obj1>> that has the overall scale property value 100 amd a dim style <<ds1>> that has the overall scale property value 500.

By changing DIMSCALE global variable to any value doesn't change the overall scale property value of <<obj1>> and <<ds1>>.

What I need is after lisp code is running for example setting the interface parameter of 1000, i shall find that both <<obj1>> and <<ds1>> and every  dimension style and  every  dimension object will hold the value of 1000.

0 Likes
Message 4 of 15

GeryKnee
Advocate
Advocate

I'm afraid, not.

Suppose i have a dim object <<obj1>> that has the overall scale property value 100 amd a dim style <<ds1>> that has the overall scale property value 500.

By changing DIMSCALE global variable to any value doesn't change the overall scale property value of <<obj1>> and <<ds1>>.

What I need is after lisp code is running for example setting the interface parameter to 1000, i shall find that both <<obj1>> and <<ds1>> and every  dimension style and  every  dimension object will hold the value of 1000.

Is that possible?

0 Likes
Message 5 of 15

Kent1Cooper
Consultant
Consultant

@GeryKnee wrote:

....

Suppose i have a dim object <<obj1>> that has the overall scale property value 100 amd a dim style <<ds1>> that has the overall scale property value 500.

By changing DIMSCALE global variable to any value doesn't change the overall scale property value of <<obj1>> and <<ds1>>.

What I need is after lisp code is running for example setting the interface parameter to 1000, i shall find that both <<obj1>> and <<ds1>> and every  dimension style and  every  dimension object will hold the value of 1000.

Is that possible?


For all existing Dimension objects:

(setq dimsc (getreal "\nDimension overall scale factor: "))
(if (setq dss (ssget "_X" '((0 . "DIMENSION")))) (repeat (setq n (sslength dss)) (vla-put-ScaleFactor (vlax-ename->vla-object (ssname dss (setq n (1- n)))) dimsc) ) )

That gets them in Model Space & all Paper-Space Layouts.

 

I'll take a shot at the Style definitions  later if someone doesn't beat me to it -- a matter of stepping through the Dimension Style Table entries.

Kent Cooper, AIA
0 Likes
Message 6 of 15

GeryKnee
Advocate
Advocate

Yes,

The code is ok for objects.

Could you do something similar about the Height property of Text Objects?

(for any Text Object set obj.Height to a new property value)

I hope i will have answer about dimension styles of the document.

Thanks,

Gery

0 Likes
Message 7 of 15

Kent1Cooper
Consultant
Consultant

@GeryKnee wrote:

.... something similar about the Height property of Text Objects?

(for any Text Object set obj.Height to a new property value)

 

....
(setq txtht (getdist "\nUniversal Text height: "))
(if (setq tss (ssget "_X" '((0 . "TEXT"))))
  (repeat (setq n (sslength tss))
    (vla-put-Height (vlax-ename->vla-object (ssname tss (setq n (1- n)))) txtht)
  )
)

Same thing as with the Dimension scale factor, just a different entity type and VLA Property.  And I used (getdist) so you can specify it by picking two points on-screen, or enter it in various different length formats [such as fractions], if you choose.

Kent Cooper, AIA
0 Likes
Message 8 of 15

Kent1Cooper
Consultant
Consultant
Accepted solution

@Kent1Cooper wrote:

 

....

I'll take a shot at the Style definitions  later ... a matter of stepping through the Dimension Style Table entries.


Try this:

(defun C:DSU ; = Dimension Scale Universal
  (/ dimsc dsty dstydata dss n)
  (setq dimsc (getreal "\nDimension overall scale factor: "))
(while (setq dsty (tblnext "dimstyle" (not dsty))) (setq dstydata (entget (tblobjname "dimstyle" (cdr (assoc 2 dsty))))) (if (assoc 40 dstydata); [because not included in data if default 1.0] (entmod (subst (cons 40 dimsc) (assoc 40 dstydata) dstydata)); then -- replace it (entmod (append dstydata (list (cons 40 dimsc)))); else -- add it ) ) (if (setq dss (ssget "_X" '((0 . "DIMENSION")))) (repeat (setq n (sslength dss)) (vla-put-ScaleFactor (vlax-ename->vla-object (ssname dss (setq n (1- n)))) dimsc) ) ) (princ) )

Minimally tested, and without the usual enhancements yet.

Kent Cooper, AIA
Message 9 of 15

GeryKnee
Advocate
Advocate

Sorry, i've done a mistake, my interface variabale i need to be a numeric scale value SF rather than a Height value that will rearange the objects textheight values

example:

For variable SF=1.55

Text obj1 ::: Text Height now 3, after code is running sould be 1.55*3=4.65

Text obj2 ::: Text Height now 1, after code is running sould be 1.55*1=1.55

.....................

 I understand that needs the vla-get-Height before vla-put-Height but i can't change the syntax because my Lisp knowleedge is poor.

Thanks,

Gery

0 Likes
Message 10 of 15

GeryKnee
Advocate
Advocate

Sorry, i've done a mistake, my interface variabale i need to be a numeric scale value SF rather than a Height value that will rearange the objects textheight values

example:

For variable SF=1.55

Text obj1 ::: Text Height now 3, after code is running sould be 1.55*3=4.65

Text obj2 ::: Text Height now 1, after code is running sould be 1.55*1=1.55

.....................

 I understand that needs the vla-get-Height before vla-put-Height but i can't change the syntax because my Lisp knowleedge is poor.

Farther, objcts sould non be all the text objects of a document but those selected on prompt : select text objects ...

Thanks,

Gery

0 Likes
Message 11 of 15

Kent1Cooper
Consultant
Consultant

@GeryKnee wrote:

.... my interface variabale i need to be a numeric scale value SF rather than a Height value ....

Farther, objcts sould non be all the text objects of a document but those selected on prompt ....


For User selection instead of all Text objects, just remove the "_X" from the (ssget) function.  Here's a quickie asking for a scale factor on the height rather than an absolute height [minimally tested]:

(setq txtsc (getdist "\nText scaling factor: "))
(prompt "\nTo apply that to Text,")
(if (setq tss (ssget '((0 . "TEXT"))))
  (repeat (setq n (sslength tss))
    (vla-put-Height
      (setq txtobj (vlax-ename->vla-object (ssname tss (setq n (1- n)))))
      (* (vla-get-Height txtobj) txtsc)
    )
  )
)

 

Did the Dimensions routine work for you?

Kent Cooper, AIA
Message 12 of 15

GeryKnee
Advocate
Advocate

That's working as i wish, is perfect, exept of that :::

Suppose that the current (active) style is for examble "MyDimStyle".

After Code Runs, the MyDimStyle DimStyle will get the nwe Scale Factor, but 

there will be created a new inherited Dim Stype callad "MyDimStyle overrides", that will have the old value.

this is unusable,

Could not this happen?

Thanks,

Gery

0 Likes
Message 13 of 15

Kent1Cooper
Consultant
Consultant

@GeryKnee wrote:

....

there will be created a new inherited Dim Stype callad "MyDimStyle overrides", that will have the old value.

....


Setting a non-overridden Style to be current eliminates that [in minimal testing].  Add this line:

....
) (command "_.dimstyle" "_restore" "STANDARD") (princ) )
Kent Cooper, AIA
0 Likes
Message 14 of 15

GeryKnee
Advocate
Advocate

That works, but it sould be better if fisrst the active dim style is stored to a var, and after the lisp code runs the insertion stored stype sould be srstored

 

get active dim style and store as activeDS

set standard as active 

run lisp code

set activeDS as active 

Thanks,

Gery

 

0 Likes
Message 15 of 15

Kent1Cooper
Consultant
Consultant

@GeryKnee wrote:

.... 

get active dim style and store as activeDS

set standard as active 

run lisp code

set activeDS as active 

.... 


Give this a try [untested this time]:

(defun C:DSU ; = Dimension Scale Universal
  (/ dimst dimsc dsty dstydata dss n)
  (setq dimst (getvar 'dimstyle))
  (command "_.dimstyle" "_restore" "STANDARD")
  (setq dimsc (getreal "\nDimension overall scale factor: "))
  (while (setq dsty (tblnext "dimstyle" (not dsty)))
    (setq dstydata (entget (tblobjname "dimstyle" (cdr (assoc 2 dsty)))))
    (if (assoc 40 dstydata); [because not included in data if default 1.0]
      (entmod (subst (cons 40 dimsc) (assoc 40 dstydata) dstydata)); then -- replace it
      (entmod (append dstydata (list (cons 40 dimsc)))); else -- add it
    )
  )
  (if (setq dss (ssget "_X" '((0 . "DIMENSION"))))
    (repeat (setq n (sslength dss))
      (vla-put-ScaleFactor (vlax-ename->vla-object (ssname dss (setq n (1- n)))) dimsc)
    )
  )
  (command "_.dimstyle" "_restore" dimst)
  (princ)
)
Kent Cooper, AIA
0 Likes