-
Re: Part View Rotate Macro
Fatih Mehmet Ozcan Nov 29, 2017 3:23 PM (in response to Dave Paul)This macro goes normal to front plane then rotates view in Z axis with default increment. I couldn't find anyway to input rotate degree. If anyone knows how to do this please share
Dim swApp As Object
Sub main()
Set swApp = Application.SldWorks
Dim boolstatus As Long
Dim status As Long
Dim swmodel As SldWorks.ModelDoc2
Set swmodel = swApp.ActiveDoc
boolstatus = swmodel.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
swmodel.Extension.RunCommand swCommands_e.swCommands_NormalTo, “”
swmodel.ViewRotateplusz
End Sub
-
Re: Part View Rotate Macro
Dave Paul Nov 29, 2017 3:31 PM (in response to Fatih Mehmet Ozcan)Here is the way that I have rotated the view.
Sub main() Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc Set swModelView = swModel.ActiveView ' Roll the model view by the specified angle swModelView.RollBy (Degrees2Radians(-90)) End Sub
-
Re: Part View Rotate Macro
Jordan Martins May 15, 2018 6:24 AM (in response to Dave Paul)I tried using this but the Degree2Radians gives me a compile error because I haven't defined it
-
Re: Part View Rotate Macro
Jacob Corder May 16, 2018 9:33 AM (in response to Jordan Martins)you must create a function called Degrees2Radians
Function Degrees2Radians (byval DegVal as double) as double
Dim Pi As Double
Pi = 3.14159265359
Degrees2Radians = degval * (pi/180)
end function
this must be in your macro as a separate function
just paste it in
-
Re: Part View Rotate Macro
Jordan Martins May 15, 2018 11:18 AM (in response to Jacob Corder)Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
_________________________________________________________________________
Sub main()
Function Degrees2Radians(ByVal DegVal As Double) As Double
Dim Pi As Double
Pi = 3.14159265359
Degrees2Radians = DegVal * 180 / Pi
End Function
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swModelView = swModel.ActiveView
' Roll the model view by the specified angle
swModelView.RollBy (Degrees2Radians(-90))
End Sub
____________________________
*Compile error:
Expected End Sub
Is the function correct?
-
Re: Part View Rotate Macro
Jacob Corder May 15, 2018 3:41 PM (in response to Jordan Martins)remove the () around Rollby
swModelView.RollBy Degrees2Radians(-90)
-
Re: Part View Rotate Macro
Jordan Martins May 16, 2018 3:18 AM (in response to Jacob Corder)It still doesn't work.
Im going to post the question in the API sub forum. If theres any luck on a solution then I'll post the link for the correct answer into this discussion
-
Re: Part View Rotate Macro
Deepak Gupta May 16, 2018 3:59 AM (in response to Jordan Martins)You need to set them correctly i.e. a function can not be inside a sub procedure.
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
_________________________________________________________________________
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swModelView = swModel.ActiveView
' Roll the model view by the specified angle
swModelView.RollBy (Degrees2Radians(-90))
End Sub
Function Degrees2Radians(ByVal DegVal As Double) As Double
Dim Pi As Double
Pi = 3.14159265359
Degrees2Radians = DegVal * 180 / Pi
End Function
-
Re: Part View Rotate Macro
Jordan Martins May 16, 2018 4:07 AM (in response to Deepak Gupta)Deepak, did you test the code to see if it works correctly?
It still sin't rotating my drawing's view with this code
-
Re: Part View Rotate Macro
Deepak Gupta May 16, 2018 4:36 AM (in response to Jordan Martins)Jordan Martins wrote:
Deepak, did you test the code to see if it works correctly?
It still sin't rotating my drawing's view with this code
Sorry these codes are for model view and not drawing view. Check my updated cods in reply to your other post.
-
-
-
Re: Part View Rotate Macro
Jacob Corder May 16, 2018 9:32 AM (in response to Jordan Martins)see below
2018 SOLIDWORKS API Help - DrawingViewRotate Method (IDrawingDoc)
2018 SOLIDWORKS API Help - Rotate Drawing Views 45 Degrees Example (VBA)
the formula for radians is Degrees * (PI\180)
Function Degrees2Radians (byval DegVal as double) as double
Dim Pi As Double
Pi = 3.14159265359
Degrees2Radians = degval * (pi /180)
end function
i posted it wrong. sorry.. use this
-
-
-
-
-
-
-
-
Re: Part View Rotate Macro
Jacob Corder Nov 29, 2017 4:14 PM (in response to Dave Paul)Dim swApp As SldWorks.SldWorks
Sub main()
'Dim Pi As Double
Pi = 3.14159265359
Set swApp = Application.SldWorks
Dim Vectdir1() As Double
Dim VectDir2() As Double
ReDim Vectdir1(2)
ReDim VectDir2(2)
'To fill these out you need 2 3d points
Dim StartPoint1(2) As Double
Dim StartPoint2(2) As Double
Dim EndPoint2(2) As Double
Dim EndPoint1(2) As Double
EndPoint1(1) = -1
EndPoint2(1) = 1
'Get Some reference to fill these out
Dim I As Integer
For I = 0 To 2
Vectdir1(I) = EndPoint1(I) - StartPoint1(I)
VectDir2(I) = EndPoint2(I) - StartPoint2(I)
Next
'Now that we have the vector magnatude defined we first need to get the Dot Product
Dim DotProd As Double
DotProd = (Vectdir1(0) * VectDir2(0)) + (Vectdir1(1) * VectDir2(1)) + (Vectdir1(2) * VectDir2(2))
Dim AngleBetween As Double
If DotProd <> 0 Then
Dim VectMult As Double
VectMult = Length(Vectdir1(0), Vectdir1(1), Vectdir1(2)) * Length(VectDir2(0), VectDir2(1), VectDir2(2))
If VectMult = 0 Then
AngleBetween = 0
Else
'NEED FORMULA FOR VBA AND ARCCOS
AngleBetween = Acos(DotProd / VectMult)
End If
Else
If (Vectdir1(0) <> 0 Or Vectdir1(1) <> 0 Or Vectdir1(1) <> 0) And (VectDir2(0) <> 0 Or VectDir2(1) <> 0 Or VectDir2(2) <> 0) Then
AngleBetween = Pi / 2
Else
AngleBetween = 0
End If
End If
Debug.Print "angle between = " & ((AngleBetween * 180) / Pi)
End Sub
as you see above in bold. you will need to find a way to calculate ACos or Cos ^-1
-
Re: Part View Rotate Macro
Dave Paul Nov 29, 2017 4:50 PM (in response to Jacob Corder)Excellent. Thank you. I'll give that a try.
-
Re: Part View Rotate Macro
Jacob Corder Nov 29, 2017 4:52 PM (in response to Dave Paul)you can use this to get the angle between any 2 vectors
so to get the angle between the Model View Z vector use
z
Vect(0,0,1)
Y Vect(0,1,0)x Vector
vect(1,0,0)
then you can rotate in the correct order which is Z X Y i believe. cant remember.
-
-
-
Re: Part View Rotate Macro
Jordan Martins May 15, 2018 6:05 AM (in response to Dave Paul)I have a similar question to this and believe you guys may be able to help create a macro function for it.
When I put a drawing onto the page sometimes it isn't in the correct orientation. I already have a rotate 90 degree clockwise macro function, however it only seems to want to rotate the first drawing on the page and not the one that's selected (front or side views). It only rotates 90 degrees globally and not native to the drawing selected so sometimes doesn't rotate at all!
I don't have any knowledge in coding so none of the above pieces make any sense to me
If someone could help me produce a macro function for this, my workflow would definitely become much more effective!
-
Re: Part View Rotate Macro
Jordan Martins May 15, 2018 6:07 AM (in response to Jordan Martins)This is the function Im using currently
______________
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
boolstatus = Part.ActivateView("Drawing View1")
boolstatus = Part.Extension.SelectByRay(0.129143015056029, 0.103495081900875, -9499.9875, 0, 0, -1, 8.52786885245901E-04, 1, False, 0, 0)
boolstatus = Part.Extension.SelectByID2("Drawing View1", "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)
boolstatus = Part.DrawingViewRotate(1.5707963267949)
End Sub
-
Re: Part View Rotate Macro
Dave Paul May 16, 2018 2:08 PM (in response to Jordan Martins)Jordan,
I came up with a macro a while ago that rotates the part and creates a named view "DrawingXX". The XX is the next sequential number. The routine counts the user's LMB clicks and issues commands based on the click number. It ain't pretty, but it seems to work. You can zoom in and out while the macro is running, just use the mouse wheel.
The first click is the face of the part that will be used in the drawing view.
Second click is the rotation point of the part. The center of the part.
The third click is the vertex, center, point, etc. that will be the 0° mark of the part in the drawing.
The named view will be created after the part rotates.
Dave
-
SetDrawingViewAngle.swp.zip 21.8 KB
-
-
-