Jump to content
cdavis

How can I scale multiple objects from each objects center?

Recommended Posts

I want to scale 40 objects to be larger, but they scale from the average center of the entire group and this moves them out from their average center. I want each object to scale from its own center and stay in the same position. Is this possible?

Share this post


Link to post

And here is a script that will do this. Copy the the lines from Procedure to Run and paste them into a new VectorScript Editor window.

{==============================}

Procedure ScaleEachObject;

{Scales each selected object in the active layer around the obejct center}

{? 2007, Coviana, Inc - Pat Stanford pat@coviana.com}

{Licensed unde the GNU Lesser General Public License}

Var H1,H2:Handle;

N1,N2:Integer;

A1:Dynarray[ ] of handle;

R1:Real;

Begin

N1:=Count(Sel);

If N1>0 then

Begin

Allocate A1[1..N1];

N2:=1;

While N2<=N1 do

Begin

A1[N2]:=FSActLayer;

SetDSelect(FSActLayer);

N2:=N2+1;

End;

R1:=RealDialog('Enter the amount to scale each object by','2.0');

N2:=1;

While N2<=N1 do

Begin

SetSelect(A1[N2]);

Scale(R1,R1);

DSelectAll;

N2:=N2+1;

End;

End

else AlrtDialog('At least one object must be selected');

End;

Run(ScaleEachObject);

{===================================}

Pat

Share this post


Link to post

Procedure ScaleEachObject;

{Scales each selected object in the active layer around the obejct center}

Pat, this looks useful. How about adding it to the new sharing forums so that it doesn't get lost.

{? 2007, Coviana, Inc - Pat Stanford pat@coviana.com}

{Licensed unde the GNU Lesser General Public License}

This might be a useful compromise rather than relinquishing copyright for your hard work when sharing resources.

Share this post


Link to post

Thanks Mr. Stanford

This is really generous of you. This is a helpfull tool. Thanks for sharing.

Share this post


Link to post

Holy Cow!

This is great. Thanks for this tool. And I even learned a ton just through the creation of this tool on my computer!

Thanks again.

Share this post


Link to post

Here is a revised version that fixes a bug I either missed or that was introduced in a later version of VW. Tested on VW2011.

The bug was when only groups were selected the script would incorrectly say not objects were selected and set stuck at the error message.

Procedure ScaleEachObject;
{Scales each selected object in the active layer around the obejct center}
{? 2007, 2010, Coviana, Inc - Pat Stanford pat@coviana.com}
{Licensed unde the GNU Lesser General Public License}

Var	H1,H2:Handle;
N1,N2:Integer;
A1:Dynarray[ ] of handle;
R1:Real;
Begin
N1:=Count(Sel);
If N1>0 then
Begin
	Allocate A1[1..N1];
	N2:=1;
	While N2<=N1 do
		Begin
			A1[N2]:=FSActLayer;
			SetDSelect(FSActLayer);
			N2:=N2+1;
		End;

	R1:=RealDialog('Enter the amount to scale each object by','2.0');

	N2:=1;
	While N2<=N1 do
		Begin
			SetSelect(A1[N2]);
			Scale(R1,R1);
			DSelectAll;
			N2:=N2+1;
		End;
End
else 
Begin
	N1:=0;
	AlrtDialog('At least one object must be selected');
End;
End;

Run(ScaleEachObject);

Share this post


Link to post

I just found this script, thank you very much

Share this post


Link to post

Just upgraded from 2009 to 2016, and can't seem to get this script to work anymore. Does anyone know if there is now a way to do this in the more recent vwx releases?

P.S. Thanks to Pat, as I was using this in the past and saved me a lot of time!

Share this post


Link to post

Works for me on 2016. Are you using the newer version of the script?

Share this post


Link to post

Works lovely,

Just go resource browser and create new script, past in and voula.

Select a few objects and double click on the script and you get a scale option up.

Share this post


Link to post

User error.

Looks to be working now. Must have missed a line somewhere at the end. You guys are great. Pat your the man!

Edited by HEengineering

Share this post


Link to post

Thanks for your replies - I'm still having problems with the script.

I can now seem to get it to scale, but only after a huge number of error boxes of 'no objects selected'. I've recorded a short video showing my process, perhaps I'm going wrong somewhere?

Screen Recording Link -

If anyone has any advice I'd be greatful as its a very useful tool!

Thanks

Share this post


Link to post

Here's my attempt using Python. (attached txt file version of script)

My vectorscript is very rusty.

** YOU NEED TO MAKE SURE YOU SET YOUR SCRIPTING LANGUAGE TO PYTHON (IN THE SCRIPT EDITOR)**

# DISCLAIMER
# - Python Novice
#  - Script presented as is
#  - save your work before using
# - use at your own risk
# - no responsibilty taken for damage to your property from the use of this script
# - copyright twk 2016
# - forum link = https://forum.vectorworks.net/index.php?/topic/19675-how-can-i-scale-multiple-objects-from-each-objects-center/
# - Tested on Windows 10 x64, Vectorworks 2016 SP4

def List_SelectedObjs_in_Layer(): # small function to store all selected objects on the current layer into a usable list (python list)
	h_FirstInContainer = vs.FIn3D(vs.ActLayer())
	listObjs_inContainer = []
	while (h_FirstInContainer != None):
		if vs.Selected(h_FirstInContainer):
			listObjs_inContainer.append(h_FirstInContainer)
		h_FirstInContainer = vs.NextObj(h_FirstInContainer)

	return listObjs_inContainer

list_selObjs = List_SelectedObjs_in_Layer() # function called, selected objects stored
countIt = len(list_selObjs) # number of selected objs store in countIt variable

if countIt > 0: # checking to make sure at least 1 or more objects are selected
	scaleAmount = vs.RealDialog("Enter Scale Amount", "1.5")
	if not vs.DidCancel(): # checking to make sure predefined Dialog's OK button was pressed
		for eachObj in list_selObjs:
			center = vs.HCenter(eachObj) # getting center of obj to be used in next function
			vs.HScale2D(eachObj,center[0],center[1],scaleAmount, scaleAmount, True)
		vs.ReDrawAll() # redraw-ing the screen as is needed after running HScale2D
		vs.AlrtDialog("{} Objs scaled".format(countIt)) #indicates the number of objects scaled
else:
	vs.AlrtDialog("At least 1 object must be selected") # checking to make sure at least 1 or more objects are selected

 

vs_scaleEachObj.txt

Edited by twk
  • Like 1

Share this post


Link to post

twk - Thanks, just used the python version of the script you posted, appears to work for me without issue!

 

Share this post


Link to post
On 05/09/2016 at 3:29 PM, Asemblance said:

Thanks for your replies - I'm still having problems with the script.

I can now seem to get it to scale, but only after a huge number of error boxes of 'no objects selected'. I've recorded a short video showing my process, perhaps I'm going wrong somewhere?

Screen Recording Link -

If anyone has any advice I'd be greatful as its a very useful tool!

Thanks

This can be fixed by replacing line:

N1:=Count(Sel);

With an option to select only the visible selections 

 

N1:=Count((VSEL=TRUE));

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×