.NET

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

Create a viewport in a particular layout

176 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 (147 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 (122 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)

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community