TheSwamp
Code Red => .NET => Topic started by: xys1995 on November 11, 2016, 03:47:52 AM
-
I want to create a polygon viewport in a layout using a closed polyline in modelspace,the entities included in the polyline area will be displayed in the viewport.
can anybody give me some information?
Using c# to create the viewport.
Please see the attach file.
-
Polyline viewport is created if Viewport.NonrectClipEntityId property is assigned to a polyline's ObjectId, and set Viewport.NonRectClipOn property to "true". So, simply create a viewportand a polyline, then set the 2 Viewport properties. You are done.
The code shown here assumes that there are already a viewport and a polyline in a layout. The code simply combine the both to be a non-rectangular viewport:
[CommandMethod("MyPort")]
public static void RunDocCommand()
{
var doc = CadApp.DocumentManager.MdiActiveDocument;
var ed = doc.Editor;
var vportId = SelectEntity(
ed, typeof(Viewport), "\nSelect a regular viewport:");
var polyId = SelectEntity(
ed, typeof(Polyline), "\nSelect a polyline inside the viewport:");
if (vportId.IsNull || polyId.IsNull)
{
ed.WriteMessage("\n*Cancel*\n");
return;
}
using (var tran = doc.TransactionManager.StartTransaction())
{
Viewport vport = (Viewport)tran.GetObject(vportId, OpenMode.ForWrite);
vport.NonRectClipEntityId = polyId;
vport.NonRectClipOn = true;
tran.Commit();
}
}
private static ObjectId SelectEntity(
Editor ed, Type entType, string selectionMsg)
{
var opt = new PromptEntityOptions(selectionMsg);
opt.SetRejectMessage("\nInvalid selection.");
opt.AddAllowedClass(entType, true);
var res = ed.GetEntity(opt);
if (res.Status == PromptStatus.OK)
return res.ObjectId;
else
return ObjectId.Null;
}
For rectangular viewport, the NonRectClipEntityId property is set to ObjectId.Null.
HTH