.NET

.NET

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

Create a viewport in a particular layout

186 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 *'
        '*********************'

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

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

                'Declaration'
                Dim acLayoutEntryName As String = acLayoutEntry.Key

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

            Next

            Try
                'Create new layout'

                'Declaration'
                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)
                Else
                    acLayoutName = [Default].MyApplication & " - " & LayerVal
                End If

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

               'Create text and viewport in this particular layout'

               'Declaration
                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
                    .SetDatabaseDefaults()
                    .Location = New Point3d(0, 0, 0)
                    .Attachment = AttachmentPoint.BottomLeft
                    .TextHeight = 2
                    .ColorIndex = 7
                    .Contents = acLayoutName.ToString
                End With

                acLayoutBlkTblRec.AppendEntity(acMText)
                acTrans.AddNewlyCreatedDBObject(acMText, True)

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

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

                acLayoutBlkTblRec.AppendEntity(acVport)
                acTrans.AddNewlyCreatedDBObject(acVport, True)
                acVport.On = True
      
                '' Update the layout
                acLayout.UpgradeOpen()
             
                'Application des changements'
                acTrans.Commit()

                'Fin de transaction'
                acTrans.Dispose()

            Catch ex As Autodesk.AutoCAD.Runtime.Exception
                MsgBox(ex.Message)
            End Try

        End Using

        'Actualisation du dessin courant'
        acDoc.Editor.Regen()

    End Sub

 

See you.

 

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 2 of 3 (157 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:
http://www.acadnetwork.com/topic-50.msg64.html#msg64
_____________________________________
C6309D9E0751D165D0934D0621DFF27919
New Member
mmarle
Posts: 2
Registered: ‎06-08-2013
Message 3 of 3 (132 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
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.