Jump to content

AFDesign

Member
  • Posts

    80
  • Joined

  • Last visited

Posts posted by AFDesign

  1. 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:

    Quote

    IndentationError: expected an indented block

     

    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!

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

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

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

  5. 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);

     

  6. 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!

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

     

  8. Hi,

    I'm working with a 2D path object plugin, and I'd like to detect if the path has been created on a screen plane or layer plane. 

     

    I tried this:

    GetObjectVariableBoolean(handle, 1160);

    using both plugin and path handles, but I always get the same result drawing in screen plane or layer plane.

     

     

    Any advice is appreciated, thanks!

     

    Andrea

  9. Hi,

    it would be very nice if Vectorscript could take advantage of multi-core cpu in repetition statements, for example:

    PROCEDURE multicore;
    
    var
    hascanceled:Boolean;
    total,counter:integer;	
    
    BEGIN
    
    total:=4000;
    counter:=0;
    hascanceled:=false;
    
    ProgressDlgOpen('Start multicore test...', true );
    ProgressDlgSetMeter('Please wait...' );
    ProgressDlgStart(100.0,total);
    
    while (counter < total) do begin
    
    	{...cpu-intensive operations}
    
    	counter:=counter+1;
    	progressdlgyield(1);
    	hasCanceled := ProgressDlgHasCancel;
    	if hasCanceled then counter:=total;
    
    	enablemulticore; {doesn't wait end of operation, start the next with another core}
    
    end; {while}
    
    progressdlgend;
    progressdlgclose;
    
    end;
    
    Run(multicore);
    

  10. Hi,

    I have the same problem reported in this post using "progress dialog" function on a plugin I wrote. You can quickly reproduce the problem in this way:

    1) create a new script and paste "example 1" from here

    2) run the script: if you click cancel button it works correctly; if you push the ESC button all stops but the dialog remains opened and, even if you close its window, vectorworks menus are locked and grayed out (impossible to quit)

    Tested with Vectorworks 2016 SP1 on OSX 10.10.5

    Any workaround to solve this adding some code to the example??

    Thanks

  11. Hi,

    I have the same problem using "progress dialog" on a plugin I wrote. You can quickly reproduce the problem in this way:

    1) create a new script and paste "example 1" from here http://developer.vectorworks.net/index.php/VS:Progress_Dialog

    2) if you click cancel button it works correctly; if you push the ESC button all stops but the dialog remains opened and, even if you close its window, all is locked and grayed out.

    Tested with Vectorworks 2016 SP1 on OSX 10.10.5

    Any workaround to solve this adding some code to the example??

    Thanks

  12. I finally found a workaround, if someone is interested:

    1) SetMaximumUndoEvents(0);

    2) execute script

    3) restore maximum undo events

    :) end of monologue

  13. I tried everything, it's probably a bug. if you try this simple code in a linear object plugin, when it regenerates with undooff you will receive the alert message twice, if you delete undooff it will works correctly (only one alert).

    Any workaround?

    Thanks

    PROCEDURE Example1;

    BEGIN

    undooff;

    ovaln(0,0,0,1,1m,1m); {draw a circle}

    alertinform('Plugin regenerated!','',false);

    END;

    Run(Example1);

  14. Hi,

    does it exist additional documentation for the "UndoOFF" procedure more than

    http://developer.vectorworks.net/index.php/VS:UndoOff ?

    My plugin take some time to regenerate so I use "Progress Dialog" to have visual feedback. If I put UndoOFF (after Begin) my plugin regenerate 2 times: when the progressbar end, it restart one more time.

    Without UndoOFF it works correctly, but I need it to reduce memory use.

    Thanks for your help!

×
×
  • Create New...