AutoCAD Map 3D Developer
Welcome to Autodesk’s AutoCAD Map 3D Developer Forums. Share your knowledge, ask questions, and explore popular AutoCAD Map 3D Developer topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

object data table create vba. but drop cadmap 3d program .

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
mirwing76
1667 Views, 4 Replies

object data table create vba. but drop cadmap 3d program .

mirwing76
Contributor
Contributor

The "autocad map 2017" program is killed.

 

make vba object data table .

 

Sub CreateODT()
Dim amap As AcadMap
Dim acadObj As Object
Dim ODfdfs As odFieldDefs
Dim ODfdf As ODFieldDef
Dim ODtb As odTable
Dim ODrc As odRecord

Set amap = ThisDrawing.Application.GetInterfaceObject("AutoCADMap.Application")

Set ODfdfs = amap.Projects(ThisDrawing).MapUtil.NewODFieldDefs
Set ODfdf = ODfdfs.Add("Entity", "Entity name", "", 0)
Set ODfdf = ODfdfs.Add("Color", "Object color", acRed, 1)
Set ODfdf = ODfdfs.Add("Layer", "Object layer", "0", 2)

If amap.Projects(ThisDrawing).ODTables.Item("SampleOD3") Is Nothing Then

Set ODtb = amap.Projects(ThisDrawing).ODTables.Add("SampleOD3", "Sample Xdata", ODfdfs, True)
Set ODrc = ODtb.CreateRecord
For Each acadObj In ThisDrawing.ModelSpace
    ODrc.Item(0).Value = acadObj.EntityName
    ODrc.Item(1).Value = acadObj.Color
    ODrc.Item(2).Value = acadObj.Layer
    ODrc.AttachTo (acadObj.ObjectID)
Next

End If

End Sub

 

 
Visual studio debugging.  Throw message 0x00007FFA48188283 (ntdll.dll) (acad.exe) Exception...........
 

0x00007FFA48188283(ntdll.dll) (acad.exe) 처리되지 않은 예외가 있습니다. 0xC0000374: 힙이 손상되었습니다(매개 변수: 0x00007FFA481DF6B0).

0 Likes

object data table create vba. but drop cadmap 3d program .

The "autocad map 2017" program is killed.

 

make vba object data table .

 

Sub CreateODT()
Dim amap As AcadMap
Dim acadObj As Object
Dim ODfdfs As odFieldDefs
Dim ODfdf As ODFieldDef
Dim ODtb As odTable
Dim ODrc As odRecord

Set amap = ThisDrawing.Application.GetInterfaceObject("AutoCADMap.Application")

Set ODfdfs = amap.Projects(ThisDrawing).MapUtil.NewODFieldDefs
Set ODfdf = ODfdfs.Add("Entity", "Entity name", "", 0)
Set ODfdf = ODfdfs.Add("Color", "Object color", acRed, 1)
Set ODfdf = ODfdfs.Add("Layer", "Object layer", "0", 2)

If amap.Projects(ThisDrawing).ODTables.Item("SampleOD3") Is Nothing Then

Set ODtb = amap.Projects(ThisDrawing).ODTables.Add("SampleOD3", "Sample Xdata", ODfdfs, True)
Set ODrc = ODtb.CreateRecord
For Each acadObj In ThisDrawing.ModelSpace
    ODrc.Item(0).Value = acadObj.EntityName
    ODrc.Item(1).Value = acadObj.Color
    ODrc.Item(2).Value = acadObj.Layer
    ODrc.AttachTo (acadObj.ObjectID)
Next

End If

End Sub

 

 
Visual studio debugging.  Throw message 0x00007FFA48188283 (ntdll.dll) (acad.exe) Exception...........
 

0x00007FFA48188283(ntdll.dll) (acad.exe) 처리되지 않은 예외가 있습니다. 0xC0000374: 힙이 손상되었습니다(매개 변수: 0x00007FFA481DF6B0).

4 REPLIES 4
Message 2 of 5
norman.yuan
in reply to: mirwing76

norman.yuan
Mentor
Mentor
Accepted solution

Have you stepped through the code to determine which line of code causes AutoCAD Map crashing?

 

Usually, exception in VBA code only stops VBA code execution and rarely crashes AutoCAD itself. However, in the case of AutoCAD Map functionality, this could happen.

 

If you had stepped through the code in debugging, you would have easily found the defect in your code at this line:

 

If amap.Projects(ThisDrawing).ODTables.Item("SampleOD3") Is Nothing Then...

 

will never work. If there is no ODTable called "SampleOD3" exists, the code ...OdTable.Item("SampleOD3") errors, because there is no item in the collection with key "SampleOD3".

 

You should loop through the ODTables collection to see if a table with the name exists. If not, you go ahead to create one with that name. See following code:

 

Option Explicit

Public Sub CreateOdTable()

    Dim amap As AutocadMAP.AcadMap
    Dim proj As AutocadMAP.Project
    Dim acadObj As Object
    Dim ODfdfs As AutocadMAP.ODFieldDefs
    Dim ODfdf As AutocadMAP.ODFieldDef
    Dim ODtb As AutocadMAP.ODTable
    Dim ODrc As AutocadMAP.ODRecord
    
    Set amap = ThisDrawing.Application.GetInterfaceObject("AutoCADMap.Application")
    Set proj = amap.Projects(ThisDrawing)
    
    Set ODfdfs = amap.Projects(ThisDrawing).MapUtil.NewODFieldDefs
    ODfdfs.Add "Entity", "Entity name", "", 0
    ODfdfs.Add "Color", "Object color", acRed, 1
    ODfdfs.Add "Layer", "Object layer", "0", 2
    
    If Not HasTable(proj, "SampleOD3") Then
        Set ODtb = amap.Projects(ThisDrawing).ODTables.Add("SampleOD3", "Sample Xdata", ODfdfs, True)
    Else
        Set ODtb = proj.ODTables.Item("SampleOD3")
    End If
    
    ''Attach ODrecord to entities here

End Sub

Private Function HasTable(proj As AutocadMAP.Project, tblName As String) As Boolean
    Dim tbl As AutocadMAP.ODTable
    For Each tbl In proj.ODTables
        If UCase(tbl.Name) = UCase(tblName) Then
            HasTable = True
            Exit Function
        End If
    Next
    HasTable = False
End Function

HTH

 

 

 

 

 

Norman Yuan

Drive CAD With Code

EESignature

Have you stepped through the code to determine which line of code causes AutoCAD Map crashing?

 

Usually, exception in VBA code only stops VBA code execution and rarely crashes AutoCAD itself. However, in the case of AutoCAD Map functionality, this could happen.

 

If you had stepped through the code in debugging, you would have easily found the defect in your code at this line:

 

If amap.Projects(ThisDrawing).ODTables.Item("SampleOD3") Is Nothing Then...

 

will never work. If there is no ODTable called "SampleOD3" exists, the code ...OdTable.Item("SampleOD3") errors, because there is no item in the collection with key "SampleOD3".

 

You should loop through the ODTables collection to see if a table with the name exists. If not, you go ahead to create one with that name. See following code:

 

Option Explicit

Public Sub CreateOdTable()

    Dim amap As AutocadMAP.AcadMap
    Dim proj As AutocadMAP.Project
    Dim acadObj As Object
    Dim ODfdfs As AutocadMAP.ODFieldDefs
    Dim ODfdf As AutocadMAP.ODFieldDef
    Dim ODtb As AutocadMAP.ODTable
    Dim ODrc As AutocadMAP.ODRecord
    
    Set amap = ThisDrawing.Application.GetInterfaceObject("AutoCADMap.Application")
    Set proj = amap.Projects(ThisDrawing)
    
    Set ODfdfs = amap.Projects(ThisDrawing).MapUtil.NewODFieldDefs
    ODfdfs.Add "Entity", "Entity name", "", 0
    ODfdfs.Add "Color", "Object color", acRed, 1
    ODfdfs.Add "Layer", "Object layer", "0", 2
    
    If Not HasTable(proj, "SampleOD3") Then
        Set ODtb = amap.Projects(ThisDrawing).ODTables.Add("SampleOD3", "Sample Xdata", ODfdfs, True)
    Else
        Set ODtb = proj.ODTables.Item("SampleOD3")
    End If
    
    ''Attach ODrecord to entities here

End Sub

Private Function HasTable(proj As AutocadMAP.Project, tblName As String) As Boolean
    Dim tbl As AutocadMAP.ODTable
    For Each tbl In proj.ODTables
        If UCase(tbl.Name) = UCase(tblName) Then
            HasTable = True
            Exit Function
        End If
    Next
    HasTable = False
End Function

HTH

 

 

 

 

 

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 5
nick.seman
in reply to: norman.yuan

nick.seman
Advocate
Advocate

Hello

 

Thanks for posting this, it is very helpful.

 

One question - do you know why it fails if the ODTable exists (in Map 2019) ?

 

  Failure occurs here-> Set ODtb = proj.ODTables.Item("SampleOD3")

 

Map simply crashes and exits.

 

Thanks;

Nick

0 Likes

Hello

 

Thanks for posting this, it is very helpful.

 

One question - do you know why it fails if the ODTable exists (in Map 2019) ?

 

  Failure occurs here-> Set ODtb = proj.ODTables.Item("SampleOD3")

 

Map simply crashes and exits.

 

Thanks;

Nick

Message 4 of 5
norman.yuan
in reply to: nick.seman

norman.yuan
Mentor
Mentor

Currently all my Object data programming uses MAP's .NET API, and I have not done Object data COM API (VBA) in production for many years. But since Map's .NET API and COM API both are built on top of MAP ObjectARX, I have been seeing the same issuer as you described in last a few AutoCAD Map versions (that is, accessing a known existing ODTable via Map project's ODTable collection). This issue seemed started since AcadMap 2015

 

It seems related to how you get the AcadMap and/or Project object prior to access the ODTables property. Since you did not show the whole code of yours, I assume you create AcadMap at once with GetInterfaceObject(), and get the Project object as global/public variable and use it through the entire process. 

 

To solve this issue, you may obtain the Project object from AcadMap.Projects and assign it to a local variable whenever you need to do something with object data in a drawing. I had to modify some of my code that had worked well before until running into this issue. This would slow down the access quite noticeable, but I found this this the only way to work around the said problem. My guess is that a quite significant change in AutoCAD 2015 (removing Fibre, the direct impact of it is switch active document would cancel active command) could be the cause of this issue, and Autodesk would not have a fix in near future or forever.

 

Also, unless you have to maintain existing VBA code on object data, I'd suggest not waste more time on VBA, move on to .NET API.

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes

Currently all my Object data programming uses MAP's .NET API, and I have not done Object data COM API (VBA) in production for many years. But since Map's .NET API and COM API both are built on top of MAP ObjectARX, I have been seeing the same issuer as you described in last a few AutoCAD Map versions (that is, accessing a known existing ODTable via Map project's ODTable collection). This issue seemed started since AcadMap 2015

 

It seems related to how you get the AcadMap and/or Project object prior to access the ODTables property. Since you did not show the whole code of yours, I assume you create AcadMap at once with GetInterfaceObject(), and get the Project object as global/public variable and use it through the entire process. 

 

To solve this issue, you may obtain the Project object from AcadMap.Projects and assign it to a local variable whenever you need to do something with object data in a drawing. I had to modify some of my code that had worked well before until running into this issue. This would slow down the access quite noticeable, but I found this this the only way to work around the said problem. My guess is that a quite significant change in AutoCAD 2015 (removing Fibre, the direct impact of it is switch active document would cancel active command) could be the cause of this issue, and Autodesk would not have a fix in near future or forever.

 

Also, unless you have to maintain existing VBA code on object data, I'd suggest not waste more time on VBA, move on to .NET API.

 

Norman Yuan

Drive CAD With Code

EESignature

Message 5 of 5
nick.seman
in reply to: norman.yuan

nick.seman
Advocate
Advocate

Thank you for the reply. 

 

>> I'd suggest not waste more time on VBA, move on to .NET API <<

 

I agree!

 

Nick

0 Likes

Thank you for the reply. 

 

>> I'd suggest not waste more time on VBA, move on to .NET API <<

 

I agree!

 

Nick

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report