Richie Hatch Posted March 7, 2005 Share Posted March 7, 2005 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 Quote Link to comment
kiwi Posted March 7, 2005 Share Posted March 7, 2005 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] Quote Link to comment
kiwi Posted March 7, 2005 Share Posted March 7, 2005 Sorry: an easy insight into VS functionality. Quote Link to comment
MullinRJ Posted March 8, 2005 Share Posted March 8, 2005 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 Quote Link to comment
Richie Hatch Posted March 8, 2005 Author Share Posted March 8, 2005 Thanks guys I will give it a go and get back to you...! Richie Quote Link to comment
kiwi Posted March 8, 2005 Share Posted March 8, 2005 Going too fast as usual I agree on the correction... Thanks Raymond Quote Link to comment
MaWi Posted August 17, 2017 Share Posted August 17, 2017 (edited) 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 August 17, 2017 by MaWi Quote Link to comment
MullinRJ Posted August 17, 2017 Share Posted August 17, 2017 (edited) 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 August 17, 2017 by MullinRJ Quote Link to comment
MaWi Posted August 17, 2017 Share Posted August 17, 2017 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() Quote Link to comment
MullinRJ Posted August 17, 2017 Share Posted August 17, 2017 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 Quote Link to comment
Recommended Posts
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.