New Member
Posts: 2
Registered: ‎06-08-2013
Message 1 of 3 (183 Views)

Create a viewport in a particular layout

183 Views, 2 Replies
06-09-2013 02:59 AM

Hi everyone,


I'm trying to create a new layout and then adding text and a viewport. The add text works but the add viewport method, written in  AutoCad's Developer Guide, doesn't! Where is the mistake.



Sub MyLayouts(ByVal LayerVal As String)

        '* Create Layout *'

        acDocs = Application.DocumentManager
        acDoc = acDocs.MdiActiveDocument
        acCurDb = acDoc.Database
        Dim acLayoutMgr As LayoutManager = LayoutManager.Current

        acDoc.Editor.WriteMessage(vbLf & [Default].MyApplication & " -> Création d'une présentation. ")

        'Transaction database'
        Using acTrans = acCurDb.TransactionManager.StartTransaction()
            Dim acLayouts As DBDictionary = acTrans.GetObject(acCurDb.LayoutDictionaryId, OpenMode.ForWrite)

            'Erase all layouts startwith "UP2XL"'
            For Each acLayoutEntry As DBDictionaryEntry In acLayouts

                Dim acLayoutEntryName As String = acLayoutEntry.Key

                'If layout starts with "UP2XL" then delete'      
                If acLayoutEntryName.StartsWith([Default].MyApplication) Then
                End If


                'Create new layout'

                Dim acLayoutName As String
                Dim acLayoutId As ObjectId

                'Rename acLayoutName'
                If LayerVal.StartsWith("(" & [Default].MyApplication & ")") Then
                    acLayoutName = [Default].MyApplication & " - " & LayerVal.Remove(0, [Default].MyApplication.Length + 5)
                    acLayoutName = [Default].MyApplication & " - " & LayerVal
                End If

                'Creating new layout'
                acLayoutId = acLayoutMgr.CreateLayout(acLayoutName)

               'Create text and viewport in this particular layout'

                Dim acLayout As Layout = DirectCast(acTrans.GetObject(acLayoutId, OpenMode.ForRead), Layout)
                Dim acLayoutBlkTblRec As BlockTableRecord = DirectCast(acTrans.GetObject(acLayout.BlockTableRecordId, OpenMode.ForWrite), BlockTableRecord)

                'Insert text'
                Dim acMText As MText = New MText()

                With acMText
                    .Location = New Point3d(0, 0, 0)
                    .Attachment = AttachmentPoint.BottomLeft
                    .TextHeight = 2
                    .ColorIndex = 7
                    .Contents = acLayoutName.ToString
                End With

                acTrans.AddNewlyCreatedDBObject(acMText, True)

                'Insert a Viewport'              
                Dim acVport As Viewport = New Viewport()

                With acVport
                    .CenterPoint = New Point3d(3.25, 3, 0)
                    .Width = 6
                    .Height = 5
                End With

                acTrans.AddNewlyCreatedDBObject(acVport, True)
                acVport.On = True
                '' Update the layout
                'Application des changements'

                'Fin de transaction'

            Catch ex As Autodesk.AutoCAD.Runtime.Exception
            End Try

        End Using

        'Actualisation du dessin courant'

    End Sub


See you.


*Expert Elite*
Posts: 1,569
Registered: ‎10-08-2008
Message 2 of 3 (154 Views)

Re: Create a viewport in a particular layout

06-09-2013 12:58 PM in reply to: mmarle
Try this xample written by Gile from this page:
New Member
Posts: 2
Registered: ‎06-08-2013
Message 3 of 3 (129 Views)

Re : Create a viewport in a particular layout

06-10-2013 07:10 AM in reply to: mmarle

TY Hallex!


See you (MGO_MKD)

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.