Jump to content

How can I scale multiple objects from each objects center?


Recommended Posts

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

Link to comment

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.

Link to comment
  • 2 years later...

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);

Link to comment
  • 3 years later...
  • 1 year later...
  • 8 months later...
  • 3 weeks later...

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

Link to comment

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
changed language encoding
  • Like 1
Link to comment
  • 1 year later...
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));

Link to comment
  • 1 year later...
On 9/5/2016 at 4:57 PM, twk said:

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

 

I've just been trying to use this to scale multiple 3d objects.

Realised that it uses the 2d scale command, which is why it didn't work.

 

I tried replacing the vs.Hscale2D in line 29 with vs.HSacle3D ... adding a 3rd center[] and a 3rd scaleAmount in the hope that might work - but no luck.

 

Completely out of my depth trying to work out why!

 

 

 

 

Link to comment

Swapped out the HScale2D for HScale3D, and seems to scaling fine here. Working on Extrudes though. What particular 3D objects where you trying to scale?

# 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.HScale3D(eachObj, center[0], center[1], 0, scaleAmount, scaleAmount, scaleAmount)
		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

 

  • Like 1
Link to comment
On 8/10/2019 at 6:33 AM, twk said:

Swapped out the HScale2D for HScale3D, and seems to scaling fine here. Working on Extrudes though. What particular 3D objects where you trying to scale?


# 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.HScale3D(eachObj, center[0], center[1], 0, scaleAmount, scaleAmount, scaleAmount)
		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

 

 

Thanks for that. I tried it on a bunch of extrudes. It did scale them all, but it didn't seem to scale relative to each object's centre. Here is the before & after (lines on the ground are for reference and weren't scaled):

 

459762542_ScreenShot2019-08-12at11_55_30.thumb.jpg.94f2e47715ba34f3e04f5d840ba2d7cd.jpg537505609_ScreenShot2019-08-12at11_55_53.thumb.jpg.e06b1b4b2e6895ce685bb8799a916626.jpg

 

 

Link to comment

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