Jesse Cogswell Posted November 26, 2023 Share Posted November 26, 2023 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: Test: Vectorscript Python is executing Vectorscript Python Test: Python After encryption, it instead returns: Test: Vectorscript Python is executing 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? Quote Link to comment
Pat Stanford Posted November 26, 2023 Share Posted November 26, 2023 It looks like this same issue was discussed in 2020 with no resolution. These two threads also contain information on encrypting VS/Python. 1 Quote Link to comment
JBenghiat Posted November 26, 2023 Share Posted November 26, 2023 You are correct— encryption substitutes a token for all the variable and constant names, so the value passed to the VSValue isn’t valid. The string repository commands (RepStr) will work, however, both for passing data between vs and python as well as for preserving data between script runs. 3 Quote Link to comment
Jesse Cogswell Posted November 28, 2023 Author Share Posted November 28, 2023 @JBenghiat I just tested this and you appear to have saved the day. Totally works. Thank you also to @Pat Stanford for the enlightening reading material. Answered some questions while raising several others. Quote Link to comment
Jesse Cogswell Posted November 28, 2023 Author Share Posted November 28, 2023 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); 2 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.