Jump to content
Developer Wiki and Function Reference Links Read more... ×
Sign in to follow this  
Richie Hatch

Scale Objects Script

Recommended Posts

Hi

I know absolutley nothing aout scripts aprt from what they do...! I have a situation that i have to scale various items (text, rectangles, circles....) all by '.5'. When I select all the items and choose scale objects from the Tool Menu it scales everything but does so relative to the entire selection, in doing so moves items out of there originally position. I can do each item individually but was wondering if it was possible to write a script that I could first select a single item and then press the script command (or appoint a keyboard command to it) to scale the object by .5.....?

Not sure how clear that is.. Worth a try...!

Richie

Share this post


Link to post

They are many ways to do this, but this script keep the normal operator logic:

-ask for a scaling factor

-memorizes all the selected objects

-deselect everything

-select each object to apply the scale factor

-reselect everything to keep working

It works (so far!), and is an easy insight into VW functionality.

code:

 

Procedure Individual_Scale;

{debug}

VAR

x,y: REAL;

h: HANDLE;

i,j: INTEGER;

MyH: DYNARRAY [] OF HANDLE ;

BEGIN

x:=RealDialog ( 'enter a scaling factor','0.5');

y:=x;

h:=ActLayer;

j:=NumSObj(h); {how many objects}

ALLOCATE MyH[1..j]; {allocatating the memory}

h:=FSActLayer;

FOR i:=1 TO j DO BEGIN {this keep on memory the objects handle}

MyH
:=h;

h:=NextObj(h);

END;

DselectAll; {we deselect everything}

FOR i:=1 TO j DO BEGIN {this select each object and apply the scale procedure}

SetSelect(MyH
);

Scale(x,y);

SetDSelect(MyH
);

END;

FOR i:=1 TO j DO BEGIN {this select all the scaled objects}

SetSelect(MyH
);

END;

END;

RUN (Individual_Scale);

[/code]

Share this post


Link to post

Sorry: an easy insight into VS functionality.

Share this post


Link to post

Hi Kiwi,

Nice script, thanks. I think you need one change in the loop where you save the handles. You have:

FOR i:=1 TO j DO BEGIN {this keep on memory the objects handle}

MyH:=h;

h:=NextObj(h);

END;

I think "h:=NextObj(h);" should be "h:=NextSObj(h);", so it just saves the handles of selected objects.

All the best,

Raymond

Share this post


Link to post

Going too fast as usual [Roll Eyes] I agree on the correction... Thanks Raymond [smile]

Share this post


Link to post

Hi All

 

I tried the following script, but I make something wrong. Does anybody see what I do wrong?

 

Thanks, Marc

 

Procedure Individual_Scale;

VAR
x,y: REAL;
h: HANDLE;
i,j: INTEGER;
MyH: DYNARRAY [] OF HANDLE;

BEGIN

x:=RealDialog ( 'Skalierungsfaktor','0.5');
y:=x;

h:=ActLayer;
j:=NumSObj(h);

ALLOCATE MyH[1..j];
h:=FSActLayer;

FOR i:=1 TO j DO BEGIN
MyH:=h;
h:=NextSObj(h);

END;


END;

DselectAll;

FOR i:=1 TO j DO BEGIN
SetSelect(MyH);
Scale(x,y);
SetDSelect(MyH);
END;

FOR i:=1 TO j DO BEGIN
SetSelect(MyH);
END;

END;

RUN (Individual_Scale);

 

Edited by MaWi

Share this post


Link to post

Hello Marc,

   There are two problems. First, you have an extra "END" in the middle of the program that needs to be removed. Second, when you make individual references to the handles in your array you need to add a subscript to indicate which one you want.  Eg. where you have   MyH := h;   you should have   MyH[index] := h;.   I marked these below. Make these changes and it will work.

 

HTH,

Raymond

 

PS - Your code may be indented on your computer, but the example above is not. If it isn't, doing so will help you see mismatched BEGIN/END's more easily. 

 

Procedure Individual_Scale;
VAR
	x,y: REAL;
	h: HANDLE;
	i,j: INTEGER;
	MyH: DYNARRAY [] OF HANDLE;
BEGIN
	x:=RealDialog ( 'Skalierungsfaktor','0.5');
	y:=x;
	h:=ActLayer;
	j:=NumSObj(h);
	ALLOCATE MyH[1..j];
	
	h:=FSActLayer;
	FOR i:=1 TO j DO BEGIN
		MyH[i]:=h;			{ need array reference [i] }
		h:=NextSObj(h);
	END;
	
{	END;			<= this END shoud not be here. Remove it. }
	DselectAll;
	FOR i:=1 TO j DO BEGIN
		SetSelect(MyH[i]);		{ need array reference [i] }
		Scale(x,y);
		SetDSelect(MyH[i]);		{ need array reference [i] }
	END;
	FOR i:=1 TO j DO BEGIN
		SetSelect(MyH[i]);		{ need array reference [i] }
	END;
END;
RUN (Individual_Scale);

 

Edited by MullinRJ

Share this post


Link to post

Hi Raymon

 

Thanks for your heldp!

Mister Marionette DomC helped me. We change the script to Phyten :-)

 

Best regards, Marc

 

x=y=0.5
h=vs.FSActLayer()
counter = 0;
while h!=None: #the same like vs.Handle(0)
    p1,p2=vs.HCenter(h)
    vs.HScale2D(h, p1, p2, x, y, True)
    h=vs.NextSObj(h)
    
    counter +=1
    if counter > 100000:
        break

vs.ReDrawAll()

Share this post


Link to post

You're welcome,

That works, too. And, it's better written. I hope you'll keep trying your hand at scripting. It's a great tool and makes VW extremely powerful. If you get stuck with anything, post your questions here. This forum is incredibly helpful. Hope to see around.


Raymond

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
Sign in to follow this  

 

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.

×