.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Block are not visible after clipping

0 REPLIES 0
Reply
Message 1 of 1
manasi_patilESZTV
139 Views, 0 Replies

Block are not visible after clipping

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();
}

Labels (4)
0 REPLIES 0

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report