Create a view in several layout by user
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Dear All,
I hope all is well with you. I try to write a VBA code in AutoCAD to :
1- Create a requested number of layouts from user by user form and create them
2- Delete all current objects from each created layout
3- The user selects its first view and put it in layout 1, then selects the second view and put it in layout 2, .......
Please review the current code: When you run, it works up to step two above correctly and does well in step three but only for one layout, and it does not continue its job up to the end one. I will be highly appreciated it if someone helps me.
Codes:
Public explicity
Dim objAcadObject As AcadObject
Dim NumberofLayouts As Integer, NumberofRequired As Integer
Private Sub DoCreatelayout()
Dim currentLayout As AcadLayout
Dim LayoutName As String
'Dim NumberofLayouts As Integer, NumberofRequired As Integer
Dim Count As Integer
Dim entry As AcadEntity
ThisDrawing.ActiveSpace = acPaperSpace
NumberofRequired = UserForm1.TextBox1.Text
For Each currentLayout In ThisDrawing.Layouts
LayoutName = currentLayout.Name
If LayoutName <> "Model" Then currentLayout.Delete
Next
ThisDrawing.ActiveLayout = ThisDrawing.Layouts("Layout1")
For Each objAcadObject In ThisDrawing.PaperSpace
If TypeName(objAcadObject) = "IAcadPViewport" Then objAcadObject.Delete
Next
For Count = 2 To NumberofRequired
ThisDrawing.Layouts.Add ("Layout" & Count)
ThisDrawing.ActiveLayout = ThisDrawing.Layouts("Layout" & Count)
For Each objAcadObject In ThisDrawing.PaperSpace
If TypeName(objAcadObject) = "IAcadPViewport" Then objAcadObject.Delete
Next
Next
ThisDrawing.Regen acActiveViewport
End Sub
Private Sub CommandButton1_Click()
DoCreatelayout
UserForm1.Hide
For Count = 2 To NumberofRequired
ThisDrawing.ActiveLayout = ThisDrawing.Layouts("Layout" & Count)
ThisDrawing.SendCommand "mview" & vbCr & "NEW" & vbCr
Next
End Sub