.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Objects and Xdata

13 REPLIES 13
Reply
Message 1 of 14
Anonymous
1684 Views, 13 Replies

Objects and Xdata

Hi, i want to set XData to Object like this:
[code] public static void RSNNSetXData(Entity Ent)
{
//Ent.XData.Add
TypedValue[] filList = new TypedValue[2];
//Build a list
filList[0] = new TypedValue((int)DxfCode.ExtendedDataRegAppName, "RSNN_Selection");
filList[1] = new TypedValue((int)DxfCode.Text, "Auswahl");
//ERROR!!!!
Ent.XData.Add(filList);
}[/code]
I get following Error: "System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object...."
The code in VBA looks like this:
[code]Sub RSNNSSSetXdata(Object As AcadEntity)

Dim DataType(1) As Integer
Dim Data(1) As Variant

On Error GoTo Err_Control
DataType(0) = 1001: Data(0) = "RSNN_Selection"
DataType(1) = 1000: Data(1) = "Auswahl"

Object.SetXData DataType, Data

End Sub[/code]
What is wrong with the C#-Code?

Roland
13 REPLIES 13
Message 2 of 14
Anonymous
in reply to: Anonymous

Try it like this:


ResultBuffer buf = new ResultBuffer();

buf.Add( new TypedValue((int) DxfCode.ExtendedDataRegAppName, "YourApp"));
buf.Add( new TypedValue((int) DxfCode.Text, "Your text"));

Entity e = //....

e.XData.Add( buf );



--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

wrote in message news:4867155@discussion.autodesk.com...
Hi, i want to set XData to Object like this:
[code] public static void RSNNSetXData(Entity Ent)
{
//Ent.XData.Add
TypedValue[] filList = new TypedValue[2];
//Build a list
filList[0] = new TypedValue((int)DxfCode.ExtendedDataRegAppName, "RSNN_Selection");
filList[1] = new TypedValue((int)DxfCode.Text, "Auswahl");
//ERROR!!!!
Ent.XData.Add(filList);
}[/code]
I get following Error: "System.Reflection.TargetInvocationException: Exception has been thrown by the target of an
invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object...."
The code in VBA looks like this:
[code]Sub RSNNSSSetXdata(Object As AcadEntity)

Dim DataType(1) As Integer
Dim Data(1) As Variant

On Error GoTo Err_Control
DataType(0) = 1001: Data(0) = "RSNN_Selection"
DataType(1) = 1000: Data(1) = "Auswahl"

Object.SetXData DataType, Data

End Sub[/code]
What is wrong with the C#-Code?

Roland
Message 3 of 14
Anonymous
in reply to: Anonymous

I tried this, it also does not work.
[code] public static void RSNNSetXData(Entity Ent)
{
//Ent.XData.Add
ResultBuffer buf = new ResultBuffer();

buf.Add(new TypedValue((int)DxfCode.ExtendedDataRegAppName, "RSNN_Selection"));
buf.Add(new TypedValue((int)DxfCode.Text, "Auswahl"));
if (Ent != null)
{
Ent.XData.Add(buf);
}
}[/code]
Thank you
Roland
Message 4 of 14
Anonymous
in reply to: Anonymous

have you tried

buf.Add( new TypedValue((int) DxfCode.ExtendedDataAsciiString, "Your
text"));

Laurence

wrote in message news:4867179@discussion.autodesk.com...
I tried this, it also does not work.
[code] public static void RSNNSetXData(Entity Ent)
{
//Ent.XData.Add
ResultBuffer buf = new ResultBuffer();

buf.Add(new TypedValue((int)DxfCode.ExtendedDataRegAppName,
"RSNN_Selection"));
buf.Add(new TypedValue((int)DxfCode.Text, "Auswahl"));
if (Ent != null)
{
Ent.XData.Add(buf);
}
}[/code]
Thank you
Roland
Message 5 of 14
Anonymous
in reply to: Anonymous

It also doesn't work.
Get this error again: "System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object."

Tried it now with this code:

[code]#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;

using System.Threading;
using System.Globalization;

#endregion

namespace RSNNAcadApp.Test
{
public class Test
{
public Test()
{
}

[CommandMethod("SetXDataTest", CommandFlags.Modal)]
public static void RSNNSetXDataTest()
{
Database db = HostApplicationServices.WorkingDatabase;
Transaction myT = db.TransactionManager.StartTransaction();
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

try
{
PromptEntityOptions entopts2 = new PromptEntityOptions("Pick object");
entopts2.Message = "Pick object";
PromptEntityResult ent2 = null;
bool RightObject2 = false;

while (!RightObject2)
{
do
{
ent2 = ed.GetEntity(entopts2);
} while (ent2.Status == PromptStatus.Error);

if (ent2.Status == PromptStatus.Cancel)
{
return;
}

if (ent2.Status == PromptStatus.OK)
{
ObjectId entid2 = ent2.ObjectId;
Entity tmpEnt2 = (Entity)myT.GetObject(entid2, OpenMode.ForWrite);
//Ent.XData.Add
ResultBuffer buf = new ResultBuffer();

buf.Add(new TypedValue((int)DxfCode.ExtendedDataRegAppName, "RSNN_Selection"));
buf.Add(new TypedValue((int)DxfCode.ExtendedDataAsciiString, "Auswahl"));
//buf.Add(new TypedValue((int)1001, "RSNN_Selection"));
//buf.Add(new TypedValue((int)1000, "Auswahl"));
if (tmpEnt2 != null)
{
tmpEnt2.XData.Add(buf);
}
}

}

myT.Commit();
}
catch (System.Exception)
{
myT.Commit();
throw;
}
finally
{
myT.Dispose();
}
}
}

}[/code]


Roland
Message 6 of 14
Anonymous
in reply to: Anonymous

try

tmpEnt2.XData = buf;

and have you registered "RSNN_Selection"

Transaction trans = db.TransactionManager.StartTransaction();

try

{

RegAppTable XdTbl = (RegAppTable)trans.GetObject(db.RegAppTableId,
OpenMode.ForWrite);

if (!XdTbl.Has(XDAppName))

{

RegAppTableRecord xdRec = new RegAppTableRecord();

xdRec.Name = XDAppName;

XdTbl.Add(xdRec);

trans.AddNewlyCreatedDBObject(xdRec, true);

}

trans.Commit();


Laurence

wrote in message news:4867384@discussion.autodesk.com...
It also doesn't work.
Get this error again: "System.Reflection.TargetInvocationException:
Exception has been thrown by the target of an invocation. --->
System.NullReferenceException: Object reference not set to an instance of an
object."

Tried it now with this code:

[code]#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;

using System.Threading;
using System.Globalization;

#endregion

namespace RSNNAcadApp.Test
{
public class Test
{
public Test()
{
}

[CommandMethod("SetXDataTest", CommandFlags.Modal)]
public static void RSNNSetXDataTest()
{
Database db = HostApplicationServices.WorkingDatabase;
Transaction myT = db.TransactionManager.StartTransaction();
Editor ed =
Application.DocumentManager.MdiActiveDocument.Editor;

try
{
PromptEntityOptions entopts2 = new PromptEntityOptions("Pick
object");
entopts2.Message = "Pick object";
PromptEntityResult ent2 = null;
bool RightObject2 = false;

while (!RightObject2)
{
do
{
ent2 = ed.GetEntity(entopts2);
} while (ent2.Status == PromptStatus.Error);

if (ent2.Status == PromptStatus.Cancel)
{
return;
}

if (ent2.Status == PromptStatus.OK)
{
ObjectId entid2 = ent2.ObjectId;
Entity tmpEnt2 = (Entity)myT.GetObject(entid2,
OpenMode.ForWrite);
//Ent.XData.Add
ResultBuffer buf = new ResultBuffer();

buf.Add(new
TypedValue((int)DxfCode.ExtendedDataRegAppName, "RSNN_Selection"));
buf.Add(new
TypedValue((int)DxfCode.ExtendedDataAsciiString, "Auswahl"));
//buf.Add(new TypedValue((int)1001,
"RSNN_Selection"));
//buf.Add(new TypedValue((int)1000, "Auswahl"));
if (tmpEnt2 != null)
{
tmpEnt2.XData.Add(buf);
}
}

}

myT.Commit();
}
catch (System.Exception)
{
myT.Commit();
throw;
}
finally
{
myT.Dispose();
}
}
}

}[/code]


Roland
Message 7 of 14
Anonymous
in reply to: Anonymous

OK, i think this works now.

[code] [CommandMethod("SetXDataTest", CommandFlags.Modal)]
public static void RSNNSetXDataTest()
{
Database db = HostApplicationServices.WorkingDatabase;
Transaction myT = db.TransactionManager.StartTransaction();
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

try
{
//selecttion of the bottom curve
PromptEntityOptions entopts2 = new PromptEntityOptions("Objekt zeigen");
entopts2.Message = "Objekt zeigen";
PromptEntityResult ent2 = null;
bool RightObject2 = false;

while (!RightObject2)
{
do
{
ent2 = ed.GetEntity(entopts2);
} while (ent2.Status == PromptStatus.Error);

if (ent2.Status == PromptStatus.Cancel)
{
return;
}

if (ent2.Status == PromptStatus.OK)
{
ObjectId entid2 = ent2.ObjectId;
Entity tmpEnt2 = (Entity)myT.GetObject(entid2, OpenMode.ForWrite);
//Ent.XData.Add
ed.WriteMessage("\nSchrit4.1!\n");


string XDAppName = "RSNN_Selection";
RegAppTable XdTbl = (RegAppTable)myT.GetObject(db.RegAppTableId, OpenMode.ForWrite);

if (!XdTbl.Has(XDAppName))
{
RegAppTableRecord xdRec = new RegAppTableRecord();
xdRec.Name = XDAppName;
XdTbl.Add(xdRec);
myT.AddNewlyCreatedDBObject(xdRec, true);
}


ResultBuffer buf = new ResultBuffer();

buf.Add(new TypedValue((int)DxfCode.ExtendedDataRegAppName, XDAppName));
buf.Add(new TypedValue((int)DxfCode.ExtendedDataAsciiString, "Auswahl"));
//buf.Add(new TypedValue((int)1001, "RSNN_Selection"));
//buf.Add(new TypedValue((int)1000, "Auswahl"));
if (tmpEnt2 != null)
{
ed.WriteMessage("\nSchrit4.2!\n");
//tmpEnt2.XData.Add(buf);
tmpEnt2.XData = buf;
RightObject2 = true;
}
ed.WriteMessage("\nSchrit4.3!\n");
}

}

myT.Commit();
}
catch (System.Exception)
{
myT.Commit();
throw;
}
finally
{
myT.Dispose();
}
}[/code]


But now i want to select all objects with this XData.
I've tried it with this code, but could not find any objects!?

[code] [CommandMethod("DelXDataTest", CommandFlags.Modal)]
public static void RSNNSSDelXdataAllTest()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
try
{
TypedValue[] filList = new TypedValue[2];
//Build a filter list so that only block references are selected
filList[0] = new TypedValue((int)DxfCode.ExtendedDataRegAppName, "RSNN_Selection");
filList[1] = new TypedValue((int)DxfCode.ExtendedDataAsciiString, "Auswahl");
SelectionFilter filter = new SelectionFilter(filList);
PromptSelectionResult res = ed.SelectAll(filter);
//Do nothing if selection is unsuccessful
if (res.Status != PromptStatus.OK)
return;
SelectionSet SS = res.Value;
ObjectId[] idArray;
idArray = SS.GetObjectIds();
double i = 0;
//collect all employee details in saEmployeeList array
foreach (ObjectId selecteObjId in idArray)
{
ed.WriteMessage(String.Format("Objekt {0}!", ++i));
//separator
ed.WriteMessage("----------------------" + "\r\n");
}
}
finally
{
}
}[/code]


I just want to know this because i want to make some object in my code which i want to make selectabel after the command with previous (like with the measure-command in acad).
Therefore i want to put some XData to the objects in the first step.
In the second step i want to select them and delete the xdata from the objects. In VBA it was no problem for me to do it. And with this code it was possible to make the objects selectable after my command.
VBA-CODE:
[code]Sub RSNNSSSetXdata(Object As AcadEntity)

Dim DataType(1) As Integer
Dim Data(1) As Variant

On Error GoTo Err_Control
DataType(0) = 1001: Data(0) = "RSNN_Selection"
DataType(1) = 1000: Data(1) = "Auswahl"

Object.SetXData DataType, Data

Exit_Here:
Exit Sub
Err_Control:
Err.Clear
Resume Exit_Here

End Sub

Sub RSNNSSDelXdataAll()

Dim objSelSet As AcadSelectionSet
Dim Object As AcadEntity
Dim varData(0) As Variant
Dim intData(0) As Integer
Dim varDataS(0) As Variant
Dim intDataS(0) As Integer

On Error GoTo Err_Control
Set objSelSet = ThisDrawing.PickfirstSelectionSet
'objSelSet.Clear
intDataS(0) = 1001
varDataS(0) = "RSNN_Selection"
'intDataS(1) = 1000
'varDataS(1) = "Auswahl"

objSelSet.Select acSelectionSetAll, FilterType:=intDataS, FilterData:=varDataS

If objSelSet.Count = 0 Then GoTo Exit_Here

intData(0) = 1001
varData(0) = "RSNN_Selection"
For Each Object In objSelSet
Object.SetXData intData, varData
Next Object

Exit_Here:
objSelSet.Delete
Exit Sub
Err_Control:
Err.Clear
Resume Exit_Here

End Sub[/code]

But it is not as easy as i hoped to do this in c#
Therefor thanks to all of you 😉
Roland Message was edited by: RolandF
Changed some code
Message 8 of 14
Anonymous
in reply to: Anonymous

Sorry, just started playing with this .Net code, but if you look at post
.net cannot do Conditional Filtering!! it should give you a clue, XData is
a -3 key with the xdappname, hope some one else has the answer as I could
also do with this, will have a go tomorrow



Laurence

wrote in message news:4867457@discussion.autodesk.com...
OK, i think this works now.
But now i want to select all objects with this XData.
I've tried it with this code, but could not find any objects!?

[code] [CommandMethod("SetXDataTest", CommandFlags.Modal)]
public static void RSNNSetXDataTest()
{
Database db = HostApplicationServices.WorkingDatabase;
Transaction myT = db.TransactionManager.StartTransaction();
Editor ed =
Application.DocumentManager.MdiActiveDocument.Editor;

try
{
//selecttion of the bottom curve
PromptEntityOptions entopts2 = new
PromptEntityOptions("Objekt zeigen");
entopts2.Message = "Objekt zeigen";
PromptEntityResult ent2 = null;
bool RightObject2 = false;

while (!RightObject2)
{
do
{
ent2 = ed.GetEntity(entopts2);
} while (ent2.Status == PromptStatus.Error);

if (ent2.Status == PromptStatus.Cancel)
{
return;
}

if (ent2.Status == PromptStatus.OK)
{
ObjectId entid2 = ent2.ObjectId;
Entity tmpEnt2 = (Entity)myT.GetObject(entid2,
OpenMode.ForWrite);
//Ent.XData.Add
ed.WriteMessage("\nSchrit4.1!\n");


string XDAppName = "RSNN_Selection";
RegAppTable XdTbl =
(RegAppTable)myT.GetObject(db.RegAppTableId, OpenMode.ForWrite);

if (!XdTbl.Has(XDAppName))
{
RegAppTableRecord xdRec = new
RegAppTableRecord();
xdRec.Name = XDAppName;
XdTbl.Add(xdRec);
myT.AddNewlyCreatedDBObject(xdRec, true);
}


ResultBuffer buf = new ResultBuffer();

buf.Add(new
TypedValue((int)DxfCode.ExtendedDataRegAppName, XDAppName));
buf.Add(new
TypedValue((int)DxfCode.ExtendedDataAsciiString, "Auswahl"));
//buf.Add(new TypedValue((int)1001,
"RSNN_Selection"));
//buf.Add(new TypedValue((int)1000, "Auswahl"));
if (tmpEnt2 != null)
{
ed.WriteMessage("\nSchrit4.2!\n");
//tmpEnt2.XData.Add(buf);
tmpEnt2.XData = buf;
RightObject2 = true;
}
ed.WriteMessage("\nSchrit4.3!\n");
}

}

myT.Commit();
}
catch (System.Exception)
{
myT.Commit();
throw;
}
finally
{
myT.Dispose();
}
}[/code]


Roland
Message 9 of 14
Anonymous
in reply to: Anonymous

Look at Lab 5 ,from this I quickly got this code to work -

PromptSelectionOptions Opts = new PromptSelectionOptions();

TypedValue[] filList = new TypedValue[1];

//Build a filter list so that only block references are selected

filList[0] = new TypedValue((int) DxfCode.ExtendedDataRegAppName, AppName);

SelectionFilter filter = new SelectionFilter(Opts, filList);

// PromptSelectionResult res = ed.GetSelection( filter); //user selection

PromptSelectionResult res = ed.SelectAll( filter); //all ents with Appname

//Do nothing if selection is unsuccessful

if (res.Status != PromptStatus.OK)

return;

Autodesk.AutoCAD.EditorInput.SelectionSet SS = res.Value;

ObjectId[] idArray;

idArray = SS.GetObjectIds();

string[] saEmployeeList = new string[4];

//collect all employee details in saEmployeeList array

foreach (ObjectId employeeId in idArray)

{

ed.WriteMessage("\nFound");

}

PromptSelectionOptions Opts = new PromptSelectionOptions();

TypedValue[] filList = new TypedValue[1];

//Build a filter list so that only block references are selected

filList[0] = new TypedValue((int) DxfCode.ExtendedDataRegAppName, AppName);

SelectionFilter filter = new SelectionFilter(Opts, filList);

// PromptSelectionResult res = ed.GetSelection( filter); //user selection
will pick only Appname ents

PromptSelectionResult res = ed.SelectAll( filter); //all ents with Appname

//Do nothing if selection is unsuccessful

if (res.Status != PromptStatus.OK)

return;

Autodesk.AutoCAD.EditorInput.SelectionSet SS = res.Value;

ObjectId[] idArray;

idArray = SS.GetObjectIds();

string[] saEmployeeList = new string[4];

//collect all employee details in saEmployeeList array

foreach (ObjectId employeeId in idArray)

{

ed.WriteMessage("\nFound"); // do what you want here

}



Laurence

wrote in message news:4867457@discussion.autodesk.com...
OK, i think this works now.
But now i want to select all objects with this XData.
I've tried it with this code, but could not find any objects!?

[code] [CommandMethod("SetXDataTest", CommandFlags.Modal)]
public static void RSNNSetXDataTest()
{
Database db = HostApplicationServices.WorkingDatabase;
Transaction myT = db.TransactionManager.StartTransaction();
Editor ed =
Application.DocumentManager.MdiActiveDocument.Editor;

try
{
//selecttion of the bottom curve
PromptEntityOptions entopts2 = new
PromptEntityOptions("Objekt zeigen");
entopts2.Message = "Objekt zeigen";
PromptEntityResult ent2 = null;
bool RightObject2 = false;

while (!RightObject2)
{
do
{
ent2 = ed.GetEntity(entopts2);
} while (ent2.Status == PromptStatus.Error);

if (ent2.Status == PromptStatus.Cancel)
{
return;
}

if (ent2.Status == PromptStatus.OK)
{
ObjectId entid2 = ent2.ObjectId;
Entity tmpEnt2 = (Entity)myT.GetObject(entid2,
OpenMode.ForWrite);
//Ent.XData.Add
ed.WriteMessage("\nSchrit4.1!\n");


string XDAppName = "RSNN_Selection";
RegAppTable XdTbl =
(RegAppTable)myT.GetObject(db.RegAppTableId, OpenMode.ForWrite);

if (!XdTbl.Has(XDAppName))
{
RegAppTableRecord xdRec = new
RegAppTableRecord();
xdRec.Name = XDAppName;
XdTbl.Add(xdRec);
myT.AddNewlyCreatedDBObject(xdRec, true);
}


ResultBuffer buf = new ResultBuffer();

buf.Add(new
TypedValue((int)DxfCode.ExtendedDataRegAppName, XDAppName));
buf.Add(new
TypedValue((int)DxfCode.ExtendedDataAsciiString, "Auswahl"));
//buf.Add(new TypedValue((int)1001,
"RSNN_Selection"));
//buf.Add(new TypedValue((int)1000, "Auswahl"));
if (tmpEnt2 != null)
{
ed.WriteMessage("\nSchrit4.2!\n");
//tmpEnt2.XData.Add(buf);
tmpEnt2.XData = buf;
RightObject2 = true;
}
ed.WriteMessage("\nSchrit4.3!\n");
}

}

myT.Commit();
}
catch (System.Exception)
{
myT.Commit();
throw;
}
finally
{
myT.Dispose();
}
}[/code]


Roland
Message 10 of 14
Anonymous
in reply to: Anonymous

Works great, thank you!!!! 😄

Roland
Message 11 of 14
Anonymous
in reply to: Anonymous

Sorry

SelectionFilter filter = new SelectionFilter(Opts, filList);

// PromptSelectionResult res = ed.GetSelection( filter); //user selection

should be

SelectionFilter filter = new SelectionFilter( filList);

// PromptSelectionResult res = ed.GetSelection( Opts, filter); //user
selection



"Laurence Skoropinski" wrote in message
news:4867668@discussion.autodesk.com...
Look at Lab 5 ,from this I quickly got this code to work -

PromptSelectionOptions Opts = new PromptSelectionOptions();

TypedValue[] filList = new TypedValue[1];

//Build a filter list so that only block references are selected

filList[0] = new TypedValue((int) DxfCode.ExtendedDataRegAppName, AppName);

SelectionFilter filter = new SelectionFilter(Opts, filList);

// PromptSelectionResult res = ed.GetSelection( filter); //user selection

PromptSelectionResult res = ed.SelectAll( filter); //all ents with Appname

//Do nothing if selection is unsuccessful

if (res.Status != PromptStatus.OK)

return;

Autodesk.AutoCAD.EditorInput.SelectionSet SS = res.Value;

ObjectId[] idArray;

idArray = SS.GetObjectIds();

string[] saEmployeeList = new string[4];

//collect all employee details in saEmployeeList array

foreach (ObjectId employeeId in idArray)

{

ed.WriteMessage("\nFound");

}

PromptSelectionOptions Opts = new PromptSelectionOptions();

TypedValue[] filList = new TypedValue[1];

//Build a filter list so that only block references are selected

filList[0] = new TypedValue((int) DxfCode.ExtendedDataRegAppName, AppName);

SelectionFilter filter = new SelectionFilter(Opts, filList);

// PromptSelectionResult res = ed.GetSelection( filter); //user selection
will pick only Appname ents

PromptSelectionResult res = ed.SelectAll( filter); //all ents with Appname

//Do nothing if selection is unsuccessful

if (res.Status != PromptStatus.OK)

return;

Autodesk.AutoCAD.EditorInput.SelectionSet SS = res.Value;

ObjectId[] idArray;

idArray = SS.GetObjectIds();

string[] saEmployeeList = new string[4];

//collect all employee details in saEmployeeList array

foreach (ObjectId employeeId in idArray)

{

ed.WriteMessage("\nFound"); // do what you want here

}



Laurence

wrote in message news:4867457@discussion.autodesk.com...
OK, i think this works now.
But now i want to select all objects with this XData.
I've tried it with this code, but could not find any objects!?

[code] [CommandMethod("SetXDataTest", CommandFlags.Modal)]
public static void RSNNSetXDataTest()
{
Database db = HostApplicationServices.WorkingDatabase;
Transaction myT = db.TransactionManager.StartTransaction();
Editor ed =
Application.DocumentManager.MdiActiveDocument.Editor;

try
{
//selecttion of the bottom curve
PromptEntityOptions entopts2 = new
PromptEntityOptions("Objekt zeigen");
entopts2.Message = "Objekt zeigen";
PromptEntityResult ent2 = null;
bool RightObject2 = false;

while (!RightObject2)
{
do
{
ent2 = ed.GetEntity(entopts2);
} while (ent2.Status == PromptStatus.Error);

if (ent2.Status == PromptStatus.Cancel)
{
return;
}

if (ent2.Status == PromptStatus.OK)
{
ObjectId entid2 = ent2.ObjectId;
Entity tmpEnt2 = (Entity)myT.GetObject(entid2,
OpenMode.ForWrite);
//Ent.XData.Add
ed.WriteMessage("\nSchrit4.1!\n");


string XDAppName = "RSNN_Selection";
RegAppTable XdTbl =
(RegAppTable)myT.GetObject(db.RegAppTableId, OpenMode.ForWrite);

if (!XdTbl.Has(XDAppName))
{
RegAppTableRecord xdRec = new
RegAppTableRecord();
xdRec.Name = XDAppName;
XdTbl.Add(xdRec);
myT.AddNewlyCreatedDBObject(xdRec, true);
}


ResultBuffer buf = new ResultBuffer();

buf.Add(new
TypedValue((int)DxfCode.ExtendedDataRegAppName, XDAppName));
buf.Add(new
TypedValue((int)DxfCode.ExtendedDataAsciiString, "Auswahl"));
//buf.Add(new TypedValue((int)1001,
"RSNN_Selection"));
//buf.Add(new TypedValue((int)1000, "Auswahl"));
if (tmpEnt2 != null)
{
ed.WriteMessage("\nSchrit4.2!\n");
//tmpEnt2.XData.Add(buf);
tmpEnt2.XData = buf;
RightObject2 = true;
}
ed.WriteMessage("\nSchrit4.3!\n");
}

}

myT.Commit();
}
catch (System.Exception)
{
myT.Commit();
throw;
}
finally
{
myT.Dispose();
}
}[/code]


Roland
Message 12 of 14
Anonymous
in reply to: Anonymous

For all who want to know how i do it now:

[code] public static void RSNNSetXData(Entity ent, Database db, Transaction myT)
{
string AppName = "RSNN_Selection";
RegAppTable XdTbl = (RegAppTable)myT.GetObject(db.RegAppTableId, OpenMode.ForWrite);

if (!XdTbl.Has(AppName))
{
RegAppTableRecord xdRec = new RegAppTableRecord();
xdRec.Name = AppName;
XdTbl.Add(xdRec);
myT.AddNewlyCreatedDBObject(xdRec, true);
}

//Ent.XData.Add
ResultBuffer buf = new ResultBuffer();

buf.Add(new TypedValue((int)DxfCode.ExtendedDataRegAppName, AppName));
buf.Add(new TypedValue((int)DxfCode.ExtendedDataAsciiString, "Auswahl"));

if (ent != null)
ent.XData = buf;

}


public static void RSNNSSDelXdataAll()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
Database db = HostApplicationServices.WorkingDatabase;
Transaction myT = db.TransactionManager.StartTransaction();
try
{
string AppName = "RSNN_Selection";

TypedValue[] filList = new TypedValue[1];

//Build a filter list so that only block references are selected
filList[0] = new TypedValue((int)DxfCode.ExtendedDataRegAppName, AppName);
SelectionFilter filter = new SelectionFilter(filList);

//user selection will pick only Appname ents
PromptSelectionResult res = ed.SelectAll(filter); //all ents with Appname

//Do nothing if selection is unsuccessful
if (res.Status != PromptStatus.OK)
return;

Autodesk.AutoCAD.EditorInput.SelectionSet SS = res.Value;
ObjectId[] idArray;
idArray = SS.GetObjectIds();

ResultBuffer buf = new ResultBuffer();
buf.Add(new TypedValue((int)DxfCode.ExtendedDataRegAppName, AppName));

//collect all employee details in saEmployeeList array
foreach (ObjectId objId in idArray)
{
Entity tmpEnt = (Entity)myT.GetObject(objId, OpenMode.ForWrite);
if (tmpEnt != null)
tmpEnt.XData = buf;

}
myT.Commit();
}
catch (System.Exception)
{
myT.Commit();
throw;
}
finally
{
myT.Dispose();
}
}[/code]

With the first function i set the XData to the objects i want to select.
The second function selects the objects and deletes the XData.

In the programm you have to start the second function first (just to delete XData if there are some), then set the XData to the objects you want. At the end start function two again. Now you can select the objects with previous after your command.

Roland Message was edited by: RolandF
Message 13 of 14
Rajesh.asana
in reply to: Anonymous

Can i get equivalent VB.net code to add xdata using ObjectARx
Message 14 of 14
NathTay
in reply to: Anonymous

Roland's code converted with http://labs.developerfusion.co.uk/convert/csharp-to-vb.aspx

Public Shared Sub RSNNSetXData(ByVal ent As Entity, ByVal db As Database, ByVal myT As Transaction)
Dim AppName As String = "RSNN_Selection"
Dim XdTbl As RegAppTable = DirectCast(myT.GetObject(db.RegAppTableId, OpenMode.ForWrite), RegAppTable)

If Not XdTbl.Has(AppName) Then
Dim xdRec As New RegAppTableRecord()
xdRec.Name = AppName
XdTbl.Add(xdRec)
myT.AddNewlyCreatedDBObject(xdRec, True)
End If

'Ent.XData.Add
Dim buf As New ResultBuffer()

buf.Add(New TypedValue(CInt(DxfCode.ExtendedDataRegAppName), AppName))
buf.Add(New TypedValue(CInt(DxfCode.ExtendedDataAsciiString), "Auswahl"))

If ent IsNot Nothing Then
ent.XData = buf
End If

End Sub

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost