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