Jump to content
Developer Wiki and Function Reference Links ×

Release: Replace Symbol Script


Recommended Posts

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.

 

image.png.f1ea849d130761bde89db110bf26f28b.png

 

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 by MarcelP102
  • Like 1
Link to comment
  • MarcelP102 changed the title to Release: Replace Symbol Script
  • 2 weeks later...
  • 3 weeks later...

@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

  • Like 1
Link to comment

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. 

  • Like 1
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...