Message 1 of 4
Why doesn't this work? Put me out of my misery!
Not applicable
11-25-2000
06:20 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have been struggling for a week, on and off, with both AutoLisp and now
VBA, to write a routine to rotate a layout (pspace objects including
viewports and views) through 90 degrees. I am a novice at both languages, so
excuse any crudities in the routine below.
The macro works right up to the last point, which is to restore the centre
of the view. I just cannot get it to work (I've tried using Direction and
Target properties). What am I doing wrong???
thanks!
Sub RotateLayout()
On Error GoTo Errorhandler
Dim ssetObj As AcadSelectionSet
Set ssetObj = ThisDrawing.SelectionSets.Add("SSET")
ssetObj.SelectOnScreen
Dim objCount As Integer
Dim I As Integer
objCount = ssetObj.Count
Dim pspaceObj As AcadEntity
Dim basept As Variant
Dim rotAngle As Double
Dim origin(0 To 2) As Double
origin(0) = 0#
origin(1) = 0#
origin(2) = 0#
rotAngle = -1.5708
basept = ThisDrawing.Utility.GetPoint(, "Enter the point which will be
at 0,0 after rotation: ")
For I = 0 To objCount - 1
Set pspaceObj = ssetObj.Item(I)
pspaceObj.Move basept, origin
pspaceObj.Rotate origin, rotAngle
Next
Dim vpObj As AcadPViewport
Dim currWidth, currHeight As Double
Dim vpTarget As Variant
Dim custScale, stdScale As Double
For I = 0 To objCount - 1
Set pspaceObj = ssetObj.Item(I)
If (pspaceObj.ObjectName = "AcDbViewport") Then
Set vpObj = ssetObj.Item(I)
'get current settings
currWidth = vpObj.Width
currHeight = vpObj.Height
vpTarget = vpObj.Target
custScale = vpObj.CustomScale
stdScale = vpObj.StandardScale
'swap width/height
vpObj.Width = currHeight
vpObj.Height = currWidth
vpObj.update
'go to mspace, turn UCS, set plan, return UCS
ThisDrawing.MSpace = True
ThisDrawing.ActivePViewport = vpObj
ThisDrawing.SendCommand "_ucs" & vbCr & "z" & vbCr & "90" & vbCr
ThisDrawing.SendCommand "_plan" & vbCr & "current" & vbCr
ThisDrawing.SendCommand "ucs" & vbCr & "prev" & vbCr
ThisDrawing.MSpace = False
'turn display off while returning previous settings then turn back on
vpObj.Display False
vpObj.StandardScale = stdScale
vpObj.CustomScale = custScale
vpObj.Target = vpTarget
vpObj.Display True
vpObj.Update
ThisDrawing.Regen acAllViewports
End If
Next
Errorhandler:
ssetObj.Delete
ZoomExtents
End Sub
-------------------------------------------------
Keith Pocock
mailto:[email protected]
VBA, to write a routine to rotate a layout (pspace objects including
viewports and views) through 90 degrees. I am a novice at both languages, so
excuse any crudities in the routine below.
The macro works right up to the last point, which is to restore the centre
of the view. I just cannot get it to work (I've tried using Direction and
Target properties). What am I doing wrong???
thanks!
Sub RotateLayout()
On Error GoTo Errorhandler
Dim ssetObj As AcadSelectionSet
Set ssetObj = ThisDrawing.SelectionSets.Add("SSET")
ssetObj.SelectOnScreen
Dim objCount As Integer
Dim I As Integer
objCount = ssetObj.Count
Dim pspaceObj As AcadEntity
Dim basept As Variant
Dim rotAngle As Double
Dim origin(0 To 2) As Double
origin(0) = 0#
origin(1) = 0#
origin(2) = 0#
rotAngle = -1.5708
basept = ThisDrawing.Utility.GetPoint(, "Enter the point which will be
at 0,0 after rotation: ")
For I = 0 To objCount - 1
Set pspaceObj = ssetObj.Item(I)
pspaceObj.Move basept, origin
pspaceObj.Rotate origin, rotAngle
Next
Dim vpObj As AcadPViewport
Dim currWidth, currHeight As Double
Dim vpTarget As Variant
Dim custScale, stdScale As Double
For I = 0 To objCount - 1
Set pspaceObj = ssetObj.Item(I)
If (pspaceObj.ObjectName = "AcDbViewport") Then
Set vpObj = ssetObj.Item(I)
'get current settings
currWidth = vpObj.Width
currHeight = vpObj.Height
vpTarget = vpObj.Target
custScale = vpObj.CustomScale
stdScale = vpObj.StandardScale
'swap width/height
vpObj.Width = currHeight
vpObj.Height = currWidth
vpObj.update
'go to mspace, turn UCS, set plan, return UCS
ThisDrawing.MSpace = True
ThisDrawing.ActivePViewport = vpObj
ThisDrawing.SendCommand "_ucs" & vbCr & "z" & vbCr & "90" & vbCr
ThisDrawing.SendCommand "_plan" & vbCr & "current" & vbCr
ThisDrawing.SendCommand "ucs" & vbCr & "prev" & vbCr
ThisDrawing.MSpace = False
'turn display off while returning previous settings then turn back on
vpObj.Display False
vpObj.StandardScale = stdScale
vpObj.CustomScale = custScale
vpObj.Target = vpTarget
vpObj.Display True
vpObj.Update
ThisDrawing.Regen acAllViewports
End If
Next
Errorhandler:
ssetObj.Delete
ZoomExtents
End Sub
-------------------------------------------------
Keith Pocock
mailto:[email protected]