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: 

Exception When trying to create a MAP ODTable

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
lmorse
1180 Views, 6 Replies

Exception When trying to create a MAP ODTable

lmorse
Contributor
Contributor

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);
                }                
            }       

 

 

 

0 Likes

Exception When trying to create a MAP ODTable

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);
                }                
            }       

 

 

 

Tags (1)
6 REPLIES 6
Message 2 of 7
fieldguy
in reply to: lmorse

fieldguy
Advisor
Advisor

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);

0 Likes

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);

Message 3 of 7
lmorse
in reply to: lmorse

lmorse
Contributor
Contributor

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);
                }

 

0 Likes

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);
                }

 

Message 4 of 7
lmorse
in reply to: lmorse

lmorse
Contributor
Contributor

I was basing my code on a VBA example that I found.

0 Likes

I was basing my code on a VBA example that I found.

Message 5 of 7
lmorse
in reply to: lmorse

lmorse
Contributor
Contributor

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);
0 Likes

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);
Message 6 of 7
fieldguy
in reply to: lmorse

fieldguy
Advisor
Advisor
Accepted solution

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 

0 Likes

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 

Message 7 of 7
lmorse
in reply to: fieldguy

lmorse
Contributor
Contributor

Genius! That worked. Thank you so much fieldguy.

0 Likes

Genius! That worked. Thank you so much fieldguy.

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

Post to forums  

Autodesk Design & Make Report