Hi All,
I have been searching all day but cannot find any documentation or examples. I have been trying to create a MAP (Autocad Civil 3D) ODTable, but receive an exception. I believe I have a fundamental misunderstanding of how this should work.
Exception is:
"Error: System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.
at AcMapODColumnDefinition.{ctor}(AcMapODColumnDefinition* , Char* , EDataType , Char* )
at Autodesk.Gis.Map.ObjectData.FieldDefinition..ctor(String name, DataType dataType, String description)
at Autodesk.Gis.Map.ObjectData.FieldDefinitions.Add(String name, String description, DataType type, Int32 position)
at ReadDatabase.DBReader.ObjectDataTable() in C:\Users\lmorse\source\repos\ReadSurveyDatabase\ReadDatabase.cs:line 302" *
* Line 302 is the 'fields.Add("BOREHOLE NAME", "Borehole Name", Autodesk.Gis.Map.Constants.DataType.Character, 0);' line.
Here is a snippet of my code:
using Autodesk.Gis.Map.Project;
using Autodesk.Gis.Map;
using Autodesk.Gis.Map.ObjectData
......
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
ProjectModel projModel = HostMapApplicationServices.Application.Projects.GetProject(doc);
Tables odTables = HostMapApplicationServices.Application.ActiveProject.ODTables;
if (!projModel.ODTables.IsTableDefined("Borehole"))
{
try
{
FieldDefinitions fields = HostMapApplicationServices.Application.ActiveProject.MapUtility.NewODFieldDefinitions();
fields.Add("BOREHOLE NAME", "Borehole Name", Autodesk.Gis.Map.Constants.DataType.Character, 0);
odTables.Add("Borehole", fields, "Boreholes", true);
}
catch (System.Exception ex)
{
ed.WriteMessage("\nError: " + ex);
}
}
Solved! Go to Solution.
Hi All,
I have been searching all day but cannot find any documentation or examples. I have been trying to create a MAP (Autocad Civil 3D) ODTable, but receive an exception. I believe I have a fundamental misunderstanding of how this should work.
Exception is:
"Error: System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.
at AcMapODColumnDefinition.{ctor}(AcMapODColumnDefinition* , Char* , EDataType , Char* )
at Autodesk.Gis.Map.ObjectData.FieldDefinition..ctor(String name, DataType dataType, String description)
at Autodesk.Gis.Map.ObjectData.FieldDefinitions.Add(String name, String description, DataType type, Int32 position)
at ReadDatabase.DBReader.ObjectDataTable() in C:\Users\lmorse\source\repos\ReadSurveyDatabase\ReadDatabase.cs:line 302" *
* Line 302 is the 'fields.Add("BOREHOLE NAME", "Borehole Name", Autodesk.Gis.Map.Constants.DataType.Character, 0);' line.
Here is a snippet of my code:
using Autodesk.Gis.Map.Project;
using Autodesk.Gis.Map;
using Autodesk.Gis.Map.ObjectData
......
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
ProjectModel projModel = HostMapApplicationServices.Application.Projects.GetProject(doc);
Tables odTables = HostMapApplicationServices.Application.ActiveProject.ODTables;
if (!projModel.ODTables.IsTableDefined("Borehole"))
{
try
{
FieldDefinitions fields = HostMapApplicationServices.Application.ActiveProject.MapUtility.NewODFieldDefinitions();
fields.Add("BOREHOLE NAME", "Borehole Name", Autodesk.Gis.Map.Constants.DataType.Character, 0);
odTables.Add("Borehole", fields, "Boreholes", true);
}
catch (System.Exception ex)
{
ed.WriteMessage("\nError: " + ex);
}
}
Solved! Go to Solution.
Solved by fieldguy. Go to Solution.
I would suspect "fields.Add" is the issue. Are you following an example from somewhere? There are several in this forum (search "fielddefinition").
I have similar code but I create a new "FieldDefinition", and add that to "FieldDefinitions", and then add the table.
Something like this:
ObjectData.FieldDefinitions tabdefs = mapprj.MapUtility.NewODFieldDefinitions();
ObjectData.FieldDefinition fd = ObjectData.FieldDefinition.Create(s, s, acgis.Constants.DataType.Character);
tabdefs.AddColumn(fd, findex);
tbls.Add(tname, tabdefs, tname, true);
I would suspect "fields.Add" is the issue. Are you following an example from somewhere? There are several in this forum (search "fielddefinition").
I have similar code but I create a new "FieldDefinition", and add that to "FieldDefinitions", and then add the table.
Something like this:
ObjectData.FieldDefinitions tabdefs = mapprj.MapUtility.NewODFieldDefinitions();
ObjectData.FieldDefinition fd = ObjectData.FieldDefinition.Create(s, s, acgis.Constants.DataType.Character);
tabdefs.AddColumn(fd, findex);
tbls.Add(tname, tabdefs, tname, true);
Hi fieldguy,
Thanks for your reply. I have adjusted my code to do something similar, but I still get an exception, this time on the "FieldDefinition fd = FieldDefinition.Create("BOREHOLE NAME", "Borehole Name", Autodesk.Gis.Map.Constants.DataType.Character);" line:
Error: System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.
at AcMapODColumnDefinition.{ctor}(AcMapODColumnDefinition* , Char* , EDataType , Char* )
at Autodesk.Gis.Map.ObjectData.FieldDefinition..ctor(String name, DataType dataType, String description)
at Autodesk.Gis.Map.ObjectData.FieldDefinition.Create(String name, String description, DataType type)
at ReadDatabase.DBReader.ObjectDataTable() in C:\Users\lmorse\source\repos\ReadSurveyDatabase\ReadDatabase.cs:line 302
Here is a code snippet of the new code:
try
{
FieldDefinitions fields = HostMapApplicationServices.Application.ActiveProject.MapUtility.NewODFieldDefinitions();
FieldDefinition fd = FieldDefinition.Create("BOREHOLE NAME", "Borehole Name", Autodesk.Gis.Map.Constants.DataType.Character);
fields.AddColumn(fd, 0);
odTables.Add("Borehole", fields, "Boreholes", true);
}
Hi fieldguy,
Thanks for your reply. I have adjusted my code to do something similar, but I still get an exception, this time on the "FieldDefinition fd = FieldDefinition.Create("BOREHOLE NAME", "Borehole Name", Autodesk.Gis.Map.Constants.DataType.Character);" line:
Error: System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.
at AcMapODColumnDefinition.{ctor}(AcMapODColumnDefinition* , Char* , EDataType , Char* )
at Autodesk.Gis.Map.ObjectData.FieldDefinition..ctor(String name, DataType dataType, String description)
at Autodesk.Gis.Map.ObjectData.FieldDefinition.Create(String name, String description, DataType type)
at ReadDatabase.DBReader.ObjectDataTable() in C:\Users\lmorse\source\repos\ReadSurveyDatabase\ReadDatabase.cs:line 302
Here is a code snippet of the new code:
try
{
FieldDefinitions fields = HostMapApplicationServices.Application.ActiveProject.MapUtility.NewODFieldDefinitions();
FieldDefinition fd = FieldDefinition.Create("BOREHOLE NAME", "Borehole Name", Autodesk.Gis.Map.Constants.DataType.Character);
fields.AddColumn(fd, 0);
odTables.Add("Borehole", fields, "Boreholes", true);
}
I found the following post from Norman.Yuan: https://forums.autodesk.com/t5/autocad-map-3d-developer/unable-to-set-default-value-in-odtable-throu...
Based on this I changed my code to the below, but still get an exception :
FieldDefinitions fields = HostMapApplicationServices.Application.ActiveProject.MapUtility.NewODFieldDefinitions();
var fld = FieldDefinition.Create("BOREHOLE NAME", "Borehole Name", "XXX");
fields.AddColumn(fld, 0);
I found the following post from Norman.Yuan: https://forums.autodesk.com/t5/autocad-map-3d-developer/unable-to-set-default-value-in-odtable-throu...
Based on this I changed my code to the below, but still get an exception :
FieldDefinitions fields = HostMapApplicationServices.Application.ActiveProject.MapUtility.NewODFieldDefinitions();
var fld = FieldDefinition.Create("BOREHOLE NAME", "Borehole Name", "XXX");
fields.AddColumn(fld, 0);
I just tried this and my guess is that field name does not accept spaces. I used your code and field name "BOREHOLE" and it worked.
I don't recall encountering this issue before, and cannot find documentation on OD field definition rules.
edit > I have never used the Add method of FieldDefinitions - it works as expected. I have always created a field def and used AddColumn
I just tried this and my guess is that field name does not accept spaces. I used your code and field name "BOREHOLE" and it worked.
I don't recall encountering this issue before, and cannot find documentation on OD field definition rules.
edit > I have never used the Add method of FieldDefinitions - it works as expected. I have always created a field def and used AddColumn
Genius! That worked. Thank you so much fieldguy.
Genius! That worked. Thank you so much fieldguy.
Can't find what you're looking for? Ask the community or share your knowledge.