XCLIP - No Boundary Found

XCLIP - No Boundary Found

Civil3DReminders_com
Mentor Mentor
616 Views
1 Reply
Message 1 of 2

XCLIP - No Boundary Found

Civil3DReminders_com
Mentor
Mentor

I'm attempting to XCLIP an External Reference DWG. The code appears to work, except for AutoCAD recognizing it. If I press the Remove Clipping Boundary from the ribbon, AutoCAD indicates "No clip boundary found." I have to create a new clipping boundary to remove the clipping boundary added via code. 

 

I'm using code based on this blog post:

https://www.keanw.com/2010/11/adding-a-2d-spatial-filter-to-perform-a-simple-xclip-on-an-external-re...

 

Is this a known issue or is there a method that gives the expected results. 

 

Using AutoCAD Civil 3D 2020.

 

        public static bool AddXClip(Transaction tr, List<Point2d> points)
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;

            var typVals = new List<TypedValue>
                    {
                        new TypedValue((int)DxfCode.Operator, "<OR"),
                        new TypedValue((int)DxfCode.Start, typeof(BlockReference)),
                        new TypedValue((int)DxfCode.Start, "INSERT"),
                        new TypedValue((int)DxfCode.Operator, "OR>")
                    };

            var xrefObjId = ed.GetEntityByTypes(typVals, "Select external reference to XCLIP: ", "", out Point3d pickPt);

            if (xrefObjId.IsNull)
            {
                return false;
            }

            try
            {
                var pt2DCollection = new Point2dCollection();

                foreach (var pt in points)
                {
                    pt2DCollection.Add(pt);
                }

                var acFilterDictName = "ACAD_FILTER";
                var acSpatialName = "SPATIAL";

                var blkRef = xrefObjId.GetObject(OpenMode.ForWrite) as BlockReference;

                var acSpatialFilterDef = new SpatialFilterDefinition(pt2DCollection, blkRef.Normal, 0.0, 0.0, 0.0, true);
                var acSpatialFilter = new SpatialFilter { Definition = acSpatialFilterDef };

                if (blkRef.ExtensionDictionary.IsNull)
                {
                    blkRef.CreateExtensionDictionary();
                }

                var extensionDict = blkRef.ExtensionDictionary.GetObject(OpenMode.ForWrite) as DBDictionary;

                if (extensionDict.Contains(acFilterDictName))
                {
                    var filterDict = extensionDict.GetAt(acFilterDictName).GetObject(OpenMode.ForWrite) as DBDictionary;

                    if (filterDict.Contains(acSpatialName))
                    {
                        filterDict.Remove(acSpatialName);
                    }

                    filterDict.SetAt(acSpatialName, acSpatialFilter);
                }
                else
                {
                    var filterDict = new DBDictionary();
                    extensionDict.SetAt(acFilterDictName, filterDict);
                    tr.AddNewlyCreatedDBObject(filterDict, true);
                    filterDict.SetAt(acSpatialName, acSpatialFilter);
                }

                tr.AddNewlyCreatedDBObject(acSpatialFilter, true);
                return true;
            }
            catch (System.Exception ex)
            {
                return false;
            }
            
        }

 

Thanks!

Civil Reminders
http://blog.civil3dreminders.com/
http://www.CivilReminders.com/
Alumni
617 Views
1 Reply
Reply (1)
Message 2 of 2

tvhlong93
Contributor
Contributor

Hi,

I have the same problem when trying to clip a block reference. I've been trying to find the solution and have come across your topic. Have you found the solution yet? If you have one, please share it. I can't find any information about this problem. 

When I saved and reopened the drawing, it fixed the problem. But it's inconvenient when creating multiple clippings because the drawing doesn't show correctly.

Thank you.

0 Likes