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
0x00007FFA48188283(ntdll.dll) (acad.exe) 처리되지 않은 예외가 있습니다. 0xC0000374: 힙이 손상되었습니다(매개 변수: 0x00007FFA481DF6B0).
Solved! Go to Solution.
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
0x00007FFA48188283(ntdll.dll) (acad.exe) 처리되지 않은 예외가 있습니다. 0xC0000374: 힙이 손상되었습니다(매개 변수: 0x00007FFA481DF6B0).
Solved! Go to Solution.
Solved by norman.yuan. Go to 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("SampleOD
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
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("SampleOD
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
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
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
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
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
Thank you for the reply.
>> I'd suggest not waste more time on VBA, move on to .NET API <<
I agree!
Nick
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.