Filleting Polylines: "The object is not in current space."

Filleting Polylines: "The object is not in current space."

Anonymous
Not applicable
361 Views
2 Replies
Message 1 of 3

Filleting Polylines: "The object is not in current space."

Anonymous
Not applicable

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:

  1. This requires manual intervention -- I'm attempting to do this all automatically through the code
  2. 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

0 Likes
Accepted solutions (1)
362 Views
2 Replies
Replies (2)
Message 2 of 3

norman.yuan
Mentor
Mentor
Accepted solution

Editor.SelectAll() would select all entities in all layouts/spaces unless you have filter, and the "Fillet" command seems only work with entities in current space. So, in your case, if you want to select plolylines in specific layout ("Model", or one of the layout), you need to add a "LayoutName" filter, say, modelspace:

 

new TypedVlue((int)DxfCode.LayoutName, "MODEL")

 

Obviously, if you just want current space, then you need to find out the current space's layout name, in order to set the filter TypedValue.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 3

Anonymous
Not applicable

Thank you! The above helped me determine that my issue was related to this as well as some external references I was missing, which was where AutoCAD was failing.

0 Likes