Jump to content
Developer Wiki and Function Reference Links ×

Using PythonExecute in encrypted plug-ins


Recommended Posts

I'm afraid that I already know the answer to this one, but I would most definitely love to be proven wrong.  I have a Vectorscript plug-in that uses PythonExecute and vs.GetVSVar and vs.SetVSVar to get a file's Last Modified date using the pathlib Python library.  This all works beautifully until I encrypt the plug-in, in which case it breaks and crashes Vectorworks.

 

The issue seems to stem from vs.GetVSVar not working correctly and returning a "NoneType" object rather than a DYNARRAY[] OF CHAR of the supplied variable.  I did some tests and it seems that vs.GetVSVar and vs.SetVSVar do not work within encrypted plug-ins.  I'm guessing that the variable names are encrypted but not in the same way that strings are, so when you pass in the variable name in a string, it no longer matches with the actual variable name so it returns NIL.

 

Here's my test code:

PROCEDURE TestPythonEncrypt;

VAR

	testString:DYNARRAY[] OF CHAR;

BEGIN
	testString:='Vectorscript';
	AlrtDialog(Concat('Test: ',testString));
	
	PythonBeginContext;
		PythonExecute('import vs');
		PythonExecute('vs.AlrtDialog("Python is executing")');
		PythonExecute('vs.AlrtDialog(vs.GetVSVar("testString"))');
		PythonExecute('vs.SetVSVar("testString","Python")');
		PythonExecute('vs.AlrtDialog(vs.GetVSVar("testString"))');
	PythonEndContext;
	
	AlrtDialog(Concat('Test: ',testString));
END;

Run(TestPythonEncrypt);

 

It should return:

  1. Test: Vectorscript
  2. Python is executing
  3. Vectorscript
  4. Python
  5. Test: Python

 

After encryption, it instead returns:

  1. Test: Vectorscript
  2. Python is executing
  3. Test: Vectorscript

 

This tells me that Python is working, but not the vs.GetVSVar or vs.SetVSVar functions.

 

The whole point of the plug-in is lost without being able to pull a file's Last Modified date, and I'd rather not send out an unencrypted plug-in.  Any ideas on a solution?

Link to comment

For those playing along at home or searching for this solution somewhere down the line, the test code above changed to use the Rpstr_GetValueStr and Rpstr_SetValueStr implementation that will survive encryption is below:

 

PROCEDURE TestPythonEncrypt;

VAR

	testString:DYNARRAY[] OF CHAR;
	BSB:BOOLEAN;

BEGIN
	testString:='Vectorscript';
	Rpstr_SetValueStr('testString',testString);
	
	AlrtDialog(Concat('Test: ',Rpstr_GetValueStr('testString','')));
	
	PythonBeginContext;
		PythonExecute('import vs');
		PythonExecute('vs.AlrtDialog("Python is executing")');
		PythonExecute('vs.AlrtDialog(vs.Rpstr_GetValueStr("testString",""))');
		PythonExecute('vs.Rpstr_SetValueStr("testString","Python")');
		PythonExecute('vs.AlrtDialog(vs.Rpstr_GetValueStr("testString",""))');
	PythonEndContext;
	
	AlrtDialog(Concat('Test: ',Rpstr_GetValueStr('testString','')));
	
	BSB:=Rpstr_RemoveValue('testString');
END;

Run(TestPythonEncrypt);

 

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