Setting current viewport

Setting current viewport

Anonymous
Not applicable
3,704 Views
4 Replies
Message 1 of 5

Setting current viewport

Anonymous
Not applicable
How can I activate a particular paperspace viewport using VB.Net? In VBA,
the document object had an "Active Viewport" property and you just did
ActiveDocument.ActiveViewport = myvport.
I can't find a similar property in VB.Net.

I've found the "CurrentViewportObjectID" as a property of the document
editor, but it's a read-only property and I can't find out where it gets
set.

Can anyone guide me? I've searched the discussion groups and Google, but
can't find anything.

Thanks in advance. . .
0 Likes
3,705 Views
4 Replies
Replies (4)
Message 2 of 5

bikelink
Contributor
Contributor
I have the same problem. The docs isn't correct. the property about the viewport not exists.
How can I set the current viewport in paper space (layout) without use property Number?
0 Likes
Message 3 of 5

Anonymous
Not applicable
Still no answer to this question? I believe this link has some relevance but the solution is still not intuitive. Well for me.

http://discussion.autodesk.com/forums/thread.jspa?threadID=455076

Have you found the answer?
0 Likes
Message 4 of 5

Anonymous
Not applicable
That code doesn't show the solution.

The only solutions are to P/Invoke acedSetCurrentVPort() or use the CVPORT
system variable.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm


wrote in message news:[email protected]...
Still no answer to this question? I believe this link has some relevance but
the solution is still not intuitive. Well for me.
http://discussion.autodesk.com/forums/thread.jspa?threadID=455076 Have you
found the answer?
0 Likes
Message 5 of 5

Anonymous
Not applicable



Thanks Tony for the direction. CVPORT? could not get it to work (send commands to command line) except in the modelspace tab. In any paperspace tab the command itself CVPORT does not work?? So I used the p/invoke acedSetCurrentVport() method. there were two great blogs I referenced.

Kean Walmsleys described a method for extracting the function line from the acad.exe file:

http://through-the-interface.typepad.com/through_the_interface/2006/07/calling_objecta.html



And using the afore mentioned example as guide:

http://discussion.autodesk.com/forums/thread.jspa?messageID=6123415?



It seems to be working, (not pretty, but moving forward!):



'pinvoke acedSetCurrentVport function out of acad.exe file

<DllImport("acad.exe", CallingConvention:=CallingConvention.Cdecl, _

EntryPoint:="?acedSetCurrentVPort@@YA?AW4ErrorStatus@Acad@@PBVAcDbViewport@@@Z")> _

Public Shared Function acedSetCurrentVPort(ByVal AcDbVport As IntPtr) As IntPtr

End Function



///////////////////////////////// after switching layout tabs to desired and zoom extents ///////////////////////////////////////////////////////////////

'*************************************** find viewport and activate **************************************

Dim ed As Editor = ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor

Dim db As Database = HostApplicationServices.WorkingDatabase

Try

Dim layoutManager__1 As LayoutManager = LayoutManager.Current

layoutManager__1.CurrentLayout = "Floor Plan 100"

Dim vpXdim As String = ("18") 'viewport desired's CenterPoint X value



Dim layout As Layout = TryCast(myTrans.GetObject(layoutManager__1.GetLayoutId _

("Floor Plan 100"), OpenMode.ForRead), Layout)



Dim objectIdCollection As ObjectIdCollection = layout.GetViewports()



For Each VportObjId As ObjectId In objectIdCollection

Dim Vport As Viewport = DirectCast(myTrans.GetObject(VportObjId, OpenMode.ForWrite), Viewport)

' Dim AcDbVport As AcDbViewport = DirectCast(myTrans.GetObject(Vport, OpenMode.ForWrite), AcDbViewport)



Dim X As String = Vport.CenterPoint.X.ToString

If vpXdim = X Then 'center point X value = given X value > this is desired viewport





//////////////////////////////////////////////// heres the gem!! //////////////////////////////////////////////////////////

acedSetCurrentVPort(Vport.UnmanagedObject) 'set Vport as current viewport



myDWG.Editor.SwitchToModelSpace() 'switch to modelspace

Exit For

End If

Next

Catch ex As System.Exception

ed.WriteMessage(vbLf & ex.Message)

ed.WriteMessage(vbLf & ex.StackTrace)

End Try



thanks again Tony, learned a bunch, now how the #$%#$% do you get this to format in a post?









0 Likes