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

Create a viewport in a particular layout

2 REPLIES 2
Reply
Message 1 of 3
mmarle
453 Views, 2 Replies

Create a viewport in a particular layout

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.

 

2 REPLIES 2
Message 2 of 3
Hallex
in reply to: mmarle

Try this xample written by Gile from this page:
http://www.acadnetwork.com/topic-50.msg64.html#msg64
_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 3 of 3
mmarle
in reply to: mmarle

TY Hallex!

 

See you (MGO_MKD)

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