I'm working on a macro to be able to open a part from a drawing and have it automatically orient itself in the same way it is oriented within the drawing view that was selected. For example, say the user choses a view in a drawing that shows the referenced model from the front, I would like to be able to run a macro that would open the referenced model and orient it to the front view. I have gotten as far as using the GetViewXform method which returns the following:
The data is formatted as the following array of 13 doubles:
- [0-8] is a 3x3 of the view rotation
- [9-11] is a 1x3 of translation
- [12] is the scaling of the transformation
I would expect to be able to use the 3x3 of view rotation within the model to get it to the proper orientation but I just don't know how to do that. Can anyone help me out? (The code snippet below just used the frist drawing view.)
-Dave
Dim swApp As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim lretval As Long
Sub main()
Set swApp = _
Application.SldWorks
Dim swdoc As SldWorks.DrawingDoc
Set swdoc = swApp.ActiveDoc
Dim swview, swview2 As SldWorks.View
Set swview = swdoc.GetFirstView
Set swview = swview.GetNextView
Dim myorientation
myorientation = swview.GetViewXform
Dim smodelname As String
Dim omodel As SldWorks.ModelDoc2
smodelname = swview2.GetReferencedModelName
If Not swview2.IsModelLoaded Then
lretval = swview2.LoadModel
End If
Set omodel = swApp.ActivateDoc2(smodelname, False, lretval)
Dim swmodelview As Object
Set swmodelview = omodel.ActiveView
'???? what now
End Sub
SolidworksApi macros