Message 1 of 4
Manipulating Paper Space Viewports with VBA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm supporting a condo project where we have to create 4 blown up plan drawings of each unit, including a construction plan, rcp, finish plan, and ff&e plan. There are 110 unique units and we are putting two drawings on each sheet so that's a total of 220 sheets. I'm trying to create a VBA script to automate this process.
The steps I want the script to take include
1) Open an existing template file (with title block, and two paper space viewports)
2) For each viewport:
-Zoom extents to center the view
-Set the viewport scale to 1/4"
-VP Freeze specific layers depending on the drawing
3) Set the sheet number and sheet name (change attributes of a block)
I'm having the hardest time manipulating the viewports. Right now I've able to get it to work partially with a series of SendCommand call and a call to SendKeys to switch between viewports. See my code bellow.
'switches from model space to the "FULL SIZE" layout tab
ThisDrawing.SendCommand ("layout set ")
ThisDrawing.SendCommand ("FULL SIZE" & vbCr)
'Right viewport opens by default
ThisDrawing.SendCommand ("mspace ")
'zooms extents in the right viewport and sets scale
ThisDrawing.SendCommand ("Z E ")
ThisDrawing.SendCommand ("Z S .02083333333xp ")
'switches to the left viewport
SendKeys "^r", True
ThisDrawing.SendCommand ("Z E ") 'clears send keys
'zooms extents is left viewport
ThisDrawing.SendCommand ("Z E ")
ThisDrawing.SendCommand ("Z S .02083333333xp" & vbCr)
This is hardly a clean way of doing this, and I'd much rather use the object model directly rather then using SendCommand. Plus the script above gets stuck at the SendKeys command for some reason.
I'd really like to be able to select the left or right viewport directly rather then by luck that the right one become active when I send the "mspace" command. I've tried to select the view port by entity handle using the code bellow. But it gives the the error "Invalid argument filter list in Select". I"m not sure what I did wrong.
'Creates Selection Sets
Dim grpCode(0) As Integer
Dim dataVal(0) As Variant
Mode = acSelectionSetAll
Set LeftVPSelection = ThisDrawing.SelectionSets.Add("LeftVP")
grpCode(0) = 5 'type five is entity handle
dataVal(0) = "266bf" 'This is the entity handle for the left VP
LeftVPSelection.Select Mode, , , grpCode, dataVal
LeftVPSelection.Delete
If I can get that to work I'm assuming that next I would need to extract a single AcadPViewport object out of the selection set (should be item 0 because there should only be one object in the set). Then I would set this to the "ActivePViewPort" so I can mess with the scale. Message was edited by: aireq
The steps I want the script to take include
1) Open an existing template file (with title block, and two paper space viewports)
2) For each viewport:
-Zoom extents to center the view
-Set the viewport scale to 1/4"
-VP Freeze specific layers depending on the drawing
3) Set the sheet number and sheet name (change attributes of a block)
I'm having the hardest time manipulating the viewports. Right now I've able to get it to work partially with a series of SendCommand call and a call to SendKeys to switch between viewports. See my code bellow.
'switches from model space to the "FULL SIZE" layout tab
ThisDrawing.SendCommand ("layout set ")
ThisDrawing.SendCommand ("FULL SIZE" & vbCr)
'Right viewport opens by default
ThisDrawing.SendCommand ("mspace ")
'zooms extents in the right viewport and sets scale
ThisDrawing.SendCommand ("Z E ")
ThisDrawing.SendCommand ("Z S .02083333333xp ")
'switches to the left viewport
SendKeys "^r", True
ThisDrawing.SendCommand ("Z E ") 'clears send keys
'zooms extents is left viewport
ThisDrawing.SendCommand ("Z E ")
ThisDrawing.SendCommand ("Z S .02083333333xp" & vbCr)
This is hardly a clean way of doing this, and I'd much rather use the object model directly rather then using SendCommand. Plus the script above gets stuck at the SendKeys command for some reason.
I'd really like to be able to select the left or right viewport directly rather then by luck that the right one become active when I send the "mspace" command. I've tried to select the view port by entity handle using the code bellow. But it gives the the error "Invalid argument filter list in Select". I"m not sure what I did wrong.
'Creates Selection Sets
Dim grpCode(0) As Integer
Dim dataVal(0) As Variant
Mode = acSelectionSetAll
Set LeftVPSelection = ThisDrawing.SelectionSets.Add("LeftVP")
grpCode(0) = 5 'type five is entity handle
dataVal(0) = "266bf" 'This is the entity handle for the left VP
LeftVPSelection.Select Mode, , , grpCode, dataVal
LeftVPSelection.Delete
If I can get that to work I'm assuming that next I would need to extract a single AcadPViewport object out of the selection set (should be item 0 because there should only be one object in the set). Then I would set this to the "ActivePViewPort" so I can mess with the scale. Message was edited by: aireq