Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Select all objects and scale their Linetype by a set factor

13 REPLIES 13
SOLVED
Reply
Message 1 of 14
Dpipke
1849 Views, 13 Replies

Select all objects and scale their Linetype by a set factor

Hi all,

I'm looking for a Lisp to select all objects in DWG and scale their lintype by 1/24.5 to move one set of DWG to our new standard. I found alisp that does it by percentage and modfied it to be a set value. Howerver since entsel only allows 1 selection. I tried using SSget "x" but I don't really know how to change it. (I also theoretically don't need a prompt since its a set scale factor but I wanted to copy my latest working version of the code below)

(defun c:lsr ()
(setq en (car (entsel))
ed (entget en)
lts (cdr (assoc 48 ed))
)
(if (/= lts nil)
(progn
(setq ns (getreal (strcat "\nScale linetype what percentage of it's current scale? Current scale: <"(rtos lts)">. Values greater than 100% will increase the scale:"))
ns2 (* (/ 1 25.4) lts)
)
(setq ed
(subst (cons 48 ns2)
(assoc 48 ed)
ed
)
)
(entmod ed)
(entupd en)
);progn
(progn
(setq ns (getreal (strcat "\nScale linetype to what percentage of it's current scale? Current scale: <"(rtos 1)">. Values greater than 100% will increase the scale:"))
ns2 (* (/ 1 25.4) 1)
)
(command "change" en "" "p" "s" (rtos ns2) "")
)
);if
)

13 REPLIES 13
Message 2 of 14
dbroad
in reply to: Dpipke

Aren't there better ways to accomplish the goal of good plots?  These variables should all be 1:  LTSCALE, MSLTSCALE, CELTSCALE, and PSLTSCALE.  All objects should have an ltscale of 1 except for small objects that the ltscale does not render on.

 

There are two sources for linetype definitions:  ACAD.LIN and ACADISO.LIN.  The ACAD.LIN linetypes are 24.5 times smaller than those found in ACADISO.LIN.  Are you using the appropriate LIN files?

Architect, Registered NC, VA, SC, & GA.
Message 3 of 14
Dpipke
in reply to: dbroad

I agree it's not ideal. It's a company issue thing. The company is changing all the base lintetype scales, however our specific client has their own standards that need to be used. The big issue is we used to have a global LTS of 25.4 to do this. but with the new standards coming in the global LTS is supposed to stay at 1. So we need to convert old drawings and I'm trying to find a way to save everyone from having to go in and manually change the scale in everyobject...

Edit: Further information all our linetypes are custom for the most part

Message 4 of 14
dbroad
in reply to: Dpipke

Sounds like you are moving in the right direction by changing LTSCALE from 24.5 to 1. Preferably, you also need to change all linetypes from the equivalent of 1/24.5 to 1.  To do so,

 

You could wrap this sequence into a function.  It should set all objects that have a linetype to have a linetypescale of 1.0

 

(vlax-for n (vla-get-blocks(vla-get-activedocument(vlax-get-acad-object)))
(vlax-for m n
(if (and
(vlax-property-available-p m 'linetype)
(< (setq lts (vla-get-linetypescale m)) 0.05) ;;smaller than 1/20
)
(vla-put-linetypescale m 1.0))))

 

It would obviously miss a few objects that should have a smaller ltscale (on purpose).  Alternatively, if you are sure that every object is 24.5 times too small in ltscale, then 

(vla-put-linetypescale m (* 24.5 lts)) could be substituted for (vla-put-linetypescale m 1.0)

Architect, Registered NC, VA, SC, & GA.
Message 5 of 14
Dpipke
in reply to: dbroad

Thanks that seems to work. Though I don't think I need the "if" routine. since we just want everything thing scaled. However When I try to remove it. it seems to break the code. How would I take that out? 

Message 6 of 14
dbroad
in reply to: Dpipke

(vlax-for n (vla-get-blocks(vla-get-activedocument(vlax-get-acad-object)))
(vlax-for m n
(if (vlax-property-available-p m 'linetype)
(vla-put-linetypescale m 1.0))))

Architect, Registered NC, VA, SC, & GA.
Message 7 of 14
Dpipke
in reply to: dbroad

Hey sorry for the thread necro, had a crazy busy time and didn't have a chance to continue on this code.

That code works for setting the LT scale to 1, however I need to set the lts scale of all objects o 25.4 times less than what they were. This worked in the code with the If(and statement above by subbing in the function. However I can seem to get it to work with this one. It seems to be because the "lts" variable used is not defined. I've tried to define it but I'm not sure what to put in to get it to work

Message 8 of 14
Kent1Cooper
in reply to: dbroad


@Anonymous wrote:

... changing LTSCALE from 24.5 to 1. Preferably, you also need to change all linetypes from the equivalent of 1/24.5 to 1.  .... 

... if you are sure that every object is 24.5 times too small in ltscale, then 

(vla-put-linetypescale m (* 24.5 lts)) could be substituted for (vla-put-linetypescale m 1.0)


[If this is a metric/imperial millimeters/inches swap situation, and you want it "accurate" [which may not be important], be sure to use 25.4 rather than 24.5.]

Kent Cooper, AIA
Message 9 of 14
Dpipke
in reply to: Kent1Cooper

Hi Kent

I did see the code there. I guess I should have been more clear. I'm trying to edit the latest piece of code in the thread:

"(vlax-for n (vla-get-blocks(vla-get-activedocument(vlax-get-acad-object)))
(vlax-for m n
(if (vlax-property-available-p m 'linetype)
(vla-put-linetypescale m 1.0))))"

and add in that function (vla-put-linetypescale m (* 25.4 lts)) in place of (vla-put-linetypescale m 1.0)

However without the if statement from the original code lts is undefined and causes errors, and I am unsure what I need to "setq" I tried adding this to the above code "(setq lts (vla-get-linetypescale m))" however adding that line causes the routine to run but not change the LT scales

Message 10 of 14
Kent1Cooper
in reply to: Dpipke


@Dpipke wrote:

...I don't think I need the "if" routine. since we just want everything thing scaled. ... 


I suspected that it should be in there, because using (vla-putlinetypescale) on something that doesn't have the LinetypeScale VLA Property would cause an error.  [I think if you did it by way of a CHPROP command, it wouldn't matter, but it does in (vla) methods.]  But I looked at a few things for which linetype and linetype scale certainly are irrelevant [Text, Mtext, 3D Solids], and to my surprise, they all have both Linetype and LinetypeScale properties, anyway.  If all entity types have those, however irrelevant they may be to some types, then the check wouldn't be needed, but I'm not sure that's the case.  Doug, do you know of types that don't have them?  [I didn't check every type.]

Kent Cooper, AIA
Message 11 of 14
dbroad
in reply to: Kent1Cooper

Kent,

In general, its a good rule to check for the availability of a property before assuming that it can be set.  I am not sure that this is necessary in this case but prefer that method to the vl-catch-all-apply method which ignores the errrors that might occur.

 

This might work but is not guaranteed.

 

(vlax-for n (vla-get-blocks
(vla-get-activedocument (vlax-get-acad-object)))
(vlax-for m n
(vla-put-linetypescale m (/ (vla-get-linetypescale m) 25.4))))

Architect, Registered NC, VA, SC, & GA.
Message 12 of 14
cwake_
in reply to: Dpipke

Dpipke,

You have some good people helping you with this, and I can't think of anything that the lisp you have will miss, but I have to ask...  (as Doug did earlier) Do you really have to do this?

You said...


"with the new standards coming in the global LTS is supposed to stay at 1."

I'm assuming that everything hinges on that one point. That and the potential problem of having older and newer drawings within a project sharing xref's. But I also assume that having new standards includes the updating of your linestyle definition files to reflect the new scales?

 

Can't you just reload the linestyle defintions from the new linestyle definition file, change the gtlobal ltscale to 1, and leave all of the entity linetypescales as they are? That would not only be simpler, but it would ensure that no entities get missed.


Clint
Message 13 of 14
Dpipke
in reply to: dbroad

Thanks that code worked great. My google has failed me though what is the significance of the "m" and "n" (this is more my curiosity) are they just variables you chose or does "m" and "n" signify something specific?

cwake: we are sitting in a weird interim period where they want us to change the global scale but we don't have the new linstyles yet... It's odd and hopefully I will only need this code for a few months while they get caught up.

Message 14 of 14
dbroad
in reply to: Dpipke

You're welcome.  Glad it worked for you.  M and N are just temporary loop placeholders in a nested loop.  Essentially the code says that for every entity M in every block N, change the ltscale property. 

Architect, Registered NC, VA, SC, & GA.

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

Post to forums  

Autodesk Design & Make Report

”Boost