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

CREATE VIEWPORT FROM POLYLINE IN MODEL SPACE BY C#

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
khang.civil.2000
2410 Views, 4 Replies

CREATE VIEWPORT FROM POLYLINE IN MODEL SPACE BY C#

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

}
}
Labels (2)
4 REPLIES 4
Message 2 of 5

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

I'm going in the direction of option 2
Message 4 of 5

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

Message 5 of 5

you can check my code above?

Thank you very much!

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report