Message 1 of 3

Not applicable
08-26-2022
11:59 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello all,
I am trying to automate the filleting of all PolyLines in a drawing. I am doing so like this:
private static ObjectIdCollection GetPolylineEntities(string layerName = null)
{
var doc = Application.DocumentManager.MdiActiveDocument;
var ed = doc.Editor;
TypedValue[] filter;
if (!String.IsNullOrEmpty(layerName))
{
filter = new TypedValue[]{
new TypedValue((int)DxfCode.Operator,"<and"),
new TypedValue((int)DxfCode.LayerName,layerName),
new TypedValue((int)DxfCode.Start,"LWPolyline"),
new TypedValue((int)DxfCode.Operator,"and>")
};
}
else
{
filter = new TypedValue[] { new TypedValue((int)DxfCode.Start, "LWPolyline") };
}
// Build a filter list so that only entities
// on the specified layer are selected
var selectionFilter = new SelectionFilter(filter);
var promptStatusResult = ed.SelectAll(selectionFilter);
if (promptStatusResult.Status == PromptStatus.OK)
return
new ObjectIdCollection(
promptStatusResult.Value.GetObjectIds()
);
else
return new ObjectIdCollection();
}
[CommandMethod("Test", "FilletAll", CommandFlags.Modal)]
public void FilletAll()
{
var ed = Application.DocumentManager.MdiActiveDocument.Editor;
var plineIds = GetPolylineEntities();
var radiusPrompt = new PromptDoubleOptions("\nWhat radius? ");
var radiusResponse = ed.GetDouble(radiusPrompt);
if (radiusResponse.Status != PromptStatus.OK)
{
ed.WriteMessage("You must supply a valid radius\n");
return;
}
// Suppress Command Line noise.
var noMutt = Application.GetSystemVariable("NOMUTT");
Application.SetSystemVariable("NOMUTT", 1);
ed.Command("FILLETRAD", 0.5);
var db = Application.DocumentManager.MdiActiveDocument.Database;
using (var pm = new ProgressMeter())
using (var tr = db.TransactionManager.StartTransaction())
{
pm.Start("Filleting Polylines");
pm.SetLimit(plineIds.Count);
foreach (ObjectId id in plineIds)
{
ed.Command("_.FILLET", "_P", id);
pm.MeterProgress();
System.Windows.Forms.Application.DoEvents();
}
pm.Stop();
System.Windows.Forms.Application.DoEvents();
}
Application.SetSystemVariable("NOMUTT", noMutt);
}
This almost works -- I am able to repeatedly (and manually) click a single polyline, and eventually it will fillet all polylines. The issues with this is:
- This requires manual intervention -- I'm attempting to do this all automatically through the code
- It provides a bunch of the following error: "The object is not in current space.", which is why I need to manually click on polylines until those polylines have been processed.
So may question is: Is it possible to filter out polylines that are not in the current space? Or, if not possible, is there a way to detect that AutoCAD is supplying this error and simply handling it in some way?
Thanks in advance
Solved! Go to Solution.