GioPet Posted October 16, 2018 Share Posted October 16, 2018 Hello, I have been working on a few Python Scripts that use third party libraries - for example BeautifulSoup4. I intend to Encryption this script into a vsm plugin so that the external libraries are bound to it and can be used on other installations of Vectorworks. I realised that the Encryption/Obfuscation method through Vectorworks is not able to bind the external packages into the vsm file: I've included the path to these libraries in the Script Options and I am using the steps indicated by Vlado in this post for the related xml file. <?xml version="1.0" encoding="UTF-8" standalone="no"?><!-- This file defines how the corresponding script plug-in should be packaged--><Plugin> <Package> <File>code/__init__.py</File> <File>bS4/</File> <File>bS4/__init__.py</File> <File>bS4/.py</File> <File>bS4/diagnose.py</File> <File>bS4/element.py</File> <File>bS4/testing.py</File> <File>bS4/builder/__init__.py</File> <File>bS4/builder/_html5lib.py</File> <File>bS4/builder/_htmlparser.py</File> <File>bS4/builder/_lxml.py</File> </Package> </Plugin> Can any one advise on how to resolve this? Thank you in advance. Giovanni Quote Link to comment
JBenghiat Posted October 18, 2018 Share Posted October 18, 2018 Is /7_Vectorworks 2018 your VW user folder? It’s an unusual name, so if not, you need to add a path attribute to the xml. For this xml, the .vsm file would be in the /7_Vectorworks 2018/plug-ins folder, along with the xml file. You’re not including the main.py file if you have one — any .py files in /code that you use also need to be in the xml file. The only reason not to include them is if your main code is all directly in the vsm. I.e. if you open the vsm in the plug-in manager’s script editor and call import bs4 from there Quote Link to comment
GioPet Posted October 19, 2018 Author Share Posted October 19, 2018 Hi Joshua, thank you for your response. Yes my user folder was set to /7_Vectorworks 2017, and I keeping the xml in the Plug-in folder within that. For clarity - I have know reverted back to the standard path and still keeping the xml next to the vsm. Indeed, I don't have a 'main.py' because all my code is in the vsm. The Encryption works with no errors, but when I run the Encrypted vsm on a different installation of Vectorworks I get the error:ImportError: No module named 'bs4' (bs4 module is the BeautifulSoup module) My python call in the script is: from bs4 import BeautifulSoup So something is not working in actually binding the package with the vsm file.. any idea? here is a screenshot of my Plug-in Folder with the Development/code and Development/bs4 folders. thank you Giovanni Quote Link to comment
JBenghiat Posted October 19, 2018 Share Posted October 19, 2018 The include files are relative to the .vsm, so add Development/ to your file locations. Quote Link to comment
GioPet Posted October 19, 2018 Author Share Posted October 19, 2018 That's the case: <?xml version="1.0" encoding="UTF-8" standalone="no"?><!-- This file defines how the corresponding script plug-in should be packaged--><Plugin> <Package> <File>Development/code/__init__.py</File> <File>Development/bS4/</File> <File>Development/bS4/__init__.py</File> <File>Development/bS4/.py</File> <File>Development/bS4/diagnose.py</File> <File>Development/bS4/element.py</File> <File>Development/bS4/testing.py</File> <File>Development/bS4/builder/__init__.py</File> <File>Development/bS4/builder/_html5lib.py</File> <File>Development/bS4/builder/_htmlparser.py</File> <File>Development/bS4/builder/_lxml.py</File> </Package> </Plugin> Quote Link to comment
The Hamma Posted July 21, 2020 Share Posted July 21, 2020 (edited) Does this run the external scripts? What would be the format If i wanted to place a python script next the the .vsm and run that script from within the vectorworks python script? Edited July 21, 2020 by The Hamma Quote Link to comment
tbexon Posted July 30, 2020 Share Posted July 30, 2020 You need to use the import command. So your .vsm file literally looks like: import external_python_script And then you make sure that the external python script's code does some thing on initialization. To encrypt the plugin that's in the same directory, I just encrypt with a "blank" .xml file: <?xml version="1.0" encoding="UTF-8" standalone="no"?><!-- This file defines how the corresponding script plug-in should be packaged--> <Plugin> <Package> </Package> </Plugin> As long as there both in the same directory should work fine. Note if you're .vsm + Script are in a subfolder within plugin folder you may need to modify the import command accordingly. Quote Link to comment
The Hamma Posted August 3, 2020 Share Posted August 3, 2020 OK I have another question. If I run an external python script from an internal script can I pass the variables from the external script back to the internal script when the external script completes? Quote Link to comment
JBenghiat Posted August 4, 2020 Share Posted August 4, 2020 19 hours ago, The Hamma said: OK I have another question. If I run an external python script from an internal script can I pass the variables from the external script back to the internal script when the external script completes? @The Hamma That's not exactly how includes in python work. Everything in the include is a resource, treating the included file like a class. Included variables become properties of the class and functions become methods of the class. Nothing in the external runs until you call it — so you would likely define a function in the "external" script that returns a value to the "internal" script. https://realpython.com/python-import/ Quote Link to comment
The Hamma Posted August 5, 2020 Share Posted August 5, 2020 Ok, I can use from VPRename_A import hVP, numberStr to retrieve hVP and numberStr from VPRenumb_A Now that I have that solved It does not seem to fix my issue with the script. If I run script "VP Label (Consecutive)" from the workspace and I place "VPRenumb_A.vsm" in the workspace and call it via "vs.DoMenuTextByName('VPRenumb_A', 0)" it actually leaves my script to run the second script and this completes without giving me any messages about renumbering the drawing labels. If I run script "VP Label (Consecutive)" from the workspace and I place "VPRenumb_A.py" in the plugins folder and call it via "from VPRename_A import hVP, numberStr" it actually imports the "VPRenumb_A.py" into the first script to run and this completes giving me a warning messages about renumbering the drawing labels. Is there a way to call an external python script without running it within the first script like "vs.DoMenuTextbyName" does? Note I still need to receive or send variables to or from the second script and not all of the labels redraw correctly. I have attached the two versions. VP Label (Consecutive) (DoMenubytextName).zip VP Label (Consecutive) (import).zip 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.