Jump to content
Developer Wiki and Function Reference Links ×

Evaluating if a variable has changed


DCarpenter

Recommended Posts

I can't seem to figure out how to tell if one of the parameters of a script has been changed for the first time.  I thought I remembered an "OnEvent" function but I can't seem to find it any more in the Script Function Reference.  

 

So I have a popup window in my Object Info Palette where the user can select a symbol from the list.  If the user selects a different symbol I need to change some of the default parameters within the PIO.  After that the user can adjust those defaults as needed, but these defaults are only changed by the script if the user selects a different symbol from the list.  If the script has to be executed again, but the symbol has not changed then the defaults will not reset.  Make sense?

 

Dave

Link to comment

Two options:  

1. Create an extra parameter that is hidden that you store the symbol name in. Then when you execute the PIO if the name in both the symbol and and hidden field don't match you run the cod to reset to the defaults for the symbol. With this method, the user would have to switch to a different symbol and then back if they just wanted to reset to the defaults.

 

2. You could not have the symbol selectable directly from the OIP, but rather put a button there to go to a custom dialog box to select the symbol. Then you could have code in the dialog handler that would reset to the defaults if a change was made to the symbol selected.

 

Let me know if you need more help.

Link to comment

Pat's suggestion of checking that POldData doesn't equal PNewData is the most straightforwards check.

You can also make your plug-in event enabled.  The first step is to set the Event Enabled option in the PIO's settings in the Plug-in Manager.  Once you do, you need to structure your code so it responds to the event retrieved with vsoGetEventInfo.

In your particular case, you also need to enable the plug-in to accept states (I believe this is documented in the Developer Wiki).  Use vsoStateGetParamChng in the reset event to check if a parameter has changed.  I believe you should be able to find a few discussions on event enabled PIOs in the archives.  Here is als a VS framework that demos events.

-Josh

{ 
	untitled text 35 by Joshua Benghiat
	11/19/15 - 10:27 AM
	© Copyright 11/19/15, Joshua Benghiat
}
PROCEDURE MyScript;
CONST
	kWidgetButton			= 12;

	kObjXPropHide3DLocationWidget = 1;
	kObjXPropHasLayerScaleDeps	= 2;
	kObjXPropSpecialEdit		= 3;
	kObjXPropPreference			= 4;
	kObjXPropDirectModeling = 5;		
	kObjXPropAttributeTool = 6;		
	kObjXPropPreventWallInsertion = 7;
	kObjXPropHasUIOverride		= 8;
	kObjXPropAcceptsMarkers = 10;
	kObjXPropDefaultPropertyUI	= 11; 
	kObjXHasCustWdgtVisibilities = 12;
	kObjXIs2DSurfaceEligable = 14;  
	kObjXPropRotatesWithVCS = 15;	
	kObjXPropCustomHideFactor = 16;	
	kObjXHasCustWdgtValues = 17;
	kObjXPropAcceptStates		= 18;
	kObjXPropAcceptStsInternal = 19;
	kObjXPropPreserveContents = 20;
	kObjXPropHasContextMenu = 21;
	kObjXPropResetBeforeExport = 23;
	kObjXPropShowOthersEditGroup = 24;
	{---------------------------------------------------------------------}
	kObjXPropRedSymbolIsStyle = 25;
	kObjXPropHasAttrMappingGeom = 26;
	kObjXPropHasSectionVPGeom = 27;  
	kObjXPropHasLayerElevDeps = 28;	
	kObjXPropHasLayerHeightDeps = 29;
	kObjXPropSupportProxyObjects = 30;
	kObjXPropResetOnMoveInViewport = 31;
	kObjXPropShowPrefDialogWhen = 32;
	
	kHideSymbolWidget = 1;
	kHidePolyWidget = 2;
	kHidePolyAndSymbolRotationWidget = 4;

	kParametricInitGlobals		= 1;
	kParametricDisposeGlobals	= 2;
	
	kResetEventID			= 3;
	kParametricPreference	= 4;
	kObjOnInitXProperties	= 5;
	kObjOnSpecialEditID		= 7;
	kObjOnObjectUIButtonHit	= 35;
	
	kObjOnReshape 				= 9;		{kObjOnDM_## events will be sent inside kObjOnReshape for VW 11.}
	
	kObjOnDM_Select 			= 10;	
	kObjOnDM_Cancel 			= 11;	
	kObjOnDM_MouseDown 			= 12;	
	kObjOnDM_Draw 				= 13;	
	kObjOnDM_Complete 			= 14;	
	kObjOnDM_GetCursor 			= 15;	
	kObjOnDM_ModeEvent 			= 16;	
	kObjOnDM_GetStatus 			= 17;	
	kObjOnDM_CustomBarEvent		= 18;
	kObjOnDM_BeginPauseEvent	= 19;
	kObjOnDM_EndPauseEvent		= 20;
	kObjOnDM_MouseMove 			= 21;
	
	kObjOnAttributeSelect 		= 26;	
	kObjOnAttributeCancel 		= 27;	
	kObjOnAttributeMouseDown 	= 28;	
	kObjOnAttributeDraw 		= 29;	
	kObjOnAttributeComplete 	= 30;	
	kObjOnAttributeGetCursor 	= 31;	
	kObjOnAttributeMove2D 	    = 32;	
	kObjOnAttributeGetStatus 	= 33;	
	kObjOnAttributeModeEvent 	= 34;
		
	kObjOnCursor_MouseDown 		= 36;	
	kObjOnCursor_Complete 		= 37;	
	kObjOnCursor_MouseMove 		= 38;	
	kObjOnCursor_Draw 			= 39;	
	kObjOnCursor_Cancel 		= 40;	

	kObjOnWidgetPrep 			= 41;	{You'll need to include "vsoSetEventResult (-8);" at the end of the event block.}
	kObjOnCommand 		    	= 42;	
	
	kObjOnGetToolName			= 43;
	kObjOnAddState 		    	= 44;
	
	kObjOnContextMenuInit		= 45;
	kObjOnContextMenuEvent		= 46;
	
	kObjOnWidgetValueUpdate		= 47;
	
	kObjOnEyedropperPrepareCopy	= 48;

	kParametricPrefOK				= -4;
	kParametricPrefCancel			= -5;

	kDefaultSpecialEdit		= 0;
	kCustomSpecialEdit		= 1;
	kPropertiesSpecialEdit	= 2;

	kObjXPropEditGroup  		= 1;
	
	{// kObjXPropAcceptsMarkers constants:}
	kObjXPropAccMrkNone = 0;
	kObjXPropAccMrkBeginningOnly = 1;
	kObjXPropAccMrkEndOnly = 2;
	kObjXPropAccMrkBoth = 3;

	
	kObjXPropEditGroupDefault 	= 0;
	kObjXPropEditGroupProfile 	= 1;
	kObjXPropEditGroupPath 		= 2;
	kObjXPropEditGroupCustom 	= 3;
	
{	kObjXPropSpecialEditDefault = 0;
	kObjXPropSpecialEditCustom = 1;
	kObjXPropSpecialEditProperties = 2;
	kObjXPropSpecialEditReshape = 3;}
	
	kParametricEnableStateEventing = 590;
	
	kCreatedReset = 0;
	kMovedReset = 1;
	kRotatedReset = 2;
	kParameterChangedReset = 3;
	kObjectChangedReset = 4;
	kLayerChangedReset = 5;
	kExitFromEditGroup = 6;
	kObjectNameChanged = 7;
	
	kOnDeleteDelete = 4; {Target object is deleted when owner is deleted.}
	kOnDeleteReset = 5;  {Target object is reset when owner is deleted.}
	
VAR
	PIHan		:HANDLE;	{handle to Plug-In}
	PIRecHan	:HANDLE;	{Handle to Plug-In Record}
	PIWallHan	:HANDLE;	{Handle to wall containing Plug-In}
	PIName		:STRING;	{Name of Plug-In definition}
	theEvent: LONGINT; 
	eventMessage: LONGINT;
	theButton: LONGINT;
	result:	BOOLEAN;
	thisDoesNothing:	LONGINT;
	
	boo		:boolean;

	widgID		:LONGINT;	{Event changes}
	prmIndex	: INTEGER;
	oldValue	: STRING;
	moveX, moveY, moveZ	:REAL;
	is3DMove	:BOOLEAN;
	diffAng		:REAL;
	oldScale	:real;
	newScale	:real;
	scaleText	:boolean;

{---------------------------------------------------------------------}
PROCEDURE InitPIO;
	BEGIN
		result:= SetObjPropVS(kObjXPropHasUIOverride, TRUE);
		result := SetObjPropVS(kObjXHasCustWdgtVisibilities, TRUE);

		SetPrefInt(kParametricEnableStateEventing, 1 );
		result := SetObjPropVS(kObjXPropAcceptStates, TRUE);

		result:=SetObjPropVS(kObjXPropHasLayerScaleDeps, TRUE);
		result:=SetObjPropVS(kObjXPropSpecialEdit, TRUE);

		result:=SetObjPropVS(kObjXPropPreference, TRUE);

		result:=SetObjPropVS(kObjXPropHasContextMenu, TRUE);

		result:=SetObjPropVS(kObjXHasCustWdgtValues, TRUE);

		result:= vsoInsertAllParams;
		
		result:= vsoAppendWidget(kWidgetButton, 9000, 'Button', thisDoesNothing);
		AlrtDialog('Init');
	END;
{---------------------------------------------------------------------}
PROCEDURE WidgetPrep;
	BEGIN
		AlrtDialog('WidgetPrep');

		vsoSetEventResult( -8 {kObjectEventHandled} );
	END;
{---------------------------------------------------------------------}
PROCEDURE GetStateChange;
BEGIN
	eventMessage := vsoStateAddCurrent(PIHan, eventMessage);
	AlrtDialog('StateChange');
END;
{---------------------------------------------------------------------}
PROCEDURE ButtonHandler;
	BEGIN
		AlrtDialog('ButtonHandler');
	END;
{---------------------------------------------------------------------}
PROCEDURE SpecialEdit;
	BEGIN
		AlrtDialog('SpecialEdit');
	END;
{---------------------------------------------------------------------}
PROCEDURE SpecialPreferences;
	BEGIN
		AlrtDialog('SpecialPreferences');
	END;
{---------------------------------------------------------------------}
PROCEDURE ContextMenuInit;
	BEGIN
		vsoContextM_Add( 'My Menu Item', 9000, 'My_Menu_Help');
		Message('Init Context Menu');
	END;
{---------------------------------------------------------------------}
PROCEDURE ContextMenuEvent;
	BEGIN
		AlrtDialog(Concat('ContextMenuEvent: ', vsoContextM_GetItem));
	END;
{---------------------------------------------------------------------}
PROCEDURE Main;
	VAR
		newH	:HANDLE;
		
	BEGIN
		AlrtDialog('Main Reset');
		IF vsoStateGetPos( PIHan, moveX, moveY, moveZ, is3DMove ) THEN
			AlrtDialog('StateRegistered: Moved');
		IF vsoStateGetRot( PIHan, diffAng, is3DMove ) THEN
			AlrtDialog('StateRegistered: Rotated');
		IF vsoStateGetParamChng( PIHan, widgID, prmIndex, oldValue ) THEN
			AlrtDialog('StateRegistered: Parameter');
		IF vsoStateGetObjChng( PIHan, widgID ) THEN
			AlrtDialog('StateRegistered: Attributes');
		IF vsoStateGetExitGroup( PIHan, widgID ) THEN
			AlrtDialog('StateRegistered: ExitGroup');
		IF vsoStateGetLayrChng( PIHan, oldScale, newScale, scaleText ) then
			AlrtDialog('StateRegistered: Layer');
		IF vsoStateGet( PIHan, 0 {kCreatedReset} ) THEN
		AlrtDialog('StateRegistered: Created');
		Locus( 0, 0 );
		vsoStateClear( PIHan );
	END;
{---------------------------------------------------------------------}

	
BEGIN
	boo:=GetCustomObjectInfo(PIName, PIHan, PIRecHan, PIWallHan);
	vsoGetEventInfo(theEvent, eventMessage);
	CASE theEvent OF
		{User has single-clicked the object's icon.}
		kObjOnInitXProperties: 
			InitPIO;
		kObjOnWidgetPrep:
			WidgetPrep;
		kObjOnAddState:
			GetStateChange;
		{User has clicked a button in the Object Info palette.}
		kObjOnObjectUIButtonHit:
			ButtonHandler;
		kObjOnSpecialEditID:
			SpecialEdit;
		kParametricPreference:
			SpecialPreferences;
		kObjOnContextMenuInit:
			ContextMenuInit;
		kObjOnContextMenuEvent:
			ContextMenuEvent;
		kObjOnWidgetValueUpdate:
			AlrtDialog('WidgetValueUpdate');
		kResetEventID:
			Main;
	END;	{Event case}
END; 
Run(MyScript);

 

  • Like 1
Link to comment

Wow, thanks for this @JBenghiat, never understood events properly till this nicely laid out code.

 

I don't mean to hijack this thread, but I'm sure this question is related and will help others.

 

Once  you add a parameter from your script, using ,for example:

result = vsoAddWidget(kParamText_ID, kCustomParam_text, "Widget Text")

how would you then grab data that's entered into this custom parameter widget?

 

I tried GetRField in the main reset block of code, but nothings coming up (Created a text object that displays whatever string is in here)

 

Thanks in advance

Link to comment
9 hours ago, twk said:

Once  you add a parameter from your script, using ,for example:


result = vsoAddWidget(kParamText_ID, kCustomParam_text, "Widget Text")

how would you then grab data that's entered into this custom parameter widget?

 

 

@twk, I believe your only option is to use the vsoStateGetParamChng call to check if that widget has changed.  I generally only insert widgets that don't correspond to parameters, like buttons and dividers.  I will manipulate a widget in the widget prep event, for example filling a pulldown menu.

 

-Josh

Link to comment

Josh, my head just exploded after reading your email.  I haven't had to work with vso... anything before, and will have to spend some time getting my head around it all, but it does look very useful.  Thank you for the suggestions.

 

Andy, thank you for the vsoStateGetParamChng that looks like what I'll need to use.

 

Diving into VSO, if I'm not back, you know what happened.  Thanks for your help.

 

Dave

Link to comment

Thanks @JBenghiat,

 

Tried calling

vsoStateGetParamChng( PIHan, widgID, prmIndex, oldValue )

 

and adding widgID, prmIndex, oldValue to the AlrtDialog, but the result is:

widgID = 9001 {just the one i chose for examples sake}

prmIndex = 0

OldVal = ' ' {nothing is displaying here}

 

Could you post an example of what you're saying please.

 

Thanks again

 

 

Link to comment

@twkyou are correct--the routine I mentioned will retrieve the previous value, not the current value.  It's been a while since I investigated, and I think we indeed don't have a way to access a value of a widget that's not bound to a parameter field.

 

You *may* be able to dynamically update the plug-in's record format and bind widgets to the record fields (I know you can definitely do the latter).  The SDK has mechanisms to work with dynamic parameters this way, but I've never tried to do it in VS.

 

-Josh

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