Message 1 of 9
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, I'm Using C# to add Xdata to a block reference in a database that's opened in I guess you would call it a Side Data base (not in the drawing Editor). I'm checking for the Registered app and creating it if it doesn't exist. But when it comes to writing the Xdata I get an error EappIdNotFound. I'm Opening the Other drawing database Read-Write. Any Help Would be appreciated. Thanks in advance.
private void PutXdataDate (ObjectId objEntId, string strAppName,string Jdate)
{
Database objDB = objEntId.Database;
Transaction objTrans = objDB.TransactionManager.StartTransaction();
Entity objEnt = (Entity)objTrans.GetObject(objEntId, OpenMode.ForWrite, false);
Database db = HostApplicationServices.WorkingDatabase;
// RegAppTable acRegAppTbl;
using (Transaction acTrans = db.TransactionManager.StartTransaction())
{
var acRegAppTbl = (RegAppTable) acTrans.GetObject(db.RegAppTableId, OpenMode.ForRead);
if (acRegAppTbl.Has(strAppName) == false)
{
RegAppTableRecord acRegAppTblRec = new RegAppTableRecord();
acRegAppTblRec.Name = strAppName;
acRegAppTbl.UpgradeOpen();
acRegAppTbl.Add(acRegAppTblRec);
acTrans.AddNewlyCreatedDBObject(acRegAppTblRec, true);
acTrans.Commit();
}
}
using (objTrans)
{
bool appFound = false;
bool found_IO = false;
bool found_Sig = false;
if (objEnt.XData != null/* TODO Change to default(_) if this is not a reference type */ )
{
bool bChange = false;
ResultBuffer objResBuf = objEnt.XData;
ResultBuffer objNewResBuf = new ResultBuffer();
//TypedValue objTypedVal;
foreach (TypedValue objTypedVal in objResBuf)
{
if (objTypedVal.TypeCode == 1001)
{
string otypval = (string) objTypedVal.Value;
if (otypval.ToString() == strAppName)
{
appFound = true;
bChange = true;
objNewResBuf.Add(objTypedVal);
}
else
bChange = false;
}
if (bChange == true & objTypedVal.TypeCode != 1001)
{
if (objTypedVal.TypeCode == 1000 & Convert.ToString( objTypedVal.Value).Substring(1, 9).ToUpper() == "Jul_Date=".ToUpper())
{
TypedValue TV = new TypedValue((int) DxfCode.ExtendedDataAsciiString, "Jul_Date=" + Jdate);
objNewResBuf.Add(TV);
found_IO = true;
}
else
objNewResBuf.Add(objTypedVal);
}
if (bChange == false)
objNewResBuf.Add(objTypedVal);
}
try
{
objEnt.XData = objNewResBuf;
}
catch (System.Exception ex)
{
System.Windows.MessageBox.Show (ex.Message);
}
}
ResultBuffer objNewestResBuf = new ResultBuffer();
if ((found_IO == false | found_Sig == false) & appFound == true)
{
if (objEnt.XData != null/* TODO Change to default(_) if this is not a reference type */ )
{
bool bChange = false;
ResultBuffer objResBuf = objEnt.XData;
foreach (var objTypedVal in objResBuf)
{
if (objTypedVal.TypeCode == 1001)
{
string otypval = (string)objTypedVal.Value;
if (otypval.ToString() == strAppName)
{
bChange = true;
objNewestResBuf.Add(objTypedVal);
}
else
bChange = false;
}
if (found_IO == false & objTypedVal.TypeCode != 1001 & bChange == true)
{
TypedValue TV = new TypedValue((int)DxfCode.ExtendedDataAsciiString, "Jul_Date=" + Jdate);
objNewestResBuf.Add(TV);
found_IO = true;
}
if (bChange == true)
objNewestResBuf.Add(objTypedVal);
if (bChange == false)
objNewestResBuf.Add(objTypedVal);
}
try
{
objEnt.XData = objNewestResBuf;
}
catch (System.Exception ex)
{
System.Windows.MessageBox.Show (ex.Message);
}
}
}
else if (appFound == false)
{
TypedValue TV = new TypedValue((int)DxfCode.ExtendedDataRegAppName, strAppName);
objNewestResBuf.Add(TV);
TV = new TypedValue((int)DxfCode.ExtendedDataAsciiString,
"Jul_Date=" + Jdate);
objNewestResBuf.Add(TV);
if (objEnt.XData != null)
{ ResultBuffer objResBuf = objEnt.XData;
foreach (var objTypedVal in objResBuf)
objNewestResBuf.Add(objTypedVal);
}
try
{
objEnt.XData = objNewestResBuf;
}
catch (System.Exception ex)
{
System.Windows.MessageBox.Show (ex.Message);
}
}
objTrans.Commit();
objTrans.Dispose();
}
}
Solved! Go to Solution.