I am using below code for wipeout using ployline/rectangle but facing issue not able to perform operation
geeting error at wipeout.SetBoundary(polyId);
setboundary no accessible extension..
anyone any idea ?
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptPointOptions ppo = new PromptPointOptions("\nSelect first corner of the rectangle: ");
PromptPointResult ppr1 = ed.GetPoint(ppo);
if (ppr1.Status == PromptStatus.OK)
{
Point3d firstCorner = ppr1.Value;
ppo.Message = "\nSelect opposite corner of the rectangle: ";
ppo.UseBasePoint = true;
ppo.BasePoint = firstCorner;
PromptPointResult ppr2 = ed.GetPoint(ppo);
if (ppr2.Status == PromptStatus.OK)
{
Point3d secondCorner = ppr2.Value;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord btr = tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
// Define wipeout vertices
Point3d[] vertices =
{
firstCorner,
new Point3d(secondCorner.X, firstCorner.Y, 0),
secondCorner,
new Point3d(firstCorner.X, secondCorner.Y, 0)
};
// Create polyline for wipeout
Polyline poly = new Polyline();
for (int i = 0; i < vertices.Length; i++)
{
poly.AddVertexAt(i, new Point2d(vertices[i].X, vertices[i].Y), 0, 0, 0);
}
poly.Closed = true;
// Add polyline to the drawing
ObjectId polyId = btr.AppendEntity(poly);
tr.AddNewlyCreatedDBObject(poly, true);
// Create wipeout
Wipeout wipeout = new Wipeout();
wipeout.SetDatabaseDefaults();
// Set wipeout boundary using polyline
wipeout.SetBoundary(polyId);
// Add wipeout to the drawing
ObjectId wipeoutId = btr.AppendEntity(wipeout);
tr.AddNewlyCreatedDBObject(wipeout, true);
// Display changes
tr.Commit();
}
}
}
Solved! Go to Solution.
Solved by _gile. Go to Solution.
Hi,
You can use Wipeout.SetFrom().
[CommandMethod("TEST")]
public static void Test()
{
var doc = Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
var ppr = ed.GetPoint("\nSelect first corner of the rectangle: ");
if (ppr.Status != PromptStatus.OK) return;
var pt1 = ppr.Value;
ppr = ed.GetCorner("\nSpecify the opposite corner of the rectangle: ", pt1);
if (ppr.Status != PromptStatus.OK) return;
var pt2 = ppr.Value;
double xMin = Math.Min(pt1.X, pt2.X);
double yMin = Math.Min(pt1.Y, pt2.Y);
double xMax = Math.Max(pt1.X, pt2.X);
double yMax = Math.Max(pt1.Y, pt2.Y);
var points = new Point2dCollection
{
new Point2d(xMin, yMin),
new Point2d(xMax, yMin),
new Point2d(xMax, yMax),
new Point2d(xMin, yMax),
new Point2d(xMin, yMin)
};
using (var tr = db.TransactionManager.StartTransaction())
{
var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
var wipeout = new Wipeout();
wipeout.SetDatabaseDefaults();
wipeout.SetFrom(points, Vector3d.ZAxis);
curSpace.AppendEntity(wipeout);
tr.AddNewlyCreatedDBObject(wipeout, true);
tr.Commit();
}
}
Thanks your solution worked for me. It may me other topic but can we highlight the wipedout part ie.. filled with any color? Attached is your working code.
OK I was tying to Achieve below thing which will mask the selected area and mark it.. thought wipeout will solve the issue but looks wipeout works in different way.. so was checking options how to do this . if any idea ?
Here's a way to draw a Solid entity by specifying 3 or 4 points:
[CommandMethod("JIGSOL")]
public void JigSolid()
{
var doc = AcAp.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
var options = new PromptPointOptions("\nSpecify the 1st point: ");
var result = ed.GetPoint(options);
if (result.Status != PromptStatus.OK) return;
var pt1 = result.Value;
options.Message = "\nSpecify the 2nd point: ";
options.BasePoint = pt1;
options.UseBasePoint = true; result = ed.GetPoint(options);
if (result.Status != PromptStatus.OK) return;
var pt2 = result.Value;
var ucs = ed.CurrentUserCoordinateSystem;
var pt3 = pt1 + pt1.GetVectorTo(pt2).CrossProduct(ucs.CoordinateSystem3d.Zaxis);
using (var tr = db.TransactionManager.StartTransaction())
using (var solid = new Solid(pt1, pt2, pt3))
{
solid.TransformBy(ucs);
solid.SetDatabaseDefaults();
var jig = new SolidJig(solid, false);
var promptResult = ed.Drag(jig);
if (promptResult.Status == PromptStatus.OK)
{
jig = new SolidJig(solid, true);
promptResult = ed.Drag(jig);
if (promptResult.Status == PromptStatus.None)
solid.SetPointAt(2, solid.GetPointAt(3));
else if (promptResult.Status != PromptStatus.OK)
return;
var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
curSpace.AppendEntity(solid);
tr.AddNewlyCreatedDBObject(solid, true);
}
tr.Commit();
}
}
class SolidJig : EntityJig
{
Solid solid;
bool fourthPoint;
Point3d dragPoint;
public SolidJig(Solid solid, bool fourthPoint) : base(solid)
{
this.solid = solid;
this.fourthPoint = fourthPoint;
}
protected override SamplerStatus Sampler(JigPrompts prompts)
{
var options = new JigPromptPointOptions();
options.Message = fourthPoint ?
"\nSpecify the 4th point (or Enter to quit): " :
"\nSpecify the 3rd point: ";
options.UserInputControls =
UserInputControls.Accept3dCoordinates |
UserInputControls.GovernedByOrthoMode |
UserInputControls.GovernedByUCSDetect |
UserInputControls.NullResponseAccepted;
var result = prompts.AcquirePoint(options);
if (result.Value.IsEqualTo(dragPoint))
return SamplerStatus.NoChange;
dragPoint = result.Value;
return SamplerStatus.OK;
}
protected override bool Update()
{
solid.SetPointAt(2, dragPoint);
if (!fourthPoint)
solid.SetPointAt(3, dragPoint);
return true;
}
}
And a way to draw a rectangular Solid entity (the rectangle is always parallel to the view).
[CommandMethod("RECSOL")]
public static void RECSOL()
{
var doc = Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
var ppr = ed.GetPoint("\nSelect first corner of the rectangle: ");
if (ppr.Status != PromptStatus.OK) return;
var pt1 = ppr.Value;
ppr = ed.GetCorner("\nSpecify the opposite corner of the rectangle: ", pt1);
if (ppr.Status != PromptStatus.OK) return;
var pt2 = ppr.Value;
using (var view = ed.GetCurrentView())
{
var eyeToWorld =
Matrix3d.Rotation(-view.ViewTwist, view.ViewDirection, view.Target) *
Matrix3d.Displacement(view.Target.GetAsVector()) *
Matrix3d.PlaneToWorld(view.ViewDirection);
var worldToEye =
Matrix3d.WorldToPlane(view.ViewDirection) *
Matrix3d.Displacement(view.Target.GetAsVector().Negate()) *
Matrix3d.Rotation(view.ViewTwist, view.ViewDirection, view.Target);
var ucsMat = ed.CurrentUserCoordinateSystem;
var ucs = ucsMat.CoordinateSystem3d;
var plane = new Plane(ucs.Origin, ucs.Zaxis);
Point3d Ucs2Dcs(Point3d p) =>
p.Project(plane, view.ViewDirection).TransformBy(worldToEye * ucsMat);
pt1 = Ucs2Dcs(pt1);
pt2 = Ucs2Dcs(pt2);
double xMin = Math.Min(pt1.X, pt2.X);
double yMin = Math.Min(pt1.Y, pt2.Y);
double xMax = Math.Max(pt1.X, pt2.X);
double yMax = Math.Max(pt1.Y, pt2.Y);
Point3d Dcs2Wcs(Point3d p) =>
p.TransformBy(eyeToWorld).Project(new Plane(), view.ViewDirection);
var p1 = Dcs2Wcs(new Point3d(xMin, yMin, 0.0));
var p2 = Dcs2Wcs(new Point3d(xMax, yMin, 0.0));
var p3 = Dcs2Wcs(new Point3d(xMin, yMax, 0.0));
var p4 = Dcs2Wcs(new Point3d(xMax, yMax, 0.0));
using (var tr = db.TransactionManager.StartTransaction())
{
var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
var solid = new Solid(p1, p2, p3, p4);
solid.SetDatabaseDefaults();
curSpace.AppendEntity(solid);
tr.AddNewlyCreatedDBObject(solid, true);
tr.Commit();
}
}
}
Thanks for help.. I tried using the Hash so I can assign the desired layer to the solid part.
[CommandMethod("RECSOL")]
public static void RECSOL()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
// Define the rectangle points
Point3d startPoint = new Point3d(0, 0, 0);
Point3d endPoint = new Point3d(10, 10, 0);
// Prompt for the rectangle points
PromptPointOptions ppo = new PromptPointOptions("\nEnter first corner of the rectangle: ");
PromptPointResult ppr = ed.GetPoint(ppo);
if (ppr.Status != PromptStatus.OK) return;
startPoint = ppr.Value;
ppo.Message = "\nEnter opposite corner of the rectangle: ";
ppr = ed.GetPoint(ppo);
if (ppr.Status != PromptStatus.OK) return;
endPoint = ppr.Value;
// Create the rectangle
using (Transaction tr = db.TransactionManager.StartTransaction())
{
doc.LockDocument();
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
// Add the rectangle to the drawing
Polyline rect = new Polyline();
rect.AddVertexAt(0, new Point2d(startPoint.X, startPoint.Y), 0, 0, 0);
rect.AddVertexAt(1, new Point2d(endPoint.X, startPoint.Y), 0, 0, 0);
rect.AddVertexAt(2, new Point2d(endPoint.X, endPoint.Y), 0, 0, 0);
rect.AddVertexAt(3, new Point2d(startPoint.X, endPoint.Y), 0, 0, 0);
rect.Closed = true;
btr.AppendEntity(rect);
tr.AddNewlyCreatedDBObject(rect, true);
// Create a solid fill hatch to mask the rectangle
Hatch hatch = new Hatch();
hatch.SetDatabaseDefaults();
hatch.Normal = Vector3d.ZAxis;
hatch.Elevation = 0;
hatch.PatternScale = 1;
hatch.SetHatchPattern(HatchPatternType.PreDefined, "ZIGZAG");
//hatch.PatternName = "SOLID";
hatch.Layer = "M-Grid";
//hatch.Color = Autodesk.AutoCAD.Colors.Color.FromRgb(255, 255, 255); // White color
hatch.AppendLoop(HatchLoopTypes.External, new ObjectIdCollection { rect.ObjectId });
hatch.EvaluateHatch(true);
// Add the hatch to the drawing
btr.AppendEntity(hatch);
tr.AddNewlyCreatedDBObject(hatch, true);
tr.Commit();
}
}
Can't find what you're looking for? Ask the community or share your knowledge.