- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Dear Better Experienced Collegues,
I am having a serious issue attaching object data to an object. I am providing the tableName from another part of the program as a string, the name of the field which is being converted from a hashtable into the position of the field in the record [will change this later], and the value is coming from a combo box in a winform. Please note that I have locked the drawing early in this procedure, based on the information in a post I felt may have been related. I am not handling the exception as I am stepping through the code with VS2010 Expression for C#, but will handle any exceptions later. Just to be clear, I am using Autodesk Map 2011. Here is my c# (c sharp) code:
public static bool CommandAddData(string tableName, string updateField, string cmbValue)
{
Document dwg = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
using (DocumentLock lk = dwg.LockDocument())
{
Tables tables = HostMapApplicationServices.Application.ActiveProject.ODTables;
ObjectId[] selObjs = SLiiCGIS.GISFunctions.SelectionFunc.selectedObjects.Value.GetObjectIds();
// Get Application Level Table Definition for object data
Hashtable masterTableDef = SLiiCGIS.ApplicationVariables.tableDefinition;
if (selObjs.Length > 0)
{
foreach (ObjectId sel in selObjs)
{
Autodesk.Gis.Map.ObjectData.Table table = tables[tableName];
using (Records rcds = tables.GetObjectRecords(0, sel, Autodesk.Gis.Map.Constants.OpenMode.OpenForWrite, false))
if (rcds.Count == 0)
{
try
{
// Create and initialize an record
Autodesk.Gis.Map.ObjectData.Record tblRcd = Autodesk.Gis.Map.ObjectData.Record.Create();
table.InitRecord(tblRcd);
int tblPos = Convert.ToInt32(masterTableDef[updateField]);
MapValue val = tblRcd[tblPos]; // String type
val.Assign(cmbValue);
table.AddRecord(tblRcd, sel);
return true;
}
catch (MapException)
{
return false;
}
}
else
{
try
{
foreach (Autodesk.Gis.Map.ObjectData.Record tblRcd in rcds)
{
// Create and initialize an record
int tblPos = (int)masterTableDef[updateField];
MapValue val = tblRcd[tblPos]; // String type
val.Assign(cmbValue);
return true;
}
}
catch (MapException)
{
return false;
}
}
}
return true;
}
else
{
return false;
}
}
}
Almost directly out of the book (AutoCAD Map 3D SDK | ObjectARX .NET Developer's Guide | Object Data | Attaching Object Data). Any assistance would be greatly appreciated.
Solved! Go to Solution.