Changing modelspace views with VBA

Changing modelspace views with VBA

Anonymous
Not applicable
1,521 Views
3 Replies
Message 1 of 4

Changing modelspace views with VBA

Anonymous
Not applicable
Hi,

I wish to provide a capability of swapping the view of the drawing
between "plan", "front elevation", "side elevation" and the standard
isometric views. Searching help files and the Object model I have not
been able to find an API for this. It seems an obvious item for there
to be an API.

I've been playing with "Sendcommand" as an alternative, but find it
unreliable in that sometime it works and other times it stacks the
commands and runs then when I exit my program.

Select Case Combobox.ListIndex
Case 0
ThisDrawing.SendCommand "-view" & vbCr & "_top" & vbCr
Case 1 '<--- "Front elevation"
ThisDrawing.SendCommand "-view" & vbCr & "_front" & vbCr
Case 2 '<--- "Side elevation"
ThisDrawing.SendCommand "-view" & vbCr & "_left" & vbCr
Case 3 '<--- "SW Isometric"
ThisDrawing.SendCommand "-view" & vbCr & "_swiso" & vbCr

Using vbcrlf or vbcr makes no difference.


Regards


Laurie Comerford
0 Likes
1,522 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
hi,

Could you do this with UCS's?

Sub Example_UserCoordinateSystems()
' This example finds the current UserCoordinateSystems collection and
' adds a new UCS to that collection.

Dim UCSColl As AcadUCSs
Set UCSColl = ThisDrawing.UserCoordinateSystems

' Create a UCS named "Top" in the current drawing
Dim ucsObj As AcadUCS
Dim origin(0 To 2) As Double
Dim xAxisPnt(0 To 2) As Double
Dim yAxisPnt(0 To 2) As Double

' Define the UCS
origin(0) = 0#: origin(1) = 0#: origin(2) = 0#
xAxisPnt(0) = 1#: xAxisPnt(1) = 0#: xAxisPnt(2) = 0#
yAxisPnt(0) = 0#: yAxisPnt(1) = 1#: yAxisPnt(2) = 0#

' Add the UCS to the UserCoordinatesSystems collection
Set ucsObj = UCSColl.Add(origin, xAxisPnt, yAxisPnt, "Top")

MsgBox "A new UCS called " & ucsObj.name & " has been added to the UserCoordinateSystems collection.", vbInformation, "UserCoordinateSystems Example"
End Sub

hope this helps
0 Likes
Message 3 of 4

Anonymous
Not applicable
I just did this for someone else... you'll have to finish the iso views but I did SEISO...

[code]
Enum Views
TOPVIEW
BOTTOMVIEW
FRONTVIEW
BACKVIEW
LEFTVIEW
RIGHTVIEW
SEISO
'...
End Enum

Function ViewVector(v As Views) As Double()
Dim temp(2) As Double

'not need to set valuse that are zero. just
'set the vector direction
Select Case v
Case Views.TOPVIEW
temp(2) = 1
Case Views.BOTTOMVIEW
temp(2) = -1
Case Views.FRONTVIEW
temp(1) = -1
Case Views.BACKVIEW
temp(1) = 1
Case Views.LEFTVIEW
temp(0) = -1
Case Views.RIGHTVIEW
temp(0) = 1
Case Views.SEISO
temp(0) = 1
temp(1) = -1
temp(2) = 1
'to get the rest set your view and type viewdir.
End Select

ViewVector = temp

End Function

Sub foo()
ThisDrawing.ActiveViewport.Direction = ViewVector(Views.SEISO)
ThisDrawing.ActiveViewport = ThisDrawing.ActiveViewport
End Sub
[/code]

"Laurie Comerford" wrote in message news:6028607@discussion.autodesk.com...
Hi,

I wish to provide a capability of swapping the view of the drawing
between "plan", "front elevation", "side elevation" and the standard
isometric views. Searching help files and the Object model I have not
been able to find an API for this. It seems an obvious item for there
to be an API.

I've been playing with "Sendcommand" as an alternative, but find it
unreliable in that sometime it works and other times it stacks the
commands and runs then when I exit my program.

Select Case Combobox.ListIndex
Case 0
ThisDrawing.SendCommand "-view" & vbCr & "_top" & vbCr
Case 1 '<--- "Front elevation"
ThisDrawing.SendCommand "-view" & vbCr & "_front" & vbCr
Case 2 '<--- "Side elevation"
ThisDrawing.SendCommand "-view" & vbCr & "_left" & vbCr
Case 3 '<--- "SW Isometric"
ThisDrawing.SendCommand "-view" & vbCr & "_swiso" & vbCr

Using vbcrlf or vbcr makes no difference.


Regards


Laurie Comerford
0 Likes
Message 4 of 4

Anonymous
Not applicable
Hi Paul and Cadger,

Thank you. Cadger for helping me understand what I was doing and Paul
for the code. I can see my knowledge of AutoCAD UCSs was defective.
They are not normally needed in Civil.

I've transformed Paul's code into my Case statement and all is well.


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Pass this the ComboBox index
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function SetViewDirection(iIndex As Integer)
Dim daViewDirection(2) As Double
Select Case iIndex
Case 0 '<--- "Plan" - OK from Email
daViewDirection(0) = 0
daViewDirection(1) = 0
daViewDirection(2) = 1
Case 1 '<--- "Bottom" - OK from Email
daViewDirection(0) = 0
daViewDirection(1) = 0
daViewDirection(2) = -1
Case 2 '<--- "Left Side elevation" - OK from Email
daViewDirection(0) = -1
daViewDirection(1) = 0
daViewDirection(2) = 0
Case 3 '<--- "Right elevation" - OK from Email
daViewDirection(0) = 1
daViewDirection(1) = 0
daViewDirection(2) = 0
Case 4 '<--- "Front" - OK from Email
daViewDirection(0) = 0
daViewDirection(1) = -1
daViewDirection(2) = 0
Case 5 '<--- "Back elevation" - OK from Email
daViewDirection(0) = 0
daViewDirection(1) = 1
daViewDirection(2) = 0
Case 6 '<--- "SW Isometric" - OK from AutoCAD
daViewDirection(0) = -1
daViewDirection(1) = 1
daViewDirection(2) = 1
Case 7 '<--- "SE Isometric" - OK from Email
daViewDirection(0) = 1
daViewDirection(1) = -1
daViewDirection(2) = 1
Case 8 '<--- "NE Isometric" - OK from AutoCAD
daViewDirection(0) = 1
daViewDirection(1) = 1
daViewDirection(2) = -1
Case 9 '<--- "NW Isometric" - OK from AutoCAD
daViewDirection(0) = -1
daViewDirection(1) = 1
daViewDirection(2) = -1
Case Else ' <--- Set to another view
daViewDirection(0) = -2.5
daViewDirection(1) = 1
daViewDirection(2) = 2

End Select
ThisDrawing.ActiveViewport.Direction = daViewDirection
ThisDrawing.ActiveViewport = ThisDrawing.ActiveViewport
ZoomExtents

End Function ' SetViewDirection


Regards


Laurie Comerford

Paul Richardson wrote:
> I just did this for someone else... you'll have to finish the iso views but I did SEISO...
>
> [code]
> Enum Views
> TOPVIEW
> BOTTOMVIEW
> FRONTVIEW
> BACKVIEW
> LEFTVIEW
> RIGHTVIEW
> SEISO
> '...
> End Enum
>
> Function ViewVector(v As Views) As Double()
> Dim temp(2) As Double
>
> 'not need to set valuse that are zero. just
> 'set the vector direction
> Select Case v
> Case Views.TOPVIEW
> temp(2) = 1
> Case Views.BOTTOMVIEW
> temp(2) = -1
> Case Views.FRONTVIEW
> temp(1) = -1
> Case Views.BACKVIEW
> temp(1) = 1
> Case Views.LEFTVIEW
> temp(0) = -1
> Case Views.RIGHTVIEW
> temp(0) = 1
> Case Views.SEISO
> temp(0) = 1
> temp(1) = -1
> temp(2) = 1
> 'to get the rest set your view and type viewdir.
> End Select
>
> ViewVector = temp
>
> End Function
>
> Sub foo()
> ThisDrawing.ActiveViewport.Direction = ViewVector(Views.SEISO)
> ThisDrawing.ActiveViewport = ThisDrawing.ActiveViewport
> End Sub
> [/code]
>
> "Laurie Comerford" wrote in message news:6028607@discussion.autodesk.com...
> Hi,
>
> I wish to provide a capability of swapping the view of the drawing
> between "plan", "front elevation", "side elevation" and the standard
> isometric views. Searching help files and the Object model I have not
> been able to find an API for this. It seems an obvious item for there
> to be an API.
>
> I've been playing with "Sendcommand" as an alternative, but find it
> unreliable in that sometime it works and other times it stacks the
> commands and runs then when I exit my program.
>
> Select Case Combobox.ListIndex
> Case 0
> ThisDrawing.SendCommand "-view" & vbCr & "_top" & vbCr
> Case 1 '<--- "Front elevation"
> ThisDrawing.SendCommand "-view" & vbCr & "_front" & vbCr
> Case 2 '<--- "Side elevation"
> ThisDrawing.SendCommand "-view" & vbCr & "_left" & vbCr
> Case 3 '<--- "SW Isometric"
> ThisDrawing.SendCommand "-view" & vbCr & "_swiso" & vbCr
>
> Using vbcrlf or vbcr makes no difference.
>
>
> Regards
>
>
> Laurie Comerford
0 Likes