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