Jump to content
DomC

Python message box inside Vectorworks

Recommended Posts

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 by DomC

Share this post


Link to post

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 by DomC

Share this post


Link to post

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

Share this post


Link to post

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.

Share this post


Link to post

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 by Benedick_Miller
formatting
  • Like 1

Share this post


Link to post

@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 🙂

 

 

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×