- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I've created a function that can be used on Civil3D (function 1), calling another function (function 2). This function calls another function that lists the existing ObjectData values of the "Profile" field of all the project's 3D polylines in a HashSet, then the idea is to make a selection of these polylines based on these different HashSet values successively.
The functions work independently of each other, but when I link them, they don't work anymore.
I think it's linked to the transactions. The records (OD fields) are correctly read in function 2, but when I want to read them again in my function 1, no record is detected and it's impossible to launch the "foreach (Record record in records2)" line, whereas before linking them, it worked.
public class Fonctions_mineures
{
public static HashSet<string> listprofilepl()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
Tables tables = HostMapApplicationServices.Application.ActiveProject.ODTables;
TypedValue[] filterList = new TypedValue[]
{
new TypedValue((int)DxfCode.Start, "POLYLINE")
};
SelectionFilter filter = new SelectionFilter(filterList);
PromptSelectionResult psr = ed.SelectAll(filter);
HashSet<String> ExistingProfile = new HashSet<String>();
if (psr.Status == PromptStatus.OK)
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
foreach (SelectedObject so in psr.Value)
{
Autodesk.AutoCAD.DatabaseServices.Polyline3d ent = (Autodesk.AutoCAD.DatabaseServices.Polyline3d)tr.GetObject(so.ObjectId, OpenMode.ForRead);
Records records = tables.GetObjectRecords(0, ent, Autodesk.Gis.Map.Constants.OpenMode.OpenForRead, false);
foreach (Record record in records)
{
for (int i = 0; i < record.Count; i++)
{
MapValue val = record[i];
Autodesk.Gis.Map.ObjectData.Table table = tables[record.TableName];
FieldDefinition fieldDef = table.FieldDefinitions[i];
if (fieldDef.Name == "Profile")
{
ExistingProfile.Add(val.StrValue);
}
}
}
ExistingProfile.Remove("");
//tr.Commit();
}
return ExistingProfile;
}
}
else
{
return ExistingProfile;
}
}
}
public class MyCommandsAEP
{
[CommandMethod("AEPFilterByObjectData")]
public static void selectplbyvalue()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
Tables tables = HostMapApplicationServices.Application.ActiveProject.ODTables;
HashSet<string> profiles = Fonctions_mineures.listprofilepl();
TypedValue[] filterList = new TypedValue[]{new TypedValue((int)DxfCode.Start, "POLYLINE")};
SelectionFilter filter = new SelectionFilter(filterList);
PromptSelectionResult psr = ed.SelectAll(filter);
List<ObjectId> matchingPolylines = new List<ObjectId>();
if (psr.Status == PromptStatus.OK)
{
Transaction tr2 = db.TransactionManager.StartTransaction();
foreach (SelectedObject so in psr.Value)
{
//Autodesk.AutoCAD.DatabaseServices.Polyline3d ent = tr.GetObject(so.ObjectId, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Polyline3d;
Autodesk.AutoCAD.DatabaseServices.Polyline3d ent = (Autodesk.AutoCAD.DatabaseServices.Polyline3d)tr2.GetObject(so.ObjectId, OpenMode.ForRead);
Records records2 = tables.GetObjectRecords(0, ent, Autodesk.Gis.Map.Constants.OpenMode.OpenForRead, false);
// Votre logique de traitement pour les polylignes 2D
foreach (Record record in records2)
{
if (record != null)
{
foreach (string prof in profiles)
{
for (int i = 0; i < record.Count; i++)
{
MapValue val = record[i];
Autodesk.Gis.Map.ObjectData.Table table = tables[record.TableName];
FieldDefinition fieldDef = table.FieldDefinitions[i];
if (fieldDef.Name == "Profile" && val.StrValue == prof)
{
ed.WriteMessage($"\nEntity with ObjectId {so.ObjectId} has Profil value of {prof}.");
matchingPolylines.Add(so.ObjectId);
// Pour les fusionner
//foreach (ObjectId vId in ent)
//{
// PolylineVertex3d v3d = (PolylineVertex3d)tr.GetObject(vId, OpenMode.ForWrite);
// ent2.AppendVertex(v3d);
//}
}
}
ed.SetImpliedSelection(matchingPolylines.ToArray());
}
}
else
{
ed.WriteMessage("\nAucun enregistrement trouvé pour l'objet avec ObjectId: " + so.ObjectId.ToString());
}
}
}
}
}
Solved! Go to Solution.