MarcelP102 Posted August 20 Share Posted August 20 (edited) Hi All, After having a kid I lost the time to code for Vectorworks. But now I finally managed to finish this script that let you replace symbols (definition, rotation, scale and/or position). With a nice little menu that saves your last input. Let me know what you think! ps. If someone wants to help me make this a 'tool' with a icon that would be nice. PROCEDURE ReplaceSymbol; VAR oldH, newH :HANDLE; trackLoc :POINT3D; SymName, TempString :STRING; SymRotationNew, SymRotationOld :REAL; rPosXold, rPosYold, rPosZold :REAL; rPosXnew, rPosYnew, rPosZnew :REAL; rScaleFactorX, rScaleFactorY, rScaleFactorZ :REAL; b1, bool, bSymName, bSymRot :BOOLEAN; bSymScale, bSymPosX, bSymPosY, bSymPosZ :BOOLEAN; id, item, rScaleType :INTEGER; {******************************** Converts a boolean to a string ****************} FUNCTION Str2Boo(str :STRING) :BOOLEAN; BEGIN IF str='TRUE' THEN Str2Boo := TRUE ELSE Str2Boo := FALSE; END; {FUNCTION Str2Boo} {******************************** The ever confusing dialog handler ****************} PROCEDURE Dialog_Handler(VAR item :LONGINT; data :LONGINT); BEGIN CASE item OF SetupDialogC: BEGIN Bool := GetSavedSetting('ReplaceSymbol','SymName',TempString); SetBooleanItem(id, 4, Str2Boo(TempString)); Bool := GetSavedSetting('ReplaceSymbol','SymRot',TempString); SetBooleanItem(id, 5, Str2Boo(TempString)); Bool := GetSavedSetting('ReplaceSymbol','SymScale',TempString); SetBooleanItem(id, 6, Str2Boo(TempString)); Bool := GetSavedSetting('ReplaceSymbol','SymPosX',TempString); SetBooleanItem(id, 8, Str2Boo(TempString)); Bool := GetSavedSetting('ReplaceSymbol','SymPosY',TempString); SetBooleanItem(id, 9, Str2Boo(TempString)); Bool := GetSavedSetting('ReplaceSymbol','SymPosZ',TempString); SetBooleanItem(id, 10, Str2Boo(TempString)); SetItemText(id, 20, Symname); SetItemText(id, 21, Angle2Str(SymRotationNEW)); SetItemText(id, 22, Concat(Num2Str(1, rScaleFactorX), ' / ', Num2Str(1, rScaleFactorY), ' / ', Num2Str(1, rScaleFactorZ))); SetItemText(id, 23, Num2StrF(rPosXnew)); SetItemText(id, 24, Num2StrF(rPosYnew)); SetItemText(id, 25, Num2StrF(rPosZnew)); END; 1: { Press OK } BEGIN GetBooleanItem(id,4,bSymName); GetBooleanItem(id,5,bSymRot); GetBooleanItem(id,6,bSymScale); GetBooleanItem(id,8,bSymPosX); GetBooleanItem(id,9,bSymPosY); GetBooleanItem(id,10,bSymPosZ); END; 2: { Press CANCEL } BEGIN END; END; {Case} END; {Dialog Handler} {******************************** The slightly less confusing dialog layout ****************} PROCEDURE MakeMeADialogBox; BEGIN id:=CreateLayout('Symbol Replacer',FALSE,'OK','Cancel'); CreateCheckBox(id,4,'Definition:'); CreateCheckBox(id,5,'Rotation: '); CreateCheckBox(id,6,'Scale X/Y/Z: '); CreateSeparator(id,7, 120); CreateCheckBox(id,8,'Postion - X: '); CreateCheckBox(id,9,'Postion - Y: '); CreateCheckBox(id,10,'Postion - Z: '); CreateStaticText(id,20,'Symbolname',-1); CreateStaticText(id,21,'Rotatievalue',-1); CreateStaticText(id,22,'Symbool Scale',-1); CreateStaticText(id,23,'X-Value',-1); CreateStaticText(id,24,'Y-Value',-1); CreateStaticText(id,25,'Z-Value',-1); SetFirstLayoutItem(id,4); SetBelowItem(id,4,5,0,0); SetBelowItem(id,5,6,0,0); SetBelowItem(id,6,7,0,0); SetBelowItem(id,7,8,0,0); SetBelowItem(id,8,9,0,0); SetBelowItem(id,9,10,0,0); SetRightItem(id,4,20,0,0); SetBelowItem(id,20,21,0,-2); SetBelowItem(id,21,22,0,-2); SetRightItem(id,8,23,0,0); SetBelowItem(id,23,24,0,-2); SetBelowItem(id,24,25,0,-2); END; {******************************** Provides Callback for selecting Symbols ****************} FUNCTION CheckObjCallback(h1:HANDLE) : BOOLEAN; BEGIN If (GetTypeN(h1) = 15) then CheckObjCallback:=True; END; {//////////////////////////////// MAIN \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ } BEGIN { Pick symbol and get propertys } TrackObjectN(0,CheckObjCallback,newH,trackLoc.x,trackLoc.y,trackLoc.z); { Get parameters for dialog } SymName := GetSymName(newH); SymRotationNEW := GetSymRot(newH); GetSymLoc3D(newH, rPosXnew, rPosYnew, rPosZnew); rScaleFactorX := GetObjectVariableReal(newH, 102); { X scale } rScaleFactorY := GetObjectVariableReal(newH, 103); { Y scale } rScaleFactorZ := GetObjectVariableReal(newH, 104); { Z scale } { Start dialog } MakeMeADialogBox; item := RunLayoutDialog(id, Dialog_Handler); IF item = 1 THEN { OK } BEGIN { Save settings for later use } SetSavedSetting('ReplaceSymbol','SymName',Concat(bSymName)); SetSavedSetting('ReplaceSymbol','SymRot',Concat(bSymRot)); SetSavedSetting('ReplaceSymbol','SymScale',Concat(bSymScale)); SetSavedSetting('ReplaceSymbol','SymPosX',Concat(bSymPosX)); SetSavedSetting('ReplaceSymbol','SymPosY',Concat(bSymPosY)); SetSavedSetting('ReplaceSymbol','SymPosZ',Concat(bSymPosZ)); B1:=False; While B1 = False do BEGIN TrackObjectN(0,CheckObjCallback,oldH,trackLoc.x,trackLoc.y,trackLoc.z); IF oldH <> NIL THEN BEGIN IF bSymName THEN BEGIN { Set symbool definition } SetHDef(oldH, GetObject(SymName)); END; IF bSymRot THEN BEGIN { Set symbool rotation } GetSymLoc3D(oldH, rPosXold, rPosYold, rPosZold); SymRotationOLD := GetSymRot(oldH); HRotate(oldH,rPosXold,rPosYold,(SymRotationNew-SymRotationOld)); END; IF bSymScale THEN BEGIN { Set symbool scale } rScaleType := GetObjectVariableInt(newH, 101); SetObjectVariableInt(oldH, 101, rScaleType); rScaleFactorX := GetObjectVariableReal(newH, 102); { X scale } SetObjectVariableReal(oldH, 102, rScaleFactorX); rScaleFactorY := GetObjectVariableReal(newH, 103); { Y scale } SetObjectVariableReal(oldH, 103, rScaleFactorY); rScaleFactorZ := GetObjectVariableReal(newH, 104); { Z scale } SetObjectVariableReal(oldH, 104, rScaleFactorZ); END; IF bSymPosX THEN BEGIN { Set symbool X position } GetSymLoc3D(oldH, rPosXold, rPosYold, rPosZold); Move3DObj(oldH,rPosXnew-rPosXold,0,0); END; IF bSymPosY THEN BEGIN { Set symbool Y position } GetSymLoc3D(oldH, rPosXold, rPosYold, rPosZold); Move3DObj(oldH,0,rPosYnew-rPosYold,0); END; IF bSymPosZ THEN BEGIN { Set symbool Y position } GetSymLoc3D(oldH, rPosXold, rPosYold, rPosZold); Move3DObj(oldH,0,0,rPosZnew-rPosZold); END; ResetObject(oldH); ReDraw; END ELSE B1:=TRUE; END; END; {If user clicked OK} END; {main} RUN(ReplaceSymbol); Edited August 20 by MarcelP102 1 Quote Link to comment
SamIWas Posted August 31 Share Posted August 31 I'm glad you posted this. Not for the script itself, but because it reminded me to look into saved settings and how to implement them. I didn't realize it was so easy, and now I got it working on my own stuff. 2 Quote Link to comment
Mirko Guhr Posted September 16 Share Posted September 16 hello @MarcelP102, I’d like to help you. Personally, I’m still a few steps behind. I still have my marionette, which I’m in the process of converting into a script/-s. After that, it should become a tool/-s. At the moment, I’m still trying to understand how this plugin/parameter specification topic works. Quote Link to comment
Pat Stanford Posted September 16 Share Posted September 16 @MarcelP102 The basic steps to make this a tool are to: 1. Go to the Tools:Plug-ins:Plug-in Manager. 2. Create a new Plug-in of the Tool type. 3. Click the Edit Script button of the Plug-in Manager and paste the script in. 4. Click the Edit Definition button of the Plug-in Manager. From the General Pane give it a name (and Category to make it easier to find.) From the Properties Pane you can import a PNG for the icon. There are specific requirements for the icon graphic that I can't remember. Something like 26x20 pixels at 72 dpi. Also a second high res version named 2X. Search the VW documentation about Plug-in Icons. 5. Edit your workspace to add the new tool and test. HTH 1 Quote Link to comment
Mirko Guhr Posted September 16 Share Posted September 16 I have already looked at the plug-in menu and the documentation a bit. @Pat Stanford Is it also possible to generate such setting buttons? Without having a special interface or function package? Quote Link to comment
Pat Stanford Posted September 16 Share Posted September 16 I have not done it, but I think you can add mode buttons to a tool using the vstXXXXX functions in Vectorscript. These allow you to "simulate" and event enabled tool using simpler Vectorscript. @JBenghiat Am I off base here? 1 Quote Link to comment
Mirko Guhr Posted September 17 Share Posted September 17 I found out that it seems to be possible only with C++ and the SDK. @JBenghiat can enlighten me a bit more. For details, I would then make a separate post when the time comes. Unless of course, @MarcelP102 wants to know more about it, then we can stay here 🙂. Quote Link to comment
JBenghiat Posted September 21 Share Posted September 21 VS tools are a little tricky. You CAN create an event enabled tool, but this requires changing a bit in the .vst via a hex editor. And even then, the tool script does not run until after the first user click. You can modify the mode bar, though. Alternatively, you can use RunTempTool to run a tool from a menu command. TrackObject will also work with the temp tool. To get tool that listens to the first click, the SDK is the only option. 1 Quote Link to comment
Mirko Guhr Posted September 21 Share Posted September 21 Thank you for the detailed response. 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.