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

Viewport from entity, on and inactive

5 REPLIES 5
Reply
Message 1 of 6
martinduke2653
431 Views, 5 Replies

Viewport from entity, on and inactive

Hello Everyone.

I have a routine that creates a new viewport from an existing entity, ie a circle or polyline or any other allowed class. My routine creates the viewport, but, it is always on and Inactive, and I cannot find a way to make it on and active. does anyone have any ideas?

Here is my code:

Public Function MakeVP(ByVal eID As ObjectId, ByVal Scale As String, ByVal PrimaryUnit As ePrimaryUnits, ByVal Locked As Boolean)
Dim OID As ObjectId
Dim DB As Database = HostApplicationServices.WorkingDatabase()
Dim Trans As Transaction = DB.TransactionManager.StartTransaction()
Try
Dim acVP As Viewport = New Viewport
Dim pCP As New Point3d
Dim AScale As AnnotationScale = ScaleManager.MakeScale(Scale, PrimaryUnit)
Dim bt As BlockTable = Trans.GetObject(DB.BlockTableId, OpenMode.ForRead)
Dim btr As BlockTableRecord = Trans.GetObject(bt(BlockTableRecord.PaperSpace), OpenMode.ForWrite)

acVP.NonRectClipEntityId = eID
acVP.NonRectClipOn = True

OID = btr.AppendEntity(acVP)
Trans.AddNewlyCreatedDBObject(acVP, True)

acVP = Trans.GetObject(OID, OpenMode.ForWrite, False, True)
acVP.Locked = Locked

acVP.CustomScale = IIf(PrimaryUnit = ePrimaryUnits.m, 1000.0 / CDbl(Scale), 1.0 / CDbl(Scale))
acVP.CustomScale = 20
acVP.On = True
acVP.AnnotationScale = AScale
Trans.Commit()

Catch aex As Autodesk.AutoCAD.Runtime.Exception
Microsoft.VisualBasic.Interaction.MsgBox("AutoCAD Exception (VIEWPORT): " & aex.Message, MsgBoxStyle.Exclamation)
Catch ex As System.Exception
Microsoft.VisualBasic.Interaction.MsgBox("System Exception: " & ex.Message, MsgBoxStyle.Exclamation)
Finally
Trans.Dispose()
End Try
End Function


Any help would be greatly appreciated.

Regards


Martin Duke
5 REPLIES 5
Message 2 of 6
Anonymous
in reply to: martinduke2653

I haven't test your code, just a thought
Your function nmust be return ObjectID of
newly creared viewport, then you can
set them active

eg.
Public Function MakeVP(ByVal eID As ObjectId, ByVal Scale As String, ByVal PrimaryUnit As ePrimaryUnits, ByVal Locked As Boolean) As ObjectID
dim someID as ObjectID
========code goes here
Return SomeID
End Function

~'J'~
Message 3 of 6

Hello,

Thank you for your suggestion. Yes I can easily return the objectID of the newly created viewport, but there is no property for a viewport that I can see that relates to whether is is active. And I can see no where, to set the active viewport. Do you know how I can do this?

Regards

Martin Duke
Message 4 of 6
Anonymous
in reply to: martinduke2653

Sorry, Martin
I've tryed to solve it but with no luck yet
I don't know how to do it
:(

~'J'~
Message 5 of 6
djonio
in reply to: martinduke2653

Martin,
I am using Map3d 2007 .... there is not an AutoCAD .NET method to set the current viewport ... So ... i think something like this will work.

Autodesk.AutoCAD.EditorInput.Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
Database db = HostApplicationServices.WorkingDatabase;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
LayoutManager layoutMgr = LayoutManager.Current;
Layout layoutObj;

layoutMgr.CreateLayout("testLayout");
layoutMgr.CurrentLayout = "testLayout";

ObjectId objId = layoutMgr.GetLayoutId("testLayout");
layoutObj = (Layout)tr.GetObject(objId, OpenMode.ForWrite);

BlockTableRecord r = (BlockTableRecord)tr.GetObject(layoutObj.BlockTableRecordId, OpenMode.ForWrite);
Viewport vp = new Viewport();
r.AppendEntity(vp);
tr.AddNewlyCreatedDBObject(vp, true);

vp.Height = 5;
vp.Width = 6;
vp.CenterPoint = new Point3d(5, 5, 0);

vp.ViewHeight = 10;
vp.ViewCenter = new Point2d(2.5, 2.5);
vp.Visible = true;
vp.On = true;
vp.UpdateDisplay();

ed.SwitchToModelSpace();
Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("CVPORT", vp.Number);

tr.Commit();
}

If the Layout is current then the vp.number is the same as CVPORT.
Message 6 of 6

Hello,

Thank you for your help. I have actually tried this already and it works. This being, creating a new viewport and then setting the height and width. The problem arises when you try to create a viewport from an existing object. I will offer my users three choices for creating a managed viewport, 1 a window, 2 a polygon and 3 an existing object, and it is this that is proving most troublesome.


Kind regards

Martin Duke

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost