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.
'==========================================================
'The purpose of this program is to add a distance mate
'based on the user preselecting to entities.
'==========================================================
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModelDoc As SldWorks.ModelDoc2
Dim swAssyDoc As SldWorks.AssemblyDoc
Dim swSelMgr As SldWorks.SelectionMgr
Dim longstatus As Long, longwarnings As Long
Dim DistanceValue As Double
Sub main()
Set swApp = Application.SldWorks
Set swModelDoc = swApp.ActiveDoc
Set swSelMgr = swModelDoc.SelectionManager
'Make sure the active document is an assembly.
If swModelDoc.GetType = swDocASSEMBLY Then
Set swAssyDoc = swModelDoc
'Make sure there are only two entities in selection.
If swSelMgr.GetSelectedObjectCount = 2 Then
Load UserFormDistance
If swUnitsLinear = swINCHES Then
UserFormDistance.Label5.Caption = "in"
Else
UserFormDistance.Label5.Caption = "mm"
End If
UserFormDistance.Show
If Not UserFormDistance.CommandButtonOK.Tag = "OK" Then End
DistanceValue = UserFormDistance.TextBoxDistance.value / 1000 'Convert to meters
Unload UserFormDistance
swAssyDoc.AddMate2 swMateDISTANCE, swMateAlignCLOSEST, True, DistanceValue, DistanceValue, DistanceValue, 1, 1, 0, 0, 0, longstatus
Else
MsgBox "Wrong number of selected items.", vbOKOnly + vbInformation, "Selection Error"
End If
Else
MsgBox "This program only works on assembly documents.", vbOKOnly + vbInformation, "Document Error"
End If
End Sub
'==========================================================
'The purpose of this program is to add a distance mate
'based on the user preselecting to entities.
'==========================================================
Option Explicit
Dim NormalVectors(2, 2) As Double
Const NormalVectorPrecision = 9 'As Integer
Dim SelectedPointData(2, 2) As Double
' ******************************************************************************
' FaceNormals.swp by ehasz
' ******************************************************************************
Function FaceNormals(iCount As Integer)
Dim swApp As SldWorks.SldWorks
Dim swMath As MathUtility
Dim swDoc As ModelDoc2
Dim swSelMgr As SelectionMgr
Dim swComponent As Component2
Dim swFace As face2
Dim swSurface As surface
Dim swCompTrans As MathTransform
Dim swCompInvTrans As MathTransform
Dim swFacePoint As MathPoint
Dim swFaceNormal As MathVector
Dim params As Variant
Dim PointData(2) As Double
Dim ArrayData(15) As Double
Dim i As Variant
Dim IsFaceInSurface As Boolean
Set swApp = CreateObject("SldWorks.Application")
Set swMath = swApp.GetMathUtility
Set swDoc = swApp.ActiveDoc
Set swSelMgr = swDoc.SelectionManager
Set swFace = swSelMgr.GetSelectedObject3(iCount)
Set swSurface = swFace.GetSurface
Set swComponent = swSelMgr.GetSelectedObjectsComponent(iCount)
If Not swComponent Is Nothing Then
Set swCompTrans = swComponent.Transform
Set swCompInvTrans = swCompTrans.Inverse
Else
For i = 0 To 15
ArrayData(i) = 0#
Next i
ArrayData(0) = 1#: ArrayData(4) = 1#: ArrayData(8) = 1#: ArrayData(12) = 1#
Set swCompTrans = swMath.CreateTransform((ArrayData))
Set swCompInvTrans = swCompTrans.Inverse
End If
params = swSelMgr.GetSelectionPoint(iCount)
Set swFacePoint = swMath.CreatePoint(params)
Set swFacePoint = swFacePoint.MultiplyTransform(swCompInvTrans)
params = swFacePoint.ArrayData
params = swSurface.EvaluateAtPoint(params(0), params(1), params(2))
PointData(0) = params(0): PointData(1) = params(1): PointData(2) = params(2)
Set swFaceNormal = swMath.CreateVector((PointData))
If swFace.FaceInSurfaceSense <> False Then
Set swFaceNormal = swFaceNormal.Scale(-1)
IsFaceInSurface = True 'duh
Else 'duh
IsFaceInSurface = False 'duh
End If
Set swFacePoint = swFacePoint.MultiplyTransform(swCompTrans)
Set swFaceNormal = swFaceNormal.MultiplyTransform(swCompTrans)
params = swFaceNormal.ArrayData
NormalVectors(iCount, 0) = FormatNumber(params(0), NormalVectorPrecision)
NormalVectors(iCount, 1) = FormatNumber(params(1), NormalVectorPrecision)
NormalVectors(iCount, 2) = FormatNumber(params(2), NormalVectorPrecision)
Debug.Print NormalVectors(iCount, 0)
Debug.Print NormalVectors(iCount, 1)
Debug.Print NormalVectors(iCount, 2)
Debug.Print ""
' swDoc.Insert3DSketch2 (True)
params = swFacePoint.ArrayData
SelectedPointData(iCount, 0) = FormatNumber(params(0), NormalVectorPrecision)
SelectedPointData(iCount, 1) = FormatNumber(params(1), NormalVectorPrecision)
SelectedPointData(iCount, 2) = FormatNumber(params(2), NormalVectorPrecision)
Debug.Print SelectedPointData(iCount, 0)
Debug.Print SelectedPointData(iCount, 1)
Debug.Print SelectedPointData(iCount, 2)
Debug.Print "*********"
' PointData(0) = params(0): PointData(1) = params(1): PointData(2) = params(2)
' Set swFaceNormal = swFaceNormal.Scale(0.1)
' params = swFaceNormal.ArrayData
' params(0) = params(0) + PointData(0)
' params(1) = params(1) + PointData(1)
' params(2) = params(2) + PointData(2)
' swDoc.CreateLine2 PointData(0), PointData(1), PointData(2), params(0), params(1), params(2)
' swDoc.Insert3DSketch2 (True)
End Function
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModelDoc As SldWorks.ModelDoc2
Dim swAssyDoc As SldWorks.AssemblyDoc
Dim swSelMgr As SldWorks.SelectionMgr
Dim longstatus As Long, longwarnings As Long
Dim boolstatus As Boolean
Dim FlipMate As Boolean
Dim DistanceValue As Double
Dim MateDistanceValue As Double
Dim swFace1 As SldWorks.face2
Dim swFace2 As SldWorks.face2
Dim vPoint1 As Variant
Dim vPoint2 As Variant
Dim vClosestPt1 As Variant
Dim vClosestPt2 As Variant
Dim swSelObj1 As Object
Dim swSelObj2 As Object
Set swApp = Application.SldWorks
Set swModelDoc = swApp.ActiveDoc
Set swSelMgr = swModelDoc.SelectionManager
'Make sure the active document is an assembly.
If swModelDoc.GetType = swDocASSEMBLY Then
Set swAssyDoc = swModelDoc
'Make sure there are only two entities in selection.
If swSelMgr.GetSelectedObjectCount = 2 Then
If swSelMgr.GetSelectedObjectType2(1) = swSelFACES Or swSelMgr.GetSelectedObjectType2(1) = swSelDATUMPLANES Then
If swSelMgr.GetSelectedObjectType2(2) = swSelFACES Or swSelMgr.GetSelectedObjectType2(2) = swSelDATUMPLANES Then
Set swFace1 = swSelMgr.GetSelectedObject5(1)
Set swFace2 = swSelMgr.GetSelectedObject5(2)
DistanceValue = swModelDoc.ClosestDistance(swFace1, swFace2, vPoint1, vPoint2)
FaceNormals (1)
FaceNormals (2)
boolstatus = True
If NormalVectors(1, 0) = 0 And NormalVectors(1, 0) = NormalVectors(2, 0) And _
NormalVectors(1, 1) = 0 And NormalVectors(1, 1) = NormalVectors(2, 1) And _
Abs(NormalVectors(1, 2)) = 1 And Abs(NormalVectors(1, 2)) = Abs(NormalVectors(2, 2)) _
Then
'Z's are same
MateDistanceValue = Abs(FormatNumber((vPoint2(2) - vPoint1(2)), NormalVectorPrecision))
If NormalVectors(1, 2) = 1 And _
NormalVectors(2, 2) = 1 And _
SelectedPointData(2, 2) > SelectedPointData(1, 2) And _
SelectedPointData(1, 2) >= 0 And _
SelectedPointData(2, 2) >= 0 _
Then
FlipMate = True
ElseIf NormalVectors(1, 2) = 1 And _
NormalVectors(2, 2) = 1 And _
SelectedPointData(2, 2) < SelectedPointData(1, 2) And _
SelectedPointData(1, 2) >= 0 And _
SelectedPointData(2, 2) >= 0 _
Then
FlipMate = True
ElseIf NormalVectors(1, 2) = 1 And _
NormalVectors(2, 2) = 1 And _
SelectedPointData(2, 2) < SelectedPointData(1, 2) And _
SelectedPointData(1, 2) >= 0 And _
SelectedPointData(2, 2) < 0 _
Then
FlipMate = True
ElseIf NormalVectors(1, 2) = 1 And _
NormalVectors(2, 2) = 1 And _
SelectedPointData(2, 2) > SelectedPointData(1, 2) And _
SelectedPointData(1, 2) < 0 And _
SelectedPointData(2, 2) >= 0 _
Then
FlipMate = True
ElseIf NormalVectors(1, 2) = 1 And _
NormalVectors(2, 2) = 1 And _
SelectedPointData(2, 2) > SelectedPointData(1, 2) And _
SelectedPointData(1, 2) < 0 And _
SelectedPointData(2, 2) < 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 2) = 1 And _
NormalVectors(2, 2) = 1 And _
SelectedPointData(2, 2) < SelectedPointData(1, 2) And _
SelectedPointData(1, 2) < 0 And _
SelectedPointData(2, 2) < 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 2) = -1 And _
NormalVectors(2, 2) = -1 And _
SelectedPointData(2, 2) > SelectedPointData(1, 2) And _
SelectedPointData(1, 2) >= 0 And _
SelectedPointData(2, 2) >= 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 2) = -1 And _
NormalVectors(2, 2) = -1 And _
SelectedPointData(2, 2) < SelectedPointData(1, 2) And _
SelectedPointData(1, 2) >= 0 And _
SelectedPointData(2, 2) >= 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 2) = -1 And _
NormalVectors(2, 2) = -1 And _
SelectedPointData(2, 2) < SelectedPointData(1, 2) And _
SelectedPointData(1, 2) >= 0 And _
SelectedPointData(2, 2) < 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 2) = -1 And _
NormalVectors(2, 2) = -1 And _
SelectedPointData(2, 2) > SelectedPointData(1, 2) And _
SelectedPointData(1, 2) < 0 And _
SelectedPointData(2, 2) >= 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 2) = -1 And _
NormalVectors(2, 2) = -1 And _
SelectedPointData(2, 2) > SelectedPointData(1, 2) And _
SelectedPointData(1, 2) < 0 And _
SelectedPointData(2, 2) < 0 _
Then
FlipMate = True
ElseIf NormalVectors(1, 2) = -1 And _
NormalVectors(2, 2) = -1 And _
SelectedPointData(2, 2) < SelectedPointData(1, 2) And _
SelectedPointData(1, 2) < 0 And _
SelectedPointData(2, 2) < 0 _
Then
FlipMate = True
ElseIf NormalVectors(1, 2) = 1 And _
NormalVectors(2, 2) = -1 And _
SelectedPointData(2, 2) > SelectedPointData(1, 2) And _
SelectedPointData(1, 2) >= 0 And _
SelectedPointData(2, 2) >= 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 2) = 1 And _
NormalVectors(2, 2) = -1 And _
SelectedPointData(2, 2) < SelectedPointData(1, 2) And _
SelectedPointData(1, 2) >= 0 And _
SelectedPointData(2, 2) >= 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 2) = 1 And _
NormalVectors(2, 2) = -1 And _
SelectedPointData(2, 2) < SelectedPointData(1, 2) And _
SelectedPointData(1, 2) >= 0 And _
SelectedPointData(2, 2) < 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 2) = 1 And _
NormalVectors(2, 2) = -1 And _
SelectedPointData(2, 2) > SelectedPointData(1, 2) And _
SelectedPointData(1, 2) < 0 And _
SelectedPointData(2, 2) >= 0 _
Then
FlipMate = True
ElseIf NormalVectors(1, 2) = 1 And _
NormalVectors(2, 2) = -1 And _
SelectedPointData(2, 2) > SelectedPointData(1, 2) And _
SelectedPointData(1, 2) < 0 And _
SelectedPointData(2, 2) < 0 _
Then
FlipMate = True
ElseIf NormalVectors(1, 2) = 1 And _
NormalVectors(2, 2) = -1 And _
SelectedPointData(2, 2) < SelectedPointData(1, 2) And _
SelectedPointData(1, 2) < 0 And _
SelectedPointData(2, 2) < 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 2) = -1 And _
NormalVectors(2, 2) = 1 And _
SelectedPointData(2, 2) > SelectedPointData(1, 2) And _
SelectedPointData(1, 2) >= 0 And _
SelectedPointData(2, 2) >= 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 2) = -1 And _
NormalVectors(2, 2) = 1 And _
SelectedPointData(2, 2) < SelectedPointData(1, 2) And _
SelectedPointData(1, 2) >= 0 And _
SelectedPointData(2, 2) >= 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 2) = -1 And _
NormalVectors(2, 2) = 1 And _
SelectedPointData(2, 2) < SelectedPointData(1, 2) And _
SelectedPointData(1, 2) >= 0 And _
SelectedPointData(2, 2) < 0 _
Then
FlipMate = True
ElseIf NormalVectors(1, 2) = -1 And _
NormalVectors(2, 2) = 1 And _
SelectedPointData(2, 2) > SelectedPointData(1, 2) And _
SelectedPointData(1, 2) < 0 And _
SelectedPointData(2, 2) >= 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 2) = -1 And _
NormalVectors(2, 2) = 1 And _
SelectedPointData(2, 2) > SelectedPointData(1, 2) And _
SelectedPointData(1, 2) < 0 And _
SelectedPointData(2, 2) < 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 2) = -1 And _
NormalVectors(2, 2) = 1 And _
SelectedPointData(2, 2) < SelectedPointData(1, 2) And _
SelectedPointData(1, 2) < 0 And _
SelectedPointData(2, 2) < 0 _
Then
FlipMate = True
End If
ElseIf NormalVectors(1, 1) = 0 And NormalVectors(1, 1) = NormalVectors(2, 1) And _
NormalVectors(1, 2) = 0 And NormalVectors(1, 2) = NormalVectors(2, 2) And _
Abs(NormalVectors(1, 0)) = 1 And Abs(NormalVectors(1, 0)) = Abs(NormalVectors(2, 0)) _
Then
'X's are same
MateDistanceValue = Abs(FormatNumber((vPoint2(0) - vPoint1(0)), NormalVectorPrecision))
If NormalVectors(1, 0) = 1 And _
NormalVectors(2, 0) = 1 And _
SelectedPointData(2, 0) > SelectedPointData(1, 0) And _
SelectedPointData(1, 0) >= 0 And _
SelectedPointData(2, 0) >= 0 _
Then
FlipMate = True
ElseIf NormalVectors(1, 0) = 1 And _
NormalVectors(2, 0) = 1 And _
SelectedPointData(2, 0) < SelectedPointData(1, 0) And _
SelectedPointData(1, 0) >= 0 And _
SelectedPointData(2, 0) >= 0 _
Then
FlipMate = True
ElseIf NormalVectors(1, 0) = 1 And _
NormalVectors(2, 0) = 1 And _
SelectedPointData(2, 0) < SelectedPointData(1, 0) And _
SelectedPointData(1, 0) >= 0 And _
SelectedPointData(2, 0) < 0 _
Then
FlipMate = True
ElseIf NormalVectors(1, 0) = 1 And _
NormalVectors(2, 0) = 1 And _
SelectedPointData(2, 0) > SelectedPointData(1, 0) And _
SelectedPointData(1, 0) < 0 And _
SelectedPointData(2, 0) >= 0 _
Then
FlipMate = True
ElseIf NormalVectors(1, 0) = 1 And _
NormalVectors(2, 0) = 1 And _
SelectedPointData(2, 0) > SelectedPointData(1, 0) And _
SelectedPointData(1, 0) < 0 And _
SelectedPointData(2, 0) < 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 0) = 1 And _
NormalVectors(2, 0) = 1 And _
SelectedPointData(2, 0) < SelectedPointData(1, 0) And _
SelectedPointData(1, 0) < 0 And _
SelectedPointData(2, 0) < 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 0) = -1 And _
NormalVectors(2, 0) = -1 And _
NormalVectors(1, 0) = NormalVectors(2, 0) And _
SelectedPointData(2, 0) > SelectedPointData(1, 0) And _
SelectedPointData(1, 0) >= 0 And _
SelectedPointData(2, 0) >= 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 0) = -1 And _
NormalVectors(2, 0) = -1 And _
SelectedPointData(2, 0) < SelectedPointData(1, 0) And _
SelectedPointData(1, 0) >= 0 And _
SelectedPointData(2, 0) >= 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 0) = -1 And _
NormalVectors(2, 0) = -1 And _
SelectedPointData(2, 0) < SelectedPointData(1, 0) And _
SelectedPointData(1, 0) >= 0 And _
SelectedPointData(2, 0) < 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 0) = -1 And _
NormalVectors(2, 0) = -1 And _
SelectedPointData(2, 0) > SelectedPointData(1, 0) And _
SelectedPointData(1, 0) < 0 And _
SelectedPointData(2, 0) >= 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 0) = -1 And _
NormalVectors(2, 0) = -1 And _
SelectedPointData(2, 0) > SelectedPointData(1, 0) And _
SelectedPointData(1, 0) < 0 And _
SelectedPointData(2, 0) < 0 _
Then
FlipMate = True
ElseIf NormalVectors(1, 0) = -1 And _
NormalVectors(2, 0) = -1 And _
SelectedPointData(2, 0) < SelectedPointData(1, 0) And _
SelectedPointData(1, 0) < 0 And _
SelectedPointData(2, 0) < 0 _
Then
FlipMate = True
ElseIf NormalVectors(1, 0) = 1 And _
NormalVectors(2, 0) = -1 And _
SelectedPointData(2, 0) > SelectedPointData(1, 0) And _
SelectedPointData(1, 0) >= 0 And _
SelectedPointData(2, 0) >= 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 0) = 1 And _
NormalVectors(2, 0) = -1 And _
SelectedPointData(2, 0) < SelectedPointData(1, 0) And _
SelectedPointData(1, 0) >= 0 And _
SelectedPointData(2, 0) >= 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 0) = 1 And _
NormalVectors(2, 0) = -1 And _
SelectedPointData(2, 0) < SelectedPointData(1, 0) And _
SelectedPointData(1, 0) >= 0 And _
SelectedPointData(2, 0) < 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 0) = 1 And _
NormalVectors(2, 0) = -1 And _
SelectedPointData(2, 0) > SelectedPointData(1, 0) And _
SelectedPointData(1, 0) < 0 And _
SelectedPointData(2, 0) >= 0 _
Then
FlipMate = True
ElseIf NormalVectors(1, 0) = 1 And _
NormalVectors(2, 0) = -1 And _
SelectedPointData(2, 0) > SelectedPointData(1, 0) And _
SelectedPointData(1, 0) < 0 And _
SelectedPointData(2, 0) < 0 _
Then
FlipMate = True
ElseIf NormalVectors(1, 0) = 1 And _
NormalVectors(2, 0) = -1 And _
SelectedPointData(2, 0) < SelectedPointData(1, 0) And _
SelectedPointData(1, 0) < 0 And _
SelectedPointData(2, 0) < 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 0) = -1 And _
NormalVectors(2, 0) = 1 And _
SelectedPointData(2, 0) > SelectedPointData(1, 0) And _
SelectedPointData(1, 0) >= 0 And _
SelectedPointData(2, 0) >= 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 0) = -1 And _
NormalVectors(2, 0) = 1 And _
SelectedPointData(2, 0) < SelectedPointData(1, 0) And _
SelectedPointData(1, 0) >= 0 And _
SelectedPointData(2, 0) >= 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 0) = -1 And _
NormalVectors(2, 0) = 1 And _
SelectedPointData(2, 0) < SelectedPointData(1, 0) And _
SelectedPointData(1, 0) >= 0 And _
SelectedPointData(2, 0) < 0 _
Then
FlipMate = True
ElseIf NormalVectors(1, 0) = -1 And _
NormalVectors(2, 0) = 1 And _
SelectedPointData(2, 0) > SelectedPointData(1, 0) And _
SelectedPointData(1, 0) < 0 And _
SelectedPointData(2, 0) >= 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 0) = -1 And _
NormalVectors(2, 0) = 1 And _
SelectedPointData(2, 0) > SelectedPointData(1, 0) And _
SelectedPointData(1, 0) < 0 And _
SelectedPointData(2, 0) < 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 0) = -1 And _
NormalVectors(2, 0) = 1 And _
SelectedPointData(2, 0) < SelectedPointData(1, 0) And _
SelectedPointData(1, 0) < 0 And _
SelectedPointData(2, 0) < 0 _
Then
FlipMate = True
End If
ElseIf NormalVectors(1, 2) = 0 And NormalVectors(1, 2) = NormalVectors(2, 2) And _
NormalVectors(1, 0) = 0 And NormalVectors(1, 0) = NormalVectors(2, 0) And _
Abs(NormalVectors(1, 1)) = 1 And Abs(NormalVectors(1, 1)) = Abs(NormalVectors(2, 1)) _
Then
'Y's are same
MateDistanceValue = Abs(FormatNumber((vPoint2(1) - vPoint1(1)), NormalVectorPrecision))
If NormalVectors(1, 1) = 1 And _
NormalVectors(2, 1) = 1 And _
SelectedPointData(2, 1) > SelectedPointData(1, 1) And _
SelectedPointData(1, 1) >= 0 And _
SelectedPointData(2, 1) >= 0 _
Then
FlipMate = True
ElseIf NormalVectors(1, 1) = 1 And _
NormalVectors(2, 1) = 1 And _
SelectedPointData(2, 1) < SelectedPointData(1, 1) And _
SelectedPointData(1, 1) >= 0 And _
SelectedPointData(2, 1) >= 0 _
Then
FlipMate = True
ElseIf NormalVectors(1, 1) = 1 And _
NormalVectors(2, 1) = 1 And _
SelectedPointData(2, 1) < SelectedPointData(1, 1) And _
SelectedPointData(1, 1) >= 0 And _
SelectedPointData(2, 1) < 0 _
Then
FlipMate = True
ElseIf NormalVectors(1, 1) = 1 And _
NormalVectors(2, 1) = 1 And _
SelectedPointData(2, 1) > SelectedPointData(1, 1) And _
SelectedPointData(1, 1) < 0 And _
SelectedPointData(2, 1) >= 0 _
Then
FlipMate = True
ElseIf NormalVectors(1, 1) = 1 And _
NormalVectors(2, 1) = 1 And _
SelectedPointData(2, 1) > SelectedPointData(1, 1) And _
SelectedPointData(1, 1) < 0 And _
SelectedPointData(2, 1) < 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 1) = 1 And _
NormalVectors(2, 1) = 1 And _
SelectedPointData(2, 1) < SelectedPointData(1, 1) And _
SelectedPointData(1, 1) < 0 And _
SelectedPointData(2, 1) < 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 1) = -1 And _
NormalVectors(2, 1) = -1 And _
SelectedPointData(2, 1) > SelectedPointData(1, 1) And _
SelectedPointData(1, 1) >= 0 And _
SelectedPointData(2, 1) >= 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 1) = -1 And _
NormalVectors(2, 1) = -1 And _
SelectedPointData(2, 1) < SelectedPointData(1, 1) And _
SelectedPointData(1, 1) >= 0 And _
SelectedPointData(2, 1) >= 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 1) = -1 And _
NormalVectors(2, 1) = -1 And _
SelectedPointData(2, 1) < SelectedPointData(1, 1) And _
SelectedPointData(1, 1) >= 0 And _
SelectedPointData(2, 1) < 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 1) = -1 And _
NormalVectors(2, 1) = -1 And _
SelectedPointData(2, 1) > SelectedPointData(1, 1) And _
SelectedPointData(1, 1) < 0 And _
SelectedPointData(2, 1) >= 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 1) = -1 And _
NormalVectors(2, 1) = -1 And _
SelectedPointData(2, 1) > SelectedPointData(1, 1) And _
SelectedPointData(1, 1) < 0 And _
SelectedPointData(2, 1) < 0 _
Then
FlipMate = True
ElseIf NormalVectors(1, 1) = -1 And _
NormalVectors(2, 1) = -1 And _
SelectedPointData(2, 1) < SelectedPointData(1, 1) And _
SelectedPointData(1, 1) < 0 And _
SelectedPointData(2, 1) < 0 _
Then
FlipMate = True
ElseIf NormalVectors(1, 1) = 1 And _
NormalVectors(2, 1) = -1 And _
SelectedPointData(2, 1) > SelectedPointData(1, 1) And _
SelectedPointData(1, 1) >= 0 And _
SelectedPointData(2, 1) >= 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 1) = 1 And _
NormalVectors(2, 1) = -1 And _
SelectedPointData(2, 1) < SelectedPointData(1, 1) And _
SelectedPointData(1, 1) >= 0 And _
SelectedPointData(2, 1) >= 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 1) = 1 And _
NormalVectors(2, 1) = -1 And _
SelectedPointData(2, 1) < SelectedPointData(1, 1) And _
SelectedPointData(1, 1) >= 0 And _
SelectedPointData(2, 1) < 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 1) = 1 And _
NormalVectors(2, 1) = -1 And _
SelectedPointData(2, 1) > SelectedPointData(1, 1) And _
SelectedPointData(1, 1) < 0 And _
SelectedPointData(2, 1) >= 0 _
Then
FlipMate = True
ElseIf NormalVectors(1, 1) = 1 And _
NormalVectors(2, 1) = -1 And _
SelectedPointData(2, 1) > SelectedPointData(1, 1) And _
SelectedPointData(1, 1) < 0 And _
SelectedPointData(2, 1) < 0 _
Then
FlipMate = True
ElseIf NormalVectors(1, 1) = 1 And _
NormalVectors(2, 1) = -1 And _
SelectedPointData(2, 1) < SelectedPointData(1, 1) And _
SelectedPointData(1, 1) < 0 And _
SelectedPointData(2, 1) < 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 1) = -1 And _
NormalVectors(2, 1) = 1 And _
SelectedPointData(2, 1) > SelectedPointData(1, 1) And _
SelectedPointData(1, 1) >= 0 And _
SelectedPointData(2, 1) >= 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 1) = -1 And _
NormalVectors(2, 1) = 1 And _
SelectedPointData(2, 1) < SelectedPointData(1, 1) And _
SelectedPointData(1, 1) >= 0 And _
SelectedPointData(2, 1) >= 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 1) = -1 And _
NormalVectors(2, 1) = 1 And _
SelectedPointData(2, 1) < SelectedPointData(1, 1) And _
SelectedPointData(1, 1) >= 0 And _
SelectedPointData(2, 1) < 0 _
Then
FlipMate = True
ElseIf NormalVectors(1, 1) = -1 And _
NormalVectors(2, 1) = 1 And _
SelectedPointData(2, 1) > SelectedPointData(1, 1) And _
SelectedPointData(1, 1) < 0 And _
SelectedPointData(2, 1) >= 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 1) = -1 And _
NormalVectors(2, 1) = 1 And _
SelectedPointData(2, 1) > SelectedPointData(1, 1) And _
SelectedPointData(1, 1) < 0 And _
SelectedPointData(2, 1) < 0 _
Then
FlipMate = False
ElseIf NormalVectors(1, 1) = -1 And _
NormalVectors(2, 1) = 1 And _
SelectedPointData(2, 1) < SelectedPointData(1, 1) And _
SelectedPointData(1, 1) < 0 And _
SelectedPointData(2, 1) < 0 _
Then
FlipMate = True
End If
Else
boolstatus = False
End If
If boolstatus Then
'Now that we know the Distance between the surfaces, let's put the mate in.
swAssyDoc.AddMate2 swMateDISTANCE, swMateAlignCLOSEST, FlipMate, MateDistanceValue, MateDistanceValue, MateDistanceValue, 1, 1, 0, 0, 0, longstatus
Else
MsgBox "Routine only works for components already orthagonal to assembly Coordinate System.", vbOKOnly + vbInformation
End If
End If
End If
Else
MsgBox "Wrong number of selected items.", vbOKOnly + vbInformation, "Selection Error"
End If
Else
MsgBox "This program only works on assembly documents.", vbOKOnly + vbInformation, "Document Error"
End If
End Sub