Jump to content
Nik

Using try/except

Recommended Posts

Trying to figure out a quick and easy way to see if a symbol exists in a drawing.  There doesn't seem to be a straight forward way of doing this that I can find. So I figured I would use "try/except". But vw still throws an error 😕

 

symName = 'mySymbolName'

try:
      vs.Symbol(symName,0,0,0)
except:
      vs.AlrtDialog(symName+' doesn't exist in this drawing')

Edited by Nik

Share this post


Link to post

You have to check whether the symbol 'name' exists in the drawing.

 

You can check using vs.GetObejct(symName) to see whether it returns None or 0.

Share this post


Link to post

should have been more clear... need to check if the symbol exists in the drawing symbol library.  vs.GetObject works to check if a symbol has been inserted in a drawing. try/except does work for other types of errors. but maybe not for VW thrown errors? 

 

The following bit of code works as expected

 

try:

     x = 9/0

except:

     vs.AlrtDialog('This is division by zero!')

 

 

Edited by Nik
to clarify post

Share this post


Link to post

Oh ok. You mean in another file? or the current document?

Share this post


Link to post

VS function's throw no exceptions. The errors are basically prints.

 

You can check a handle like a boolean to see if its valid:

if not vs.GetObject(SymName):
  # XXX error
  
 # If another obj type could have the name this might be saver:

kSymbol_Definition = 16

h = vs.GetObject(SymName)

if (vs.GetTypeN(h) != kSymbol_Definition):
  # XXX error
                 

 

Edited by PatW

Share this post


Link to post

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.


 

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.

×
×
  • Create New...