DomC Posted February 27, 2015 Share Posted February 27, 2015 (edited) Hi It looks that it should be possible to use all functionality of the standard python 3.3 inside Vectorworks. The python package is included inside Vectorworks. Just to check this out with a simple dialogue window i tried to create a python based message windows inside Vectorworks -without any success. Maybe i trie to practice with the wrong example (Dialoge Box) Somehow module os.path.basename fails. Anyone else tried to do this? Example Code which do not work inside/outside a Vectorscript. But it works from the python 3 mac terminal. import sys from tkinter import * def mhello(): pass return mGui = Tk() ment = StringVar() mGui.geometry('450x450+500+300') mGui.title('python tkinter message') mlabel = Label(mGui,text ='my label').pack() mbutton = Button(mGui,text ='ok',command = mhello,fg = 'red',bg='blue').pack() mEntry = entry().pack This code is from a very simple python script. It checks if the classes of the active document are part of a standard class list. I post this here, because posting some code is something that makes it more interesting to read a thread. It shows the code with the working vectorscript alert dialogue. KlassenAnzahl=vs.ClassNum() Standardklassen = ('Standardklasse1', 'Standardklasse2', 'Standardklasse2', 'Standardklasse3', 'Standardklasse4') NichtStandard ='' x = 1 while x <= KlassenAnzahl: Klasse = vs.ClassList(x) istKlasseVorhanden = Klasse in Standardklassen x= x+1 if istKlasseVorhanden == 0: NichtStandard = NichtStandard + ' / '+ Klasse vs.AlrtDialog(NichtStandard) Edited February 27, 2015 by DomC Quote Link to comment
DomC Posted March 25, 2015 Author Share Posted March 25, 2015 (edited) In case someone cares Dialog box still not working, but another test with the python module subprocess to open a system window, works instead. A script test to export the classes of the active document to a textfile and open the export folder in a finder windows. This is an example of feature (open a sys folder) wich would be not possible just with the function offered by classic "pascal-vectorscript". import codecs import os.path import os homeDir = os.path.join(os.path.expanduser("~")) Pfad = '{}/Documents/TempVWFiles'.format(homeDir) FileName=vs.GetFName() File = homeDir+'/Documents/TempVWFiles/'+'Klassenliste_'+FileName+'.txt' d = os.path.dirname(Pfad) if not os.path.isdir(Pfad): os.mkdir(Pfad) KlassenAnzahl=vs.ClassNum() f = codecs.open(File, "w", "utf-8") x = 1 while x <= KlassenAnzahl: Klasse = vs.ClassList(x) x= x+1 f.write('\''+Klasse+'\''+',') f.close() vs.AlrtDialog('Die Datei wurde an folgende Stelle gespeichert:'+File) import subprocess import sys path=Pfad if sys.platform == 'darwin': def openFolder(path): subprocess.check_call(['open', '--', path]) elif sys.platform == 'linux2': def openFolder(path): subprocess.check_call(['gnome-open', '--', path]) elif sys.platform == 'win32': def openFolder(path): subprocess.check_call(['explorer', path]) openFolder(path) Edited March 25, 2015 by DomC Quote Link to comment
Benedick_Miller Posted December 28, 2018 Share Posted December 28, 2018 I care! - I have old tools I wrote in Vector-script which I need to update, so I am learning python.This looks like a good learning script, but I get an error: File "<string>", line 1 import codecs I am using Vectorworks 2019 on MacOS 10.14.2 Quote Link to comment
Benedick_Miller Posted December 29, 2018 Share Posted December 29, 2018 answering my own question above: import codecs - works fine now - the problem was caused with copy /paste (for some reason) - I had to re-write the script by hand to get it to work. Quote Link to comment
Benedick_Miller Posted December 29, 2018 Share Posted December 29, 2018 (edited) continued... @DomC - thank for this example, it's really helpful for learning. However there seems to be a mistake in the indenting in your example code, which of course with python is deadly! I got it to work like this: import codecs import os.path import os homeDir = os.path.join(os.path.expanduser("~")) Pfad = '{}/Documents/TempVWFiles'.format(homeDir) FileName=vs.GetFName() File = homeDir+'/Documents/TempVWFiles/'+'Klassenliste_'+FileName+'.txt' d = os.path.dirname(Pfad) if not os.path.isdir(Pfad): os.mkdir(Pfad) KlassenAnzahl=vs.ClassNum() f = codecs.open(File, "w", "utf-8") x = 1 while x <= KlassenAnzahl: Klasse = vs.ClassList(x) x= x+1 f.write('\''+Klasse+'\''+',') f.close() vs.AlrtDialog('Die Datei wurde an folgende Stelle gespeichert:'+File) import subprocess import sys path=Pfad if sys.platform == 'darwin': def openFolder(path): subprocess.check_call(['open', '--', path]) elif sys.platform == 'linux2': def openFolder(path): subprocess.check_call(['gnome-open', '--', path]) elif sys.platform == 'win32': def openFolder(path): subprocess.check_call(['explorer', path]) openFolder(path) Edited December 29, 2018 by Benedick_Miller formatting 1 Quote Link to comment
DomC Posted December 29, 2018 Author Share Posted December 29, 2018 @Benedick_Miller Thanks for Feedback. Certainly you are right. Maybe I edited this in the old forum and after conversion the edited intention was wrong. Or I just pasted wrong code (which is more probable), sorry for taken you busy by posting wrong code 🙂 1 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.