CREATE VIEWPORT FROM POLYLINE IN MODEL SPACE BY C#

CREATE VIEWPORT FROM POLYLINE IN MODEL SPACE BY C#

khang.civil.2000
Contributor Contributor
4,191 Views
4 Replies
Message 1 of 5

CREATE VIEWPORT FROM POLYLINE IN MODEL SPACE BY C#

khang.civil.2000
Contributor
Contributor

I have polyline close in model space . I want create viewport from this polyline, but I do'nt know how do.

You can help me?

Thank you very much!!!

 

This my code:

 

 

private void button1_Click(object sender, EventArgs e)
{
acad.Document _doc = acad.Application.DocumentManager.MdiActiveDocument;
Database db = _doc.Database;
Editor _ed = _doc.Editor;
//var ext = new Extents2d();
using (acad.DocumentLock _lock = _doc.LockDocument())
{
using (Transaction _tr = db.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)_tr.GetObject(db.BlockTableId, OpenMode.ForRead);
DBObjectCollection objs = new DBObjectCollection();
for (int i = 0; i < _ListKhungView.Count; i++)
{
Polyline _pl = _ListKhungView[i];
//Tạo layout mới
ObjectId id = LayoutManager.Current.CreateLayout("A" + i.ToString());
Layout lay = (Layout)_tr.GetObject(id, OpenMode.ForWrite);

// tạo 1 polyline copy
Polyline _plClone = _pl.Clone() as Polyline;
// Mở Block table record in paperSpace
BlockTableRecord ps = (BlockTableRecord)_tr.GetObject(lay.BlockTableRecordId, OpenMode.ForWrite);

ps.AppendEntity(_plClone);
_tr.AddNewlyCreatedDBObject(_plClone, true);
Viewport vp = new Viewport();
vp.SetDatabaseDefaults();
ps.AppendEntity(vp);
_tr.AddNewlyCreatedDBObject(vp, true);
vp.NonRectClipEntityId = _plClone.ObjectId;
vp.NonRectClipOn = true;
//vp.On = true;

vp.CustomScale = 1;
}

_tr.Commit();
}

acad.Application.UpdateScreen();

}
}
0 Likes
Accepted solutions (1)
4,192 Views
4 Replies
Replies (4)
Message 2 of 5

mgarcesUX9HW
Enthusiast
Enthusiast
Accepted solution

hi im  not sure what you want but here is the options.

 

1. in the paperspace just type mview to create viewport and scale it as you want

2. or copy your polyline in the model space and paste in the paperspace, you can scale down the polyline or you can just leave it 1:1, then type mview, then type o to select the object you want to become viewport, then select he polyline and then the polyline will be converted to viewport

Message 3 of 5

khang.civil.2000
Contributor
Contributor
I'm going in the direction of option 2
Message 4 of 5

mgarcesUX9HW
Enthusiast
Enthusiast

hi if this answers your question can you please click the accept button thanks!

Message 5 of 5

khang.civil.2000
Contributor
Contributor

you can check my code above?

Thank you very much!