brengine
Mechanical
- Apr 19, 2001
- 616
Can the Measure Routine Report Dual Dimensions? I get tired of switiching between the 2 (our parts, customer parts, and purchased parts are always different somewhere 8(
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Option Explicit
Const dPi = 3.141592654
Const MtoIN = 1 / 0.0254
Const MtoMM = 1000
Const M2toIN2 = 1550.003
Const M2toMM2 = 1000000
Const swSelEDGES = 1
Const swMbInformation = 2
Const swMbStop = 4
Const swMbOk = 2
Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim swSelMgr As SelectionMgr
Dim swEdge As Edge
Dim swCurve As Curve
Dim lngSelType As Long
Dim pt1 As Double
Dim pt2 As Double
Dim bVal1 As Boolean
Dim bVal2 As Boolean
Dim vSafeArray As Variant
Dim dLen As Double
Sub main()
Dim sMsg As String
Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
If swSelMgr.GetSelectedObjectCount <> 1 Then
swApp.SendMsgToUser2 "Please Select ONE Edge to Measure", swMbStop, swMbOk
GoTo CleanUp
End If
lngSelType = swSelMgr.GetSelectedObjectType2(1)
If lngSelType = swSelEDGES Then
Set swEdge = swSelMgr.GetSelectedObject3(1)
Set swCurve = swEdge.GetCurve
If swCurve.IsLine Then
Call swCurve.GetEndParams(pt1, pt2, bVal1, bVal2)
dLen = swCurve.GetLength2(pt1, pt2)
sMsg = "Selected Edge - Line" & vbCrLf & vbCrLf & _
"Length (in): " & Format(dLen * MtoIN, "##,##0.00000") & vbCrLf & _
"Length (mm): " & Format(dLen * MtoMM, "###,##0.000")
ElseIf swCurve.IsCircle Then
vSafeArray = swCurve.CircleParams
sMsg = "Selected Edge - Circle:" & vbCrLf & vbCrLf & _
"Center (in): (" & Format(vSafeArray(0) * MtoIN, "##,##0.0000") & _
", " & Format(vSafeArray(1) * MtoIN, "##,##0.0000") & _
", " & Format(vSafeArray(2) * MtoIN, "##,##0.0000") & ")" & vbCrLf & _
"Daimeter (in): " & Format(vSafeArray(6) * 2 * MtoIN, "##,##0.0000") & vbCrLf & _
"Circumference (in): " & Format(2 * dPi * vSafeArray(6) * MtoIN, "##,##0.0000") & vbCrLf & _
"Area (in^2): " & Format(dPi * vSafeArray(6) ^ 2 * M2toIN2, "##,##0.0000") & vbCrLf & vbCrLf & _
"Center (mm): (" & Format(vSafeArray(0) * MtoMM, "##,##0.000") & _
", " & Format(vSafeArray(1) * MtoMM, "##,##0.000") & _
", " & Format(vSafeArray(2) * MtoMM, "##,##0.000") & ")" & vbCrLf & _
"Daimeter (mm): " & Format(vSafeArray(6) * 2 * MtoMM, "##,##0.000") & vbCrLf & _
"Circumference (mm): " & Format(2 * dPi * vSafeArray(6) * MtoMM, "##,##0.000") & vbCrLf & _
"Area (mm^2): " & Format(dPi * vSafeArray(6) ^ 2 * M2toMM2, "##,##0.000")
Else
swApp.SendMsgToUser2 "Edge Must be a Line or a Circle", swMbStop, swMbOk
GoTo CleanUp
End If
Else
swApp.SendMsgToUser2 "I can only measure Edges", swMbStop, swMbOk
End If
swApp.SendMsgToUser2 sMsg, swMbInformation, swMbOk
CleanUp:
Set swEdge = Nothing
Set swCurve = Nothing
Set swSelMgr = Nothing
Set swModel = Nothing
Set swApp = Nothing
End Sub
Option Explicit
Const swSelFACES = 2
Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim swFace1 As face2
Dim swFace2 As face2
Dim swSurface1 As surface
Dim swSurface2 As surface
Dim swSelMgr As SelectionMgr
Sub main()
Dim vSelectionPt1 As Variant
Dim vSelectionPt2 As Variant
Dim vClosestPt1 As Variant
Dim vClosestPt2 As Variant
Dim dDistance1 As Double
Dim dDistance2 As Double
Dim lSelType1 As Long
Dim lSelType2 As Long
Dim dX As Double
Dim dY As Double
Dim dZ As Double
Dim sMsg As String
Set swApp = CreateObject("Sldworks.Application")
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
lSelType1 = swSelMgr.GetSelectedObjectType2(1)
lSelType2 = swSelMgr.GetSelectedObjectType2(2)
If lSelType1 <> swSelFACES Or lSelType2 <> swSelFACES Then
swApp.SendMsgToUser "Please Select 2 Faces"
GoTo CleanUp
End If
Set swFace1 = swSelMgr.GetSelectedObject3(1)
Set swFace2 = swSelMgr.GetSelectedObject3(2)
Set swSurface1 = swFace1.GetSurface
Set swSurface2 = swFace2.GetSurface
vSelectionPt1 = swSelMgr.GetSelectionPoint(1)
vSelectionPt2 = swSelMgr.GetSelectionPoint(2)
vClosestPt1 = swSurface1.GetClosestPointOn(vSelectionPt2(0), vSelectionPt2(1), vSelectionPt2(2))
vClosestPt2 = swSurface2.GetClosestPointOn(vSelectionPt1(0), vSelectionPt1(1), vSelectionPt1(2))
dX = vSelectionPt1(0) - vClosestPt2(0)
dY = vSelectionPt1(1) - vClosestPt2(1)
dZ = vSelectionPt1(2) - vClosestPt2(2)
dDistance1 = Sqr(dX ^ 2 + dY ^ 2 + dZ ^ 2)
dX = vSelectionPt2(0) - vClosestPt1(0)
dY = vSelectionPt2(1) - vClosestPt1(1)
dZ = vSelectionPt2(2) - vClosestPt1(2)
dDistance2 = Sqr(dX ^ 2 + dY ^ 2 + dZ ^ 2)
If Abs(dDistance1 - dDistance2) <= 0.0001 Then 'Close enough to parallel
sMsg = "Distance = " & Format((dDistance1 * 39.37008), "#,##0.00000") & " inches" & vbCrLf & _
Space(18) & Format((dDistance1 * 1000), "##,##0.0000") & " mm"
Else
sMsg = "Selected Faces are NOT Parallel"
End If
swApp.SendMsgToUser sMsg
CleanUp:
Set swFace1 = Nothing
Set swFace2 = Nothing
Set swSurface1 = Nothing
Set swSurface2 = Nothing
Set swSelMgr = Nothing
Set swModel = Nothing
Set swApp = Nothing
End Sub