Jump to content
Developer Wiki and Function Reference Links ×

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

Link to comment

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]

Link to comment

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

Link to comment
  • 12 years later...

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
Link to comment

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
Link to comment

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

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