Jump to content

AFDesign

Member
  • Posts

    80
  • Joined

  • Last visited

Reputation

0 Neutral

3 Followers

Personal Information

  • Occupation
    Architect
  • Homepage
    www.andreafacchinello.it
  • Location
    Italy

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. This would be great, if the file can be a .py file written in standard Python language (without splitting code in lines). Thanks!
  2. Thank you so much Raymond! It would be great if the "PythonBeginContext" would allow to start writing Python code as "multi-line text", or even including a .py file directly as for .px files using "{$INCLUDE filename}". Kind regards
  3. Hi everybody, I'm trying to use Python code inside Vectorscript using PythonExecute procedure. It works, but when I need to use indentation I receive this error: I tried with different space counts, using tab, and with unicode \u0009 (tab) but nothing works. Indentation characters seems to be ignored. This is the sample code: procedure test_pythoncontext; VAR check:BOOLEAN; BEGIN check:=true; PythonBeginContext; PythonExecute('import vs'); PythonExecute('check_py = vs.GetVSVar("check")'); {INDENTATION CODE THAT GENERATE AN ERROR} PythonExecute('if check_py == true: '); PythonExecute(' check_py = false'); PythonEndContext; message(check); END; run(test_pythoncontext); Anybody can tell me if indentation is admitted in "PythonExecute"? Thanks!
  4. Yes, as I said previously, if you simply "replace" a string there is no problem, SetVSVar works correctly, and the white space isn't a problem if I use Dynarray of Char. The problem is that after encrypting the plugin, SetVSVar returns an empty value, as you can test in my last example (without using any other python code).
  5. I discovered why my plugin freeze: after encrypting the plugin and rebooting vectorworks, SetVSVar returns an empty variable. You can see the problem by creating a new plugin with this simple code: procedure testsetvsvar; VAR result:STRING; begin PythonBeginContext; PythonExecute('import vs'); PythonExecute('vs.SetVSVar("result","PYTHON TEXT")'); PythonEndContext; alertinform(concat('text from python : ',result),'',false); end; run(testsetvsvar); Without encryption, the plugin works correctly. If you encrypt the plugin and reboot Vectorworks, text from python result is empty.
  6. Sure! Same code, but string is directly assigned in python: PROCEDURE Example; VAR strName : String; BEGIN PythonBeginContext; PythonExecute('import vs'); PythonExecute('import hashlib'); PythonExecute('thestring="test"'); PythonExecute('myhash=hashlib.md5(thestring.encode())'); PythonExecute('vs.SetVSVar("strName", myhash.hexdigest())'); PythonEndContext; AlrtDialog( Concat( '*', strName, '*' ) ); END; RUN(Example); SetVSVar return the white space, after encoding the hash. I think I will not use this phyton code because it works only if the plugin is not encrypted. After encryption, the plugin freeze Vectorworks. If I remove the code and encrypt the plugin, it works. Maybe plugin encryption cause some problems to python code, I will try to understand why.
  7. It's true, if you simply "replace" a string there is no problem. But if you process the variable as in my example, the result has a white space, that disappear if you use "Dynarray of Char" instead of "string". Your example with hash process and String variable (white space in the result): PROCEDURE Example; VAR strName : String; BEGIN strName := ''; PythonBeginContext; PythonExecute('import vs'); PythonExecute('import hashlib'); PythonExecute('thestring=vs.GetVSVar(''strName'')'); PythonExecute('myhash=hashlib.md5(thestring.encode())'); PythonExecute('vs.SetVSVar("strName", myhash.hexdigest())'); PythonEndContext; AlrtDialog( Concat( '*', strName, '*' ) ); END; RUN(Example); Same example using Dynarray variable (correct result): PROCEDURE Example; VAR strName : Dynarray of Char; BEGIN strName := ''; PythonBeginContext; PythonExecute('import vs'); PythonExecute('import hashlib'); PythonExecute('thestring=vs.GetVSVar(''strName'')'); PythonExecute('myhash=hashlib.md5(thestring.encode())'); PythonExecute('vs.SetVSVar("strName", myhash.hexdigest())'); PythonEndContext; AlrtDialog( Concat( '*', strName, '*' ) ); END; RUN(Example); Maybe is something linked to string encoding in python.
  8. Yes, if you use SetVSVar with a STRING variable, the result has a white space at the beginning.
  9. Thank you Pat, I understood the problem: I passed the result to "var myMD5string:STRING;" variable, using STRING a white space is added. If I change to "var myMD5string:DYNARRAY OF CHAR" it works correctly. Thank you for your patience
  10. Using "mystring:DYNARRAY[] OF CHAR;" the hash is generated correctly, but now the result start with a white space. There is the same kind of bug to report.. Thank you procedure MD5test; var myMD5string:STRING; mystring:DYNARRAY[] OF CHAR; begin mystring:='test'; PythonBeginContext; PythonExecute('import vs'); PythonExecute('import hashlib'); PythonExecute('thestring=vs.GetVSVar(''mystring'')'); PythonExecute('vs.AlrtDialog("Imported in python <"+thestring+">")'); PythonExecute('myhash=hashlib.md5(thestring.encode())'); PythonExecute('vs.SetVSVar("myMD5string",myhash.hexdigest())'); PythonEndContext; alertinform(concat('<',myMD5string,'>'),'',false); {result start with a white space} end; run(MD5test);
  11. Thank you Patrick, my fear was only me seeing this error. I will use the workaround. kind regards Andrea
  12. Hi, this is the first time I try to use Python code inside Vectorscript, and I can't understand why by "importing" a variable in Python (using GetVSVar) the first character is automatically deleted. I'm trying to retrieve an MD5 hash from a string: procedure MD5test; var mystring,myMD5string:STRING; begin {importing the correct string} mystring:='test'; PythonBeginContext; PythonExecute('import vs'); PythonExecute('import hashlib'); PythonExecute('thestring=vs.GetVSVar(''mystring'')'); PythonExecute('vs.AlrtDialog("Imported in python <"+thestring+">")'); {string lose the first character!!} PythonExecute('myhash=hashlib.md5(thestring.encode())'); PythonExecute('vs.SetVSVar("myMD5string",myhash.hexdigest())'); PythonEndContext; alertinform(concat('input string: <',mystring,'> wrong result (result for "est"): ',myMD5string),'',false); {importing the string with a starting space} mystring:=' test'; PythonBeginContext; PythonExecute('import vs'); PythonExecute('import hashlib'); PythonExecute('thestring=vs.GetVSVar(''mystring'')'); PythonExecute('vs.AlrtDialog("Imported in python <"+thestring+">")'); PythonExecute('myhash=hashlib.md5(thestring.encode())'); PythonExecute('vs.SetVSVar("myMD5string",myhash.hexdigest())'); PythonEndContext; alertinform(concat('input string with starting space: <',mystring,'> correct result: ',myMD5string),'',false); {using the string directly} PythonBeginContext; PythonExecute('import vs'); PythonExecute('import hashlib'); PythonExecute('myhash=hashlib.md5(b"test")'); PythonExecute('vs.SetVSVar("myMD5string",myhash.hexdigest())'); PythonEndContext; alertinform(concat('correct result using "test" string directly in python: ',myMD5string),'',false); end; run(MD5test); I tried with Vectorworks 2020 and 2021, same problem. Maybe I'm doing something wrong? Thanks!
  13. GetPlanarRef doesn't work too. I created a new 2d path plugin and GetObjectVariableBoolean 650 and 651 works correctly, Pat! I will check what's wrong in my code. EDIT: Now I understood. Variable 650/651 read if an object is 2D or 3D: a 2D object in a custom plane is detected as 3D. For this reason the new plugin I created works, because I only created a 2D polyline to test. But my plugin use the 2D path to create a 3D object, so I receive the same value because my object is a 3D object, in both screen or plan mode. The only way to solve my problem is being able to read the custom plane tilt, but I didn't find a command for this. (I found GetWorkingPlaneN but it isn't relative to an object) Thank you all!
  14. Sorry I'm using a 2D path plugin so I can't post a small sample. I will create a new 2d path plugin and I will try your advice on it! I will let you know if it works tomorrow. Thank you!
×
×
  • Create New...