Jump to content

Python message box inside Vectorworks


DomC

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
Link to comment
  • 4 weeks later...

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
Link to comment
  • 3 years later...

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
Link to comment

@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
Link to comment

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...