<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Error while transferring Object Data in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/error-while-transferring-object-data/m-p/11523021#M11128</link>
    <description>&lt;P&gt;your post belongs in the Map Developer forum again.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you provide test data? a dwg file with some points with object data and the block definition "NBN_TPT"?&lt;/P&gt;&lt;P&gt;my guess is the error is in "OdUtils.getFieldValue".&amp;nbsp; Set a breakpoint there and check the value of&amp;nbsp;IList&amp;lt;string&amp;gt; data; &amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 01 Nov 2022 14:37:14 GMT</pubDate>
    <dc:creator>fieldguy</dc:creator>
    <dc:date>2022-11-01T14:37:14Z</dc:date>
    <item>
      <title>Error while transferring Object Data</title>
      <link>https://forums.autodesk.com/t5/net-forum/error-while-transferring-object-data/m-p/11519584#M11127</link>
      <description>&lt;P&gt;I have a MapInfo (.MIF) file, was able to successfully import into AutoCAD Map 3D 2015 using&amp;nbsp;Autodesk.Gis.Map.ImportExport.Importer import = app.Application.Importer; along with Object Data. The features were imported as point features. I have to insert an attribute block for each point feature and need to transfer the Object Data and then need to update the Attribute data from Object Data and getting the following exception "&lt;STRONG&gt;Exception of type 'Autodesk.Gis.Map.MapException' was thrown"&lt;/STRONG&gt;. I have attached the class file and the exception log as an attachment and request for help. Please also let me know for any other information.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2022 05:36:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/error-while-transferring-object-data/m-p/11519584#M11127</guid>
      <dc:creator>subash.nalla</dc:creator>
      <dc:date>2022-11-02T05:36:30Z</dc:date>
    </item>
    <item>
      <title>Re: Error while transferring Object Data</title>
      <link>https://forums.autodesk.com/t5/net-forum/error-while-transferring-object-data/m-p/11523021#M11128</link>
      <description>&lt;P&gt;your post belongs in the Map Developer forum again.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you provide test data? a dwg file with some points with object data and the block definition "NBN_TPT"?&lt;/P&gt;&lt;P&gt;my guess is the error is in "OdUtils.getFieldValue".&amp;nbsp; Set a breakpoint there and check the value of&amp;nbsp;IList&amp;lt;string&amp;gt; data; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Nov 2022 14:37:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/error-while-transferring-object-data/m-p/11523021#M11128</guid>
      <dc:creator>fieldguy</dc:creator>
      <dc:date>2022-11-01T14:37:14Z</dc:date>
    </item>
    <item>
      <title>Re: Error while transferring Object Data</title>
      <link>https://forums.autodesk.com/t5/net-forum/error-while-transferring-object-data/m-p/11523335#M11129</link>
      <description>&lt;P&gt;The error logs in your attachment is useless without knowing which line of the code causes it. Have you actually step through your code in debugging to identify which line of code raises the exception? You really should post relevant code and point out the offending line so other can at least has a focus point to respond from; instead of place all the code in an attachment and let others to guess where things could go wrong (not to mention, downloading/opening attachment from an open forum/unknown source could be potentially harmful, many people may just ignore it).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With that said, I did "take an unknown risk" and quickly browsed your code in the class "OdUtils" and spotted bad code in the transferObjectData() method:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You do not need to start a Transaction to read OD data from an entity, nor to add OD data to an entity. AutoCAD Map does it for you: OdTables.GetObjectRecords()/odTable.AddRecord() both take entity's ObjectId as input, not an opened Entity. That is, the 2 methods open Transaction inside as needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code explicitly starts a Transaction, and worse, open the 2 entities (one for reading OD from , the other for writing OD to) for WRITE. I think this is the source of the error: because of these 2 entities have been opened for writing, the further odTable.AddRecord() call cannot write OD data to the target entity with its own transaction inside.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Nov 2022 16:32:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/error-while-transferring-object-data/m-p/11523335#M11129</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2022-11-01T16:32:29Z</dc:date>
    </item>
    <item>
      <title>Re: Error while transferring Object Data</title>
      <link>https://forums.autodesk.com/t5/net-forum/error-while-transferring-object-data/m-p/11524489#M11130</link>
      <description>Thank you for the reply and suggestions. I will attach the files as suggested. I have used this "OdUtils.getFieldValue" method in the same solution for other features (polylines and lines from .MIF File) and didn't get any issue. I am not aware how to move this post to Map Developer forum.</description>
      <pubDate>Wed, 02 Nov 2022 04:37:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/error-while-transferring-object-data/m-p/11524489#M11130</guid>
      <dc:creator>subash.nalla</dc:creator>
      <dc:date>2022-11-02T04:37:06Z</dc:date>
    </item>
    <item>
      <title>Re: Error while transferring Object Data</title>
      <link>https://forums.autodesk.com/t5/net-forum/error-while-transferring-object-data/m-p/11524510#M11131</link>
      <description>&lt;P&gt;Hi Thank you for your valuable suggestions will definitely follow them.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;I have attached the error logs file as it got generated after the execution and thought it might help for analyzing.&lt;/LI&gt;&lt;LI&gt;I have debugged a lot and the exception is not consistent sometimes the it is occurring in using (Records odRecords = odTables.GetObjectRecords(0, sourceObjId, Autodesk.Gis.Map.Constants.OpenMode.OpenForRead, false)) line in transferObjectData method Sometimes in Records tblRecords = tbl.GetObjectTableRecords(0, dbObj, Autodesk.Gis.Map.Constants.OpenMode.OpenForRead, true); line in getFieldValue method.&lt;/LI&gt;&lt;LI&gt;I will remove the start transaction in transferObjectData() method as suggested.&lt;/LI&gt;&lt;LI&gt;The same method is working fine across the solution for other features.&lt;/LI&gt;&lt;/OL&gt;</description>
      <pubDate>Wed, 02 Nov 2022 04:58:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/error-while-transferring-object-data/m-p/11524510#M11131</guid>
      <dc:creator>subash.nalla</dc:creator>
      <dc:date>2022-11-02T04:58:27Z</dc:date>
    </item>
    <item>
      <title>Re: Error while transferring Object Data</title>
      <link>https://forums.autodesk.com/t5/net-forum/error-while-transferring-object-data/m-p/11524560#M11132</link>
      <description>&lt;P&gt;I changed my method like this and still getting the exception, please suggest me where I am going wrong. I got the exception while doing .AddRecord() method.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;public static void transferObjectData(ObjectId sourceObjId, ObjectId targetObjId)&lt;BR /&gt;{&lt;BR /&gt;Database db = HostApplicationServices.WorkingDatabase;&lt;BR /&gt;Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.GetDocument(db);&lt;BR /&gt;using (DocumentLock docLk = doc.LockDocument())&lt;BR /&gt;{&lt;BR /&gt;//using (Transaction actr = db.TransactionManager.StartTransaction())&lt;BR /&gt;//{&lt;BR /&gt;//Entity srcEnt = (Entity)actr.GetObject(sourceObjId, OpenMode.ForWrite);&lt;BR /&gt;//Entity trgEnt = (Entity)actr.GetObject(targetObjId, OpenMode.ForWrite);&lt;BR /&gt;MapApplication mapApp = HostMapApplicationServices.Application;&lt;BR /&gt;Tables odTables = mapApp.ActiveProject.ODTables;&lt;BR /&gt;if (odTables.TablesCount == 0)&lt;BR /&gt;{&lt;BR /&gt;//actr.Commit();&lt;BR /&gt;return;&lt;BR /&gt;}&lt;BR /&gt;try&lt;BR /&gt;{&lt;BR /&gt;//using (Records odRecords = odTables.GetObjectRecords(0, sourceObjId, Autodesk.Gis.Map.Constants.OpenMode.OpenForWrite, false))&lt;BR /&gt;using (Records odRecords = odTables.GetObjectRecords(0, sourceObjId, Autodesk.Gis.Map.Constants.OpenMode.OpenForRead, false))&lt;BR /&gt;{&lt;BR /&gt;if (odRecords.Count &amp;gt; 0)&lt;BR /&gt;{&lt;BR /&gt;foreach (Record odRecord in odRecords)&lt;BR /&gt;{&lt;BR /&gt;Autodesk.Gis.Map.ObjectData.Table odTable = odTables[odRecord.TableName];&lt;BR /&gt;odTable.AddRecord(odRecord, targetObjId);&lt;BR /&gt;//actr.Commit();&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;catch (Autodesk.Gis.Map.MapException ex)&lt;BR /&gt;{&lt;BR /&gt;MessageBox.Show(ex.Message.ToString(), "NBN Map Import", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);&lt;BR /&gt;}&lt;BR /&gt;//}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2022 05:46:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/error-while-transferring-object-data/m-p/11524560#M11132</guid>
      <dc:creator>subash.nalla</dc:creator>
      <dc:date>2022-11-02T05:46:29Z</dc:date>
    </item>
    <item>
      <title>Re: Error while transferring Object Data</title>
      <link>https://forums.autodesk.com/t5/net-forum/error-while-transferring-object-data/m-p/11525107#M11133</link>
      <description>&lt;P&gt;Hi we can have a Google meet meeting to look into the issue if possible for you.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2022 11:02:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/error-while-transferring-object-data/m-p/11525107#M11133</guid>
      <dc:creator>subash.nalla</dc:creator>
      <dc:date>2022-11-02T11:02:49Z</dc:date>
    </item>
    <item>
      <title>Re: Error while transferring Object Data</title>
      <link>https://forums.autodesk.com/t5/net-forum/error-while-transferring-object-data/m-p/11525492#M11134</link>
      <description>&lt;P&gt;Well, I did not go through your code line by line, just a quick browsing. By the way, when posting code here, please use the "&amp;lt;/&amp;gt;" button of the toolbar (above the message window while you are entering your message), so that the code is formatted read-friendly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The other obvious error in your code is to add an existing OD record retrieved from source entity to another entity (target entity). You cannot do that. You need to create a &lt;STRONG&gt;NEW&lt;/STRONG&gt; OD record, set its values with the values obtained from the source entity's record (note: values!, not record!).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Following are code samples to copy OD data from one entity to another. Note, this is an extension method.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;public static void CopyObjectDataFrom(this ObjectId entId, ObjectId sourceEntId, ProjectModel mapProj = null)
        {
            var dicData = sourceEntId.RetrieveObjectDataFromEntity(mapProj);
            if (dicData.Count == 0) return;

            Autodesk.Gis.Map.ObjectData.Tables tables = null;

            if (mapProj == null) mapProj = HostMapApplicationServices.Application.ActiveProject;
            tables = mapProj.ODTables;

            foreach (var item in dicData)
            {
                if (!mapProj.ODTables.IsTableDefined(item.Key)) continue;

                using (var table = mapProj.ODTables[item.Key])
                {
                    var fldDefs = table.FieldDefinitions;
                    using (var record = Record.Create())
                    {
                        table.InitRecord(record);

                        for (int i = 0; i &amp;lt; fldDefs.Count; i++)
                        {
                            string fldName = fldDefs[i].Name;
                            OdField odFld = FindOdField(item.Value, fldName);
                            if (odFld == null) continue;

                            MapValue mapVal = record[i];

                            switch (odFld.DataType)
                            {
                                case Map.Constants.DataType.Character:
                                    mapVal.Assign(odFld.FieldValue.ToString());
                                    break;
                                case Map.Constants.DataType.Integer:
                                    mapVal.Assign(Convert.ToInt32(odFld.FieldValue));
                                    break;
                                case Map.Constants.DataType.Real:
                                    mapVal.Assign(Convert.ToDouble(odFld.FieldValue));
                                    break;
                                case Map.Constants.DataType.Point:
                                    mapVal.Assign((Point3d)odFld.FieldValue);
                                    break;
                            }
                        }

                        table.AddRecord(record, entId);
                    }
                }
            }


            //if (tables != null) tables.Dispose();
            //if (mapProj != null) mapProj.Dispose();
        }&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is the method RetrieveObjectDataFromEntity() used in above code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;public static Dictionary&amp;lt;string, IEnumerable&amp;lt;OdField&amp;gt;&amp;gt; RetrieveObjectDataFromEntity(this ObjectId entId, ProjectModel mapProj = null)
        {
            var dic = new Dictionary&amp;lt;string, IEnumerable&amp;lt;OdField&amp;gt;&amp;gt;();

            if (mapProj == null) mapProj = HostMapApplicationServices.Application.GetProjectForDB(entId.Database);

                var tables = mapProj.ODTables;
                if (tables.TablesCount &amp;gt; 0)
                {
                    using (Records records = tables.GetObjectRecords(0, entId, Map.Constants.OpenMode.OpenForRead, true))
                    {
                        if (records.Count &amp;gt; 0)
                        {
                            string tName = "";

                            try
                            {
                                foreach (Record record in records)
                                {
                                    tName = record.TableName;
                                    if (!tables.IsTableDefined(tName)) continue;

                                    var table = tables[tName];
                                    var fields = GetOdRecordData(record, table);

                                    dic.Add(tName, fields);
                                }
                            }
                            catch (Map.MapException ex)
                            {
                                string err = ((Map.Constants.ErrorCode)ex.ErrorCode).ToString();
                                throw new ApplicationException(
                                    "Cannot reach object data record!");
                            }
                        }
                    }
                }

            return dic;
        }&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, this is the class OdField used in above code:&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;public class OdField
    {
        public string FieldName { set; get; }
        public object FieldValue { set; get; }
        public Map.Constants.DataType DataType { set; get; }

        public string StringValue
        {
            get
            {
                string ret = "";
                if (FieldValue != null)
                {
                    switch (DataType)
                    {
                        case Map.Constants.DataType.Character:
                            ret = FieldValue.ToString();
                            break;
                        case Map.Constants.DataType.Integer:
                            ret = ((int)FieldValue).ToString();
                            break;
                        case Map.Constants.DataType.Real:
                            ret = ((double)FieldValue).ToString();
                            break;
                        case Map.Constants.DataType.Point:
                            ret = ((Point3d)FieldValue).ToString();
                            break;
                    }
                }

                return ret;
            }
        }
    }&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HTH&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2022 13:36:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/error-while-transferring-object-data/m-p/11525492#M11134</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2022-11-02T13:36:05Z</dc:date>
    </item>
    <item>
      <title>Re: Error while transferring Object Data</title>
      <link>https://forums.autodesk.com/t5/net-forum/error-while-transferring-object-data/m-p/11525618#M11135</link>
      <description>&lt;P&gt;Hi I think&amp;nbsp;FindOdField and GetOdRecordData methods are missing in the code.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2022 14:13:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/error-while-transferring-object-data/m-p/11525618#M11135</guid>
      <dc:creator>subash.nalla</dc:creator>
      <dc:date>2022-11-02T14:13:03Z</dc:date>
    </item>
    <item>
      <title>Re: Error while transferring Object Data</title>
      <link>https://forums.autodesk.com/t5/net-forum/error-while-transferring-object-data/m-p/11525675#M11136</link>
      <description>&lt;P&gt;OK, here they are:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;private static List&amp;lt;OdField&amp;gt; GetOdRecordData(Record record, Map.ObjectData.Table table)
        {
            var lst = new List&amp;lt;OdField&amp;gt;();

            for (int i = 0; i &amp;lt; record.Count; i++)
            {
                FieldDefinition fld = table.FieldDefinitions[i];
                string fldName = fld.Name;

                object fldVal;
                var val = record[i];
                switch (fld.Type)
                {
                    case Map.Constants.DataType.Character:
                        fldVal = val.StrValue;
                        break;
                    case Map.Constants.DataType.Integer:
                        fldVal = val.Int32Value;
                        break;
                    case Map.Constants.DataType.Real:
                        fldVal = val.DoubleValue;
                        break;
                    case Map.Constants.DataType.Point:
                        fldVal = val.Point;
                        break;
                    default:
                        fldVal = "";
                        break;
                }

                lst.Add(new OdField()
                {
                    FieldName = fldName,
                    FieldValue = fldVal,
                    DataType=fld.Type
                });
            }

            return lst;
        }

        private static OdField FindOdField(IEnumerable&amp;lt;OdField&amp;gt; flds, string fieldName)
        {
            foreach (var fld in flds)
            {
                if (fld.FieldName.ToUpper() == fieldName.ToUpper()) return fld;
            }
            return null;
        }

        private static List&amp;lt;Tuple&amp;lt;string, MapValue&amp;gt;&amp;gt; GetSourceDataFromRecord(Record record, Autodesk.Gis.Map.ObjectData.Table sourceTable)
        {
            var lst = new List&amp;lt;Tuple&amp;lt;string, MapValue&amp;gt;&amp;gt;();

            for (int i=0; i&amp;lt;record.Count; i++)
            {
                var fld = sourceTable.FieldDefinitions[i];
                lst.Add(new Tuple&amp;lt;string, MapValue&amp;gt;(fld.Name, record[i]));
            }

            return lst;
        }&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2022 14:23:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/error-while-transferring-object-data/m-p/11525675#M11136</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2022-11-02T14:23:07Z</dc:date>
    </item>
    <item>
      <title>Re: Error while transferring Object Data</title>
      <link>https://forums.autodesk.com/t5/net-forum/error-while-transferring-object-data/m-p/11527281#M11137</link>
      <description>&lt;P&gt;Hi thank you for the help the code solved my issue.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Nov 2022 05:03:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/error-while-transferring-object-data/m-p/11527281#M11137</guid>
      <dc:creator>subash.nalla</dc:creator>
      <dc:date>2022-11-03T05:03:36Z</dc:date>
    </item>
  </channel>
</rss>

