I have a nested block. When I apply clipping on that block by c# Api after that some of block hidden. They are not visible, but they are there in same clipped block. code for reference.
const string filterDictName = "ACAD_FILTER";
const string spatialName = "SPATIAL";
[CommandMethod("TEST")]
public void Test()
{
var doc = Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
// Select a block to clip
var peo = new PromptEntityOptions("\nSelect a block reference to clip:");
peo.AllowNone = false;
peo.SetRejectMessage("\nNot a block reference.");
peo.AddAllowedClass(typeof(BlockReference), false);
var per = ed.GetEntity(peo);
if (per.Status != PromptStatus.OK)
return;
// Select rectangle to clip
var ppo = new PromptPointOptions("\nSelect first clip corner: ");
ppo.AllowNone = false;
var ppr = ed.GetPoint(ppo);
if (ppr.Status != PromptStatus.OK)
return;
var pt1 = ppr.Value;
var pco = new PromptCornerOptions("\nSelect second clip corner: ", pt1);
ppr = ed.GetCorner(pco);
if (ppr.Status != PromptStatus.OK)
return;
var pt2 = ppr.Value;
using (var tr = db.TransactionManager.StartTransaction())
{
// Transform and re-order points
BlockReference br = (BlockReference)tr.GetObject(per.ObjectId, OpenMode.ForRead);
double scale = br.ScaleFactors[0];
var xform =
Matrix2d.Rotation(-br.Rotation, Point2d.Origin) *
Matrix2d.Displacement(new Vector2d(-br.Position.X, -br.Position.Y)) ;
Matrix2d matrix2d = Matrix2d.Scaling(1/scale, Point2d.Origin);
Point2dCollection pts =
new Point2dCollection(2) {
new Point2d(pt1.X, pt1.Y).TransformBy(xform).TransformBy(matrix2d),
new Point2d(pt2.X, pt1.Y).TransformBy(xform).TransformBy(matrix2d),
new Point2d(pt2.X, pt2.Y).TransformBy(xform).TransformBy(matrix2d),
new Point2d(pt1.X, pt2.Y).TransformBy(xform).TransformBy(matrix2d)};
// Create spatial filter
// Just zeroes for the elevation and clip depths
var sfd = new SpatialFilterDefinition(pts, Vector3d.ZAxis, 0.0, 0.0, 0.0, true);
var sf = new SpatialFilter();
sf.Definition = sfd;
// Create extension dictionary if doesn't exist
if (br.ExtensionDictionary == ObjectId.Null)
{
br.UpgradeOpen();
br.CreateExtensionDictionary();
br.DowngradeOpen();
}
// Add spatial filter to extension dictionary
var xDict = (DBDictionary)tr.GetObject(br.ExtensionDictionary, OpenMode.ForWrite);
if (xDict.Contains(filterDictName))
{
var fDict = (DBDictionary)tr.GetObject(xDict.GetAt(filterDictName), OpenMode.ForWrite);
if (fDict.Contains(spatialName))
fDict.Remove(spatialName);
fDict.SetAt(spatialName, sf);
}
else
{
var fDict = new DBDictionary();
xDict.SetAt(filterDictName, fDict);
tr.AddNewlyCreatedDBObject(fDict, true);
fDict.SetAt(spatialName, sf);
}
tr.AddNewlyCreatedDBObject(sf, true);
tr.Commit();
}
ed.Regen();
}