Results 1 to 8 of 8

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

  1. #1
    Dan Guest

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

    /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

  2. #2
    VBA Guest
    Are you using an "On Error Goto" construct?

    "Dan" <danderson@nospamculpandtanner.com> wrote in message
    news:41c716b4$1_2@newsprd01...
    /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

  3. #3
    Dan Guest
    Yes I am: On Error GoTo Err_Control
    Dan
    "VBA" <nospam@nowhere.com> wrote in message news:41c7294e$1_3@newsprd01...
    Are you using an "On Error Goto" construct?

    "Dan" <danderson@nospamculpandtanner.com> wrote in message
    news:41c716b4$1_2@newsprd01...
    /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



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


    "Dan" <danderson@nospamculpandtanner.com> wrote in message
    news:41c716b4$1_2@newsprd01...
    /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

  5. #5
    Tony Tanzillo Guest
    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.

    --
    http://www.caddzone.com

    AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005
    http://www.acadxtabs.com

    "Dan" <danderson@nospamculpandtanner.com> wrote in message news:41c716b4$1_2@newsprd01...
    /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

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

    :

    "Tony Tanzillo" <tony.tanzillo@U_KNOW_WHERE.com> wrote in message
    news:41c75a84$1_3@newsprd01...
    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.

    --
    http://www.caddzone.com

    AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005
    http://www.acadxtabs.com

    "Dan" <danderson@nospamculpandtanner.com> wrote in message
    news:41c716b4$1_2@newsprd01...
    /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



  7. #7
    Tony Tanzillo Guest
    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.

    --
    http://www.caddzone.com

    AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005
    http://www.acadxtabs.com

    "Dan" <danderson@nospamculpandtanner.com> wrote in message news:41c776f5$1_3@newsprd01...
    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

    :

    "Tony Tanzillo" <tony.tanzillo@U_KNOW_WHERE.com> wrote in message
    news:41c75a84$1_3@newsprd01...
    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.

    --
    http://www.caddzone.com

    AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005
    http://www.acadxtabs.com

    "Dan" <danderson@nospamculpandtanner.com> wrote in message
    news:41c716b4$1_2@newsprd01...
    /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





  8. #8
    Dan Guest
    still no ideas....?

    "Dan" <danderson@nospamculpandtanner.com> wrote in message
    news:41c85c70_2@newsprd01...
    It looks like an ordinary id to me.

    Here was my test:
    I copied problematic text and field: "Test3"
    Text ObjID = 2130161576



    USING THE CODE (GetFieldExpression) PROVIDED,
    Sub GetFieldExpression()
    Dim ssetObj As AcadSelectionSet
    Dim point1(0 To 2) As Double
    Dim point2(0 To 2) As Double
    Dim entText As AcadObject
    Dim vPt As Variant
    Dim text As String
    Tag
    On Error GoTo Err_Control

    ' Sub ???Not sure why TextObj needs to be present to work, delete after
    Dim textObj As IAcadText2
    Dim insertionPoint(0 To 2) As Double
    Dim Height As Double
    text = "%<\AcVar Date \f ""M/d/yyyy""%>%"
    insertionPoint(0) = 2000000: insertionPoint(1) = 2000000:
    insertionPoint(2)
    = 0
    Height = 0.5
    Set textObj = ThisDrawing.ModelSpace.AddText(text, insertionPoint, Height)

    'acSelectionSetLast
    ThisDrawing.Application.ZoomAll
    Set ssetObj = ThisDrawing.SelectionSets.Add("deletelast")
    ssetObj.Select acSelectionSetLast
    'MsgBox ("Selection set " & ssetObj.Name & " contains " & ssetObj.Count &
    "
    items")

    text = textObj.FieldCode
    UserForm3.Hide
    ThisDrawing.Application.ZoomPrevious
    ThisDrawing.Utility.GetEntity entText, vPt, vbCr & "Pick a FIELD in
    drawing:"
    text = entText.FieldCode
    UserForm3.TextBox1 = text
    ThisDrawing.Application.ZoomAll

    ' Erase the objects in the selection set
    ssetObj.Erase

    ThisDrawing.Application.ZoomPrevious
    UserForm3.Show
    ThisDrawing.SelectionSets.Item("deletelast").Delet e
    Exit_Here:
    Exit Sub
    Err_Control:
    MsgBox "This OBJECT FIELD Entity's Expression could not be found. " &
    vbCrLf
    & "Verify it is not inside a dimension or table.", vbOKOnly + vbQuestion,
    "CT-Error"
    ssetObj.Erase
    ThisDrawing.SelectionSets.Item("deletelast").Delet e
    Exit Sub
    End Sub


    WITH THIS FIELD I GET:

    %<\AcObjProp Object(2117824080).TextString \f "%bl2">%

    Notice, "2117824080" is not the correct Objectid and I cant figure out
    why?


    I created a new field linked to the text, and it works properly:

    USING THE CODE (GetFieldExpression) PROVIDED,
    WITH THIS FIELD I GET:
    %<\AcObjProp Object(2130161576).TextString \f %bl2>%
    IF YOU USE THE CODE (MapField) ON THIS FIELD, YOU WILL GET
    A FATAL ERROR, AND AUTOCAD WILL CRASH.

    ????

    This works well, but when ACAD comes across a bad objectid, a complete
    crash
    does nobady any good.
    So I was hoping to build in some kind of verification first, or at least
    figure out why.

    Thankd,
    Dan


    "Tony Tanzillo" <tony.tanzillo@U_KNOW_WHERE.com> wrote in message
    news:41c797fd$1_3@newsprd01...
    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.

    --
    http://www.caddzone.com

    AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005
    http://www.acadxtabs.com

    "Dan" <danderson@nospamculpandtanner.com> wrote in message
    news:41c776f5$1_3@newsprd01...
    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

    :

    "Tony Tanzillo" <tony.tanzillo@U_KNOW_WHERE.com> wrote in message
    news:41c75a84$1_3@newsprd01...
    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.

    --
    http://www.caddzone.com

    AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005
    http://www.acadxtabs.com

    "Dan" <danderson@nospamculpandtanner.com> wrote in message
    news:41c716b4$1_2@newsprd01...
    /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










Similar Threads

  1. plotStyle() isn' valid for Wavescan.
    By pancho_hideboo in forum Cadence
    Replies: 0
    Last Post: 11-18-2006, 08:15 AM
  2. Replies: 1
    Last Post: 09-23-2005, 01:29 PM
  3. Excel loses its formulas after verify
    By T Bennett in forum Pro/Engineer
    Replies: 3
    Last Post: 04-27-2005, 05:10 PM
  4. verify if dwg was saved
    By Hunter van Leeuwen in forum Customization
    Replies: 10
    Last Post: 03-30-2005, 08:47 PM
  5. PC3 files not valid
    By CathyG in forum Printing
    Replies: 2
    Last Post: 02-07-2005, 10:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other forums: Access Forum - Microsoft Office Forum - Exchange Server Forum