Jump to content
Developer Wiki and Function Reference Links Read more... ×
Julian Carr

Sample VST with Mode Bar Buttons

Recommended Posts

Does anyone have a sample script for a VST that uses buttons in the tool bar?

 

Thanks!

Share this post


Link to post

Julian,

   If you find one, I'd love one, too. Please share. Years ago, when I first looked for the same, I believe I was told it was only achievable with the SDK. I have several tools I have made that would benefit immensely from Mode Buttons. I hope you find an example.

 

Raymond

Share this post


Link to post

I don't think you can either. In vectorscript tools are generated automatically fitting the plugin type. In the SDK, these are separate and can be customized.

Share this post


Link to post

It's possible, but not straightforwards.  You need to flag the tool as event enabled.  AFIK, the only way to do this is with a hex editor.  The instructions for this are somewhere — either in the developer wiki, or possibly VectorDepot or such.

 

The mode bar buttons are generally designed to be part of RunTempTool or TrackObject.  These are generally best run from a menu or PIO button, though.  Tool functionality is primarily why I switched to the SDK.

 

Here's an example.  It's an edited version of an actual plug-in, not a sample, so it won't necessarily work as is.

 

PROCEDURE MyScript;
CONST
	kToolXPropSelectionChange = 1;		{tool wants selection change events.}
	kToolXPropUnsupported = 2;			{not supported}
	kToolXPropWantsMoveSelection2D = 3;	{tool wants kToolMoveSelection2DEvent event with nudge and move 2D commands.}
	k2DToolEnabledInStackedLayerMode = 4;		{2D tool wants to be enabled in Unified View.}
	kToolXPropSetUnrestrictedMode	= 5;		{set unrestricted scaling mode to the 2D selection tool}

	kToolInitGlobals		= 1;
	kToolDisposeGlobals		= 2;
	kToolDoSetup			= 3;
	kToolDoSetDown			= 4;
	kToolGetCursor			= 5;
	kToolDoInterface 		= 6;	{// to be removed}
	kToolDoModeEvent		= 7;
	kToolDoDoubleClick		= 8;
	kToolDoDrawScrMod		= 9;
	kToolDoUndrawScrMod		= 10;
	kToolPointAdded			= 100;
	kToolMouseMove			= 101;
	kToolDrawingDoubleClick	= 102;
	kToolDraw 				= 103;
	kToolHandleComplete 	= 104;
	kToolGetStatus 			= 105;
	kToolPointRemoved		= 106;
	kToolGenericStateChange	= 107;		
	
	{ below can be sent to Tool Definition Procedure (TDP) with Extended Properties.}

	kToolOnInitXProperties		= 108;
	kToolOnSelectionChange		= 109;															
	kToolOnMoveSelection2D		= 110;														
	kToolCustomSubtypeInsert	= 111;		
	kToolOnIdleEvent			= 112;						
	kToolOnCustomBarEvent     	= 113;
	
	kStr_HelpSelectPoint	= 3000 -1 + 1;	{String in PIO.  I would move these to strings file now}
	kStr_HelpSelectOrigin	= 3000 -1 + 2;	

	kMode1Btn1 = 'VWRName/Images/ModeViewBar/NameofImage1.png';
	kMode1Btn2 = 'VWRName/Images/ModeViewBar/NameofImage2.png';
	
	kModeGroupOrigin = 1;
	kModeGroupClick = 2;
	kOriginStore = 9001;
	kTokenCounter = '<count>';

VAR
	pt 			:POINT;		{User click point}
	origin		:POINT;		{User origin}
	outAction     :LONGINT;
	outMessage1   :LONGINT;
	outMessage2   :LONGINT;
	helpText 		:dynarray[] of char;
	result			:BOOLEAN;
	totalPts		:LONGINT;
	firstPt			:REAL;
	modeInt_1		:LONGINT;
	i			:INTEGER;
	startIndex	:INTEGER;
	adjustTotal	:INTEGER;
	
	boo			:boolean;

{---------------------------------------------------------------------}
FUNCTION GetOriginMode : REAL;
	VAR
		mode:REAL;
		boo	:BOOLEAN;
	BEGIN
		vstGetDataLong( kOriginStore, mode, boo );
		IF NOT boo THEN
			mode := 1;
		GetOriginMode := mode;
	END;
{---------------------------------------------------------------------}
BEGIN
	vstGetEventInfo(outAction, outMessage1, outMessage2);
	
	vstGetModeValue(1, modeInt_1);

	CASE outAction OF
		kToolInitGlobals		: BEGIN
		
		END;
		kToolDisposeGlobals		: BEGIN
		
		END;
		kToolDoSetup			: BEGIN
			AddRadioMode( kModeGroupOrigin, 2, kMode1Btn1, kMode1Btn2, '', '', '', '' );
			vstSetPtBehavior(4);
			vstGetModeValue(kModeGroupOrigin, modeInt_1);
			IF modeInt_1 = kModeGroupOrigin THEN
				vstSetHelpString(GetPluginString(kStr_HelpSelectPoint))
			ELSE
				vstSetHelpString(GetPluginString(kStr_HelpSelectOrigin));
			vstSetDataReal(1, 1, result);
		END;
		kToolDoSetDown			: BEGIN
			ReDrawAll;
			vstGetModeValue(kModeGroupOrigin, modeInt_1);
			vstSetDataLong( kOriginStore, modeInt_1, boo );
		END;
		kToolGetCursor			: BEGIN
		
		END;
		kToolDoInterface 		: BEGIN
		
		END;
		kToolDoModeEvent		: BEGIN
			IF modeInt_1 = kModeGroupOrigin THEN
				vstSetHelpString(GetPluginString(kStr_HelpSelectPoint))
			ELSE
				vstSetHelpString(GetPluginString(kStr_HelpSelectOrigin));
		END;
		kToolDoDoubleClick		: BEGIN
		
		END;
		kToolDoDrawScrMod		: BEGIN
		
		END;
		kToolDoUndrawScrMod		: BEGIN
		
		END;
		kToolPointAdded			: BEGIN
			vstNumPts(totalPts);
			vstGetDataReal(1, firstPt, result);
			IF (totalPts=2) & (firstPt=1) THEN BEGIN
				vstSetDataReal(1, 0, result);
				totalPts:=1;
			END;
			IF modeInt_1=kModeGroupOrigin THEN adjustTotal:=0 ELSE adjustTotal:=-1;
			helpText := GetPluginString( kStr_HelpClicks );
			ReplaceStr( helpText, kTokenCounter, Concat( totalPts + 1 + adjustTotal ) );
			vstSetHelpString( helpText );
		END;
		kToolMouseMove			: BEGIN

		END;
		kToolDrawingDoubleClick: BEGIN
		END;
		kToolDraw 				: BEGIN
		
		END;
		kToolHandleComplete 	: BEGIN
			vstNumPts(totalPts);
			IF modeInt_1=kModeGroupOrigin THEN BEGIN	{Drawing origin}
				origin.y:=0;
				startIndex:=1;
			END
			ELSE BEGIN
				vstGetPt2D(0, origin.x, origin.y, result);
				startIndex:=2;
			END;
			FOR i:=startIndex TO totalPts DO BEGIN
				vstGetPt2D(i-1, pt.x, pt.y, result);

			END;

			RefreshAllLSSched;
			vstSetHelpString(GetPluginString(kStr_HelpSelectPoint));
			vstSetDataReal(1, 1, result);
		END;
		kToolGetStatus 			: BEGIN
		
		END;
		kToolPointRemoved		: BEGIN
		
		END;
		kToolGenericStateChange: BEGIN
		
		END;
	END; {CASE}
END;
Run(MyScript);

 

Share this post


Link to post

Josh,

   You've got my attention. Thanks. Somewhere I've got a recipe for "using" a Hex Editor. I'll post back when I dig it up.

 

   So, in your opinion which is harder, going down this route, or learning the SDK?

 

 

:-)

Raymond

Share this post


Link to post

Getting the tool to work is actually not so bad. Figuring out what events are open to VS takes some trial and error, and they are different for event enabled tools, RunTempTool, and TrackObject. 

 

And there still isnt away to get a VS tool to run before the first click. 

Share this post


Link to post
1 hour ago, JBenghiat said:

And there still isnt away to get a VS tool to run before the first click. 

 

I have run down that dead-end alley, too. Life would be so much more colorful if it did.

 

Thanks,

Raymond

Share this post


Link to post

Thanks Josh. I had a bit of a play with it but as you implied, it makes Vectorscript even more of a black box than it is already. Lots of unexplained crashes and mystery.  Two things I have built up immunity to over the years, but I still got the bug with this one.

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

 

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.

×