Jump to content

Using try/except


Nik

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

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

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
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...