Is it possible to prompt selection for an empty area, a la vanilla hatch command? I've written a piece of code where I aimed to select an object, then fill it with hatch. This would've worked had I a single object, but my enclosed space is surrounded by more than a single object or even types of objects.
Hence, I'm in need of a Prompt to select the empty enclosed space instead. Is this possible, or has anyone experience with this kind of thing? My code blow, which was to prompt for an object selection.
public static void HatchArea() { Document acDoc = Application.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; Editor docEd = acDoc.Editor; PromptKeywordOptions promptKeyOpts = new PromptKeywordOptions(""); promptKeyOpts.AllowArbitraryInput = false; promptKeyOpts.Keywords.Add("Area"); promptKeyOpts.Keywords.Add("Boundary"); PromptResult hatchSelRes = docEd.GetKeywords(promptKeyOpts); using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { BlockTable acBt; acBt = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable; BlockTableRecord acBtr; acBtr = acTrans.GetObject(acBt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; using (Hatch acHatch = new Hatch()) { if (hatchSelRes.StringResult == "Area") { Point3dCollection p3Coll = new Point3dCollection(); PromptEntityOptions promptEntity = new PromptEntityOptions(""); PromptEntityResult entityRes = docEd.GetEntity(promptEntity); if (entityRes.ObjectId != null) { ObjectId oid = new ObjectId(); oid = entityRes.ObjectId; ObjectIdCollection oidCol = new ObjectIdCollection(); oidCol.Add(oid); try { acBtr.AppendEntity(acHatch); acTrans.AddNewlyCreatedDBObject(acHatch, true); acHatch.AppendLoop(HatchLoopTypes.External, oidCol); } catch (SystemException ex) { docEd.WriteMessage("Select an enclosed object."); } } }
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
I can not test it now, but it does not work if you select multiple items?
TypedValue[] acTypValAr = new TypedValue[9]; acTypValAr.SetValue(new TypedValue((int)DxfCode.Operator, "<or"), 0); acTypValAr.SetValue(new TypedValue((int)DxfCode.Start, "POLYLINE"), 1); acTypValAr.SetValue(new TypedValue((int)DxfCode.Start, "LWPOLYLINE"), 2); acTypValAr.SetValue(new TypedValue((int)DxfCode.Start, "POLYLINE2D"), 3); acTypValAr.SetValue(new TypedValue((int)DxfCode.Start, "POLYLINE3D"), 4); acTypValAr.SetValue(new TypedValue((int)DxfCode.Start, "SPLINE"), 5); acTypValAr.SetValue(new TypedValue((int)DxfCode.Start, "LINE"), 6); acTypValAr.SetValue(new TypedValue((int)DxfCode.Start, "ARC"), 7); acTypValAr.SetValue(new TypedValue((int)DxfCode.Operator, "or>"), 8); SelectionFilter acSelFtr = new SelectionFilter(acTypValAr); PromptSelectionResult pSelRes; PromptSelectionOptions pSelOpts = new PromptSelectionOptions(); pSelOpts.MessageForAdding = "\nSelect Lines, Polylines, Arcs or Splines: "; pSelRes = ed.GetSelection(pSelOpts, acSelFtr); if (pSelRes.Status == PromptStatus.OK) { //your code }
Hi,
The POLYLINE2D and POLYLINE3D are not valid DXF entity types (both are types of POLYLINE)
You can build your selection filter in a much more concise way:
TypedValue[] acTypValAr = new TypedValue[1]; acTypValAr.SetValue(new TypedValue(0, "ARC,LINE,LWPOLYLINE,POLYLINE,SPLINE"), 0); SelectionFilter acSelFtr = new SelectionFilter(acTypValAr);
Or simply:
var filter = new SelectionFilter(new[] { new TypedValue(0, "ARC,LINE,LWPOLYLINE,POLYLINE,SPLINE") });
@stefan.hofer wrote:
it does not work if you select multiple items?
Have a look at the PICKADD system variable
Well, I'm not the most VB literate, but I've tried to implement it to my best.
PromptPointOptions ptOptions = new PromptPointOptions("Select point "); ptOptions.AllowNone = false; PromptPointResult ptResult = docEd.GetPoint(ptOptions); if (ptResult.Status != PromptStatus.OK) { return; } DBObjectCollection collection = docEd.TraceBoundary(ptResult.Value, true); ObjectIdCollection oidCol = new ObjectIdCollection(); using (Autodesk.AutoCAD.DatabaseServices.Polyline acPoly = new Autodesk.AutoCAD.DatabaseServices.Polyline()) { foreach (Object obj in collection) { Polyline poly = obj as Polyline; //Autodesk.AutoCAD.DatabaseServices.Entity ent = obj as Autodesk.AutoCAD.DatabaseServices.Entity; if (poly != null) { ObjectId oid = new ObjectId(); oid = acBtr.AppendEntity(poly); oidCol.Add(oid); } } }
try
{
acBtr.AppendEntity(acHatch);
acTrans.AddNewlyCreatedDBObject(acHatch, true);
acHatch.AppendLoop(HatchLoopTypes.External, oidCol);
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
docEd.WriteMessage("Select an enclosed object.");
Console.WriteLine(ex.Message);
return;
}
It collects some oid's for sure, however I receive Invalid Input exception (at Catch).
As for other inquiries: Yes, I'm sorry I haven't made it clear at first. I could work around this by making the user select multiple items, but that's not my goal. I am trying to make it function similarly to the vanilla hatch command, and am willing to do my other code on the side. If desired, much more easily, hatch creation could be separated from the code itself. I'm just trying to make it a little easier to use.
However, I appreciate the help. I'll look into advice related to see filters. I'm sure I could make use of it somewhere else. Thanks a lot.
Can't find what you're looking for? Ask the community or share your knowledge.