- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I need to create a little application (Not the firt one in .NET but my first one for Autocad in C# .NET).
What do I need to do ?
User select texts on screen. => Making a SelectionSet of those selected texts. DONE
Foreach select text is on screen another text (on another layer) with the same coordinates.
Here is my trouble.
Foreach text in the first SelectionSet, I try to create a second SelectionSet (filtered to select text only, named acPSResPCode) but that SelectionSet stay always null.
If I make the SelectionSet without filter I select every lines in the crossingwindows, but no text are selected.
How do I need to do ?
Here's my code (PS : Code for AcadMp 2010)
[CommandMethod("SelectionPP")]
public void SelectionPP()
{
//Récupère le document courant, sa base de données, et demarre une transaction
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
//Récupération de l'éditeur de la base de données courante
Editor ed = acDoc.Editor;
//Démarre une nouvelle transaction
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
//Création d'un filtre pour récupérer uniquement les textes
TypedValue[] acFilList = new TypedValue[1] { new TypedValue((int)DxfCode.Start, "TEXT") };
SelectionFilter acFilter = new SelectionFilter(acFilList);
PromptSelectionOptions acPSOpts = new PromptSelectionOptions();
acPSOpts.MessageForAdding = "Cliquez les PP";
PromptSelectionResult acPSResPP = ed.GetSelection(acPSOpts, acFilter);
//Si la sélection a réussi
if (acPSResPP.Status == PromptStatus.OK)
{
SelectionSet acSSetPP = acPSResPP.Value;
ObjectId[] acIdsPP = acSSetPP.GetObjectIds();
for (int i = 0; i < acIdsPP.Length; i++)
{
//Récupération de l'objet texte saisi
DBText acTextPP = (DBText)acTrans.GetObject(acIdsPP[i], OpenMode.ForRead);
//Récupération des coordonnées du Texte saisi
Point3d acPoint3DPP = acTextPP.Position;
StringBuilder sb = new StringBuilder();
//Création d'un point inférieur gauche
Point3d acPt1 = new Point3d(acPoint3DPP.X - 0.0001, acPoint3DPP.Y - 0.0001, 0.0);
//Création d'un point supérieur droit
Point3d acPt2 = new Point3d(acPoint3DPP.X + 0.0001, acPoint3DPP.Y + 0.0001, 0.0);
//Sélection de tous les textes dans le rectangle formé par les 2 points
PromptSelectionResult acPSResPCode = ed.SelectCrossingWindow(acPt1, acPt2, acFilter);
//Si la sélection a réussi
if (acPSResPCode.Status == PromptStatus.OK)
{
SelectionSet acSSetPCodes = acPSResPCode.Value;
ObjectId[] acIdsPCodes = acSSetPCodes.GetObjectIds();
sb = new StringBuilder();
sb.AppendFormat("{0} éléments sélectionnés", acSSetPCodes.Count);
Application.ShowAlertDialog(sb.ToString());
for (int j = 0; j < acIdsPCodes.Length; j++)
{
DBText acTextPCode = null;
acTextPCode = (DBText)acTrans.GetObject(acIdsPCodes[i], OpenMode.ForRead);
sb = new StringBuilder();
sb.AppendFormat("{3}{2}Id : {0}{2}Id sélectionné : {1}", acTextPP.ObjectId, acTextPCode.ObjectId, Environment.NewLine,i);
Application.ShowAlertDialog(sb.ToString());
if (acTextPCode.ObjectId != acTextPP.ObjectId)
{
int intPCode = 0;
if (int.TryParse(acTextPCode.TextString, out intPCode))
{
PP newPP = new PP(acTextPP.TextString, intPCode, acPoint3DPP.X, acPoint3DPP.Y, acPoint3DPP.Z);
sb = new StringBuilder();
sb.AppendFormat("PP : {0} PCode : {1}{5}Coord : {2},{3},{4}{5}", newPP.NoPP, newPP.PCode, newPP.X, newPP.Y, newPP.Z, Environment.NewLine);
Application.ShowAlertDialog(sb.ToString());
}
}
}
}
else
{
sb.AppendFormat("Aucun texte trouvé pour le point {0}{2}PromptStatus = {1}", acTextPP.TextString, acPSResPCode.Status, Environment.NewLine);
Application.ShowAlertDialog(sb.ToString());
}
}
}
}
}Thanks for your advices,
Jean-Marc
Solved! Go to Solution.