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

How to access viewports in paperspace

9 REPLIES 9
Reply
Message 1 of 10
Anonymous
1275 Views, 9 Replies

How to access viewports in paperspace

I would like to access all the viewports defined in the paperspace. Can
someone point out a sample code that shows how to do that?

Thanks! Gagan.
9 REPLIES 9
Message 2 of 10
Siamak
in reply to: Anonymous

I have the same problem. how to avtivate/deactivate a viewport with vb.net (mspcace/pspace)
Message 3 of 10
Anonymous
in reply to: Anonymous

Gagan Gajabaharia wrote:
> I would like to access all the viewports defined in the paperspace. Can
> someone point out a sample code that shows how to do that?
>
> Thanks! Gagan.

Never mind, I found the solution in the recently put online .NET ARX
help document:

_
Public Sub DoVports3()
'' Get the current document and database, and start a transaction
Dim acDoc As Document =
Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database

Using acTrans As Transaction =
acCurDb.TransactionManager.StartTransaction()
'' Open the Block table for read
Dim acBlkTbl As BlockTable
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
OpenMode.ForRead)

'' Open the Block table record Paper space for write
Dim acBlkTblRec As BlockTableRecord
acBlkTblRec =
acTrans.GetObject(acBlkTbl(BlockTableRecord.PaperSpace), OpenMode.ForRead)

'' Switch to the previous Paper space layout
Application.SetSystemVariable("TILEMODE", 0)
acDoc.Editor.SwitchToPaperSpace()

' Enumerate the BTR
Dim pBTREnum As BlockTableRecordEnumerator =
acBlkTblRec.GetEnumerator()
While (pBTREnum.MoveNext())
Dim pObjId As ObjectId = pBTREnum.Current
Dim pDbObj As DBObject = acTrans.GetObject(pObjId,
OpenMode.ForWrite, False, True)
If (TypeOf pDbObj Is Viewport) Then
Dim pVprt As Viewport = DirectCast(pDbObj,
Viewport)
End If
End While

'' Save the new objects to the database
acTrans.Commit()
End Using

End Sub
Message 4 of 10
Anonymous
in reply to: Anonymous

siamak wrote:
> I have the same problem. how to avtivate/deactivate a viewport with vb.net (mspcace/pspace)

Seems you need to use DllImport directive to set the current viewport.
Here's the sample code from the help file:


EntryPoint:="?acedSetCurrentVPort@@YA?AW4ErrorStatus@Acad@@PBVAcDbViewport@@@Z")>
_
Public Shared Function acedSetCurrentVPort(ByVal AcDbVport As
IntPtr) As IntPtr
End Function

_
Public Sub CreateFloatingViewport()
'' Get the current document and database, and start a transaction
Dim acDoc As Document =
Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database

Using acTrans As Transaction =
acCurDb.TransactionManager.StartTransaction()
'' Open the Block table for read
Dim acBlkTbl As BlockTable
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
OpenMode.ForRead)

'' Open the Block table record Paper space for write
Dim acBlkTblRec As BlockTableRecord
acBlkTblRec =
acTrans.GetObject(acBlkTbl(BlockTableRecord.PaperSpace), OpenMode.ForWrite)

'' Switch to the previous Paper space layout
Application.SetSystemVariable("TILEMODE", 0)
acDoc.Editor.SwitchToPaperSpace()

'' Create a Viewport
Dim acVport As Viewport = New Viewport()
acVport.SetDatabaseDefaults()
acVport.CenterPoint = New Point3d(3.25, 3, 0)
acVport.Width = 6
acVport.Height = 5

'' Add the new object to the block table record and the
transaction
acBlkTblRec.AppendEntity(acVport)
acTrans.AddNewlyCreatedDBObject(acVport, True)

'' Change the view direction
acVport.ViewDirection = New Vector3d(1, 1, 1)

'' Enable the viewport
acVport.On = True

'' Activate model space in the viewport
acDoc.Editor.SwitchToModelSpace()

'' Set the new viewport current via an imported ObjectARX
function
acedSetCurrentVPort(acVport.UnmanagedObject)

'' Save the new objects to the database
acTrans.Commit()
End Using

End Sub
Message 5 of 10
Anonymous
in reply to: Anonymous

Are there code examples from the Autodesk docs that show the use of
GetEnumerator()/MoveNext()/Current?

--
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

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");


"Gagan Gajabaharia" wrote in message
news:6227427@discussion.autodesk.com...
Gagan Gajabaharia wrote:
> I would like to access all the viewports defined in the paperspace. Can
> someone point out a sample code that shows how to do that?
>
> Thanks! Gagan.

Never mind, I found the solution in the recently put online .NET ARX
help document:

_
Public Sub DoVports3()
'' Get the current document and database, and start a transaction
Dim acDoc As Document =
Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database

Using acTrans As Transaction =
acCurDb.TransactionManager.StartTransaction()
'' Open the Block table for read
Dim acBlkTbl As BlockTable
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
OpenMode.ForRead)

'' Open the Block table record Paper space for write
Dim acBlkTblRec As BlockTableRecord
acBlkTblRec =
acTrans.GetObject(acBlkTbl(BlockTableRecord.PaperSpace), OpenMode.ForRead)

'' Switch to the previous Paper space layout
Application.SetSystemVariable("TILEMODE", 0)
acDoc.Editor.SwitchToPaperSpace()

' Enumerate the BTR
Dim pBTREnum As BlockTableRecordEnumerator =
acBlkTblRec.GetEnumerator()
While (pBTREnum.MoveNext())
Dim pObjId As ObjectId = pBTREnum.Current
Dim pDbObj As DBObject = acTrans.GetObject(pObjId,
OpenMode.ForWrite, False, True)
If (TypeOf pDbObj Is Viewport) Then
Dim pVprt As Viewport = DirectCast(pDbObj,
Viewport)
End If
End While

'' Save the new objects to the database
acTrans.Commit()
End Using

End Sub
Message 6 of 10
Anonymous
in reply to: Anonymous

Tony Tanzillo wrote:
> Are there code examples from the Autodesk docs that show the use of
> GetEnumerator()/MoveNext()/Current?
>

Sorry, I don't get your question. My gut feeling is there must be - but
you would know that already, wouldn't you?

The code that I posted is based on this code that shows how to create a
viewport in paper space at this url:

http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer%27s%20Guide/index.html

Please search for the term "Viewport" and you will get several hits. The
very first is "Create paperspace viewports"

Gagan
===========
Message 7 of 10
Anonymous
in reply to: Anonymous

{quote}

Sorry, I don't get your question. My gut feeling is there must be - but
you would know that already, wouldn't you?

{quote}

No, I wouldn't know because I don't have time to read their materials.

{quote}

The code that I posted is based on this code that shows how to create a
viewport in paper space at this url:

{quote}

I asked that question because using GetEnumerator()/MoveNext()/etc. is the
wrong way to iterate collections. To wit, a recent post here demonstrates
how using it can even cause AutoCAD to crash (sorry forget the subject
line).

If any Autodesk code samples use GetEnumerator() then shame on them.

--
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

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");


"Gagan Gajabaharia" wrote in message
news:6227663@discussion.autodesk.com...
Tony Tanzillo wrote:
> Are there code examples from the Autodesk docs that show the use of
> GetEnumerator()/MoveNext()/Current?
>

Sorry, I don't get your question. My gut feeling is there must be - but
you would know that already, wouldn't you?

The code that I posted is based on this code that shows how to create a
viewport in paper space at this url:

http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer%27s%20Guide/index.html

Please search for the term "Viewport" and you will get several hits. The
very first is "Create paperspace viewports"

Gagan
===========
Message 8 of 10
Anonymous
in reply to: Anonymous

Tony Tanzillo wrote:
>
> No, I wouldn't know because I don't have time to read their materials.
>
I understand. I mostly develop software solutions for spatial sciences,
and sometimes I am required to develop on AutoCAD platform, and that
forces me to read their material - whatever that I find. I wish I never
have to develop on AutoCAD platform, though.
>
> I asked that question because using GetEnumerator()/MoveNext()/etc. is the
> wrong way to iterate collections. To wit, a recent post here demonstrates
> how using it can even cause AutoCAD to crash (sorry forget the subject
> line).
>
> If any Autodesk code samples use GetEnumerator() then shame on them.

I never had any problems with GetEnumerator from VB.NET or C#. But I
learn hard way that the enumerator is required to be deleted explicitly
to avoid crashes if used from managed C++; I don't know why though.

Thanks for your comments.

Gagan
===============
Message 9 of 10
Anonymous
in reply to: Anonymous

Right.

The object returned by GetEnumerator() sometimes supports
IDisposable and if it does, its Dispose() method must be
called when finished using it.


--
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

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");


"Gagan Gajabaharia" wrote in message
news:6228254@discussion.autodesk.com...
Tony Tanzillo wrote:
>
> No, I wouldn't know because I don't have time to read their materials.
>
I understand. I mostly develop software solutions for spatial sciences,
and sometimes I am required to develop on AutoCAD platform, and that
forces me to read their material - whatever that I find. I wish I never
have to develop on AutoCAD platform, though.
>
> I asked that question because using GetEnumerator()/MoveNext()/etc. is the
> wrong way to iterate collections. To wit, a recent post here demonstrates
> how using it can even cause AutoCAD to crash (sorry forget the subject
> line).
>
> If any Autodesk code samples use GetEnumerator() then shame on them.

I never had any problems with GetEnumerator from VB.NET or C#. But I
learn hard way that the enumerator is required to be deleted explicitly
to avoid crashes if used from managed C++; I don't know why though.

Thanks for your comments.

Gagan
===============
Message 10 of 10
Anonymous
in reply to: Anonymous

Tony Tanzillo wrote:
> Right.
>
> The object returned by GetEnumerator() sometimes supports
> IDisposable and if it does, its Dispose() method must be
> called when finished using it.
>
>
Thanks for the insight.

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