How can I verify an ObjectId is valid in a drawing?

Discussion in 'AutoCAD' started by Dan, Dec 20, 2004.

  1. Dan

    Dan Guest

    /snip

    'Find an object from a given objectID
    Set tempObj = ThisDrawing.ObjectIdToObject(newObjsString)
    /snip

    This is a line I have in my code, it works great if the ObjectId is valid,
    but if it is not, AutoCAD creates a Fatal Error, and crashes.

    If I have a ObjectId number, how can verify it is valid without AutoCAD
    crashing?

    Thanks again all,
    Dan
     
    Dan, Dec 20, 2004
    #1
  2. Dan

    VBA Guest

    Are you using an "On Error Goto" construct?
     
    VBA, Dec 20, 2004
    #2
  3. Dan

    Dan Guest

    Yes I am: On Error GoTo Err_Control
    Dan
     
    Dan, Dec 20, 2004
    #3
  4. Dan

    Jorge Lopez Guest

    Why are you trying to determine if an ObjectID is valid? Are you storing the
    ObjectID in a database for later retrieval? ObjectIDs are transient and not
    persistent between drawing loads. I can look into how to do this but first I
    want to make sure you aren't trying to do something you should not be doing.

    Handles are persistent between drawing loads btw.

    Cheers,

    Jorge
     
    Jorge Lopez, Dec 20, 2004
    #4
  5. AutoCAD shouldn't crash if you give ObjectIDToObject() an invalid
    object id. But, your code below suggests you're passing a string
    into the method. Are you?

    Why would you need to verify if an object id is valid? If an object
    is erased (or unappeneded), its object id is still valid, but this
    method will generate an error nontheless.

    Step back and tell us what the purpose of validating the object id is.
     
    Tony Tanzillo, Dec 20, 2004
    #5
  6. Dan

    Dan Guest

    Thanks for the assistance....
    The purpose is to create a Field mapping tool.

    Purpose is simply this:

    There is a defined field that needs to be modified.
    How does the user know where the parent of that field resides?

    Solution/Tool

    I have written some code to prompt the user to select desired field, then
    the code reads the field expression,
    then zooms to the Objectid in the expression and highlights it for the user,
    for the user to make necessary modifications.


    Odd thing as stated in a previous post, it works great, but there is some
    anomily that can give the wrong objectid.
    (See "What's wrong in code? Get Field Expression Tool thread")

    If Objectid provided is not a valid ID, AutoCAD will crash when I get to
    this line:
    Set tempObj = ThisDrawing.ObjectIdToObject(newObjsString)

    Thanks,
    Dan

    :
     
    Dan, Dec 21, 2004
    #6
  7. Per chance, are you using object ids that have small values?

    This is a known problem. In some cases, the object referenced
    by the object id is valid, but has no COM/ActiveX representation
    or wrapper object, and I'm pretty sure that this may cause
    the crash.
     
    Tony Tanzillo, Dec 21, 2004
    #7
  8. Dan

    Dan Guest

    still no ideas....?

     
    Dan, Dec 29, 2004
    #8
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.