Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

distance mate macro

Status
Not open for further replies.

swmetal

Mechanical
Oct 13, 2006
58
Hi all,
Has anyone tried to create a distance mate macro? When I try and apply what Ive created, it gives me a limit mate instead. SW2005 sp5.0 Thanks
 
Replies continue below

Recommended for you

Can you post an image of the features involved?

... and the equation you are using?

[cheers]
 
CBL
I record a macro and choose the appropriate commands to get a distance mate, choosing two faces prior. I think my problem has something to do with the need for a distance input. I thought I was able to pause recording, allowing the input of the distance needed however the pause button on the macro toolbar is not available. I have created concentric ans coincident mate macros using this procedure.
Thanks
 
Macro recording usually creates clunky, inefficient code with no error trapping. Check out the assembly macro page of Matthew Lorono's website (and the other pages too) for some cleaned-up macros.


If you want to input a distance value at the beginning of your macro to use as the mate distance you'll need to use an InputBox function prior to the AddMate.
 
Thanks Hman
Im limited in knowledge of API functions. Can you give me the string to stop the macro and allow the user input? Thanks
 
swmetal,

If you are fresh to macro's, I recommend starting off small. Get a feel for how the API works. Jumping right in to a complex macro might be too big of a bite early on.

I've set up my site for novice to intermediate users as a resource to learn and expand functionality in SolidWorks macros. There's an example of pretty much every S/W macro function you might need/want as a someone without a lot of exposure to API. I recommend checking out many of the downloads provided. These are the same ones that I used to learn on.

To directly anwser your question though: on getting user input, the simpliest way is using InputBox. Look up InputBox in Solidworks API Help, and also check out the many examples where it is used on my website.

Good luck!

Matt
CAD Engineer/ECN Analyst
Silicon Valley, CA
 
A Distance macro is a lot harder than you probably realize. You have to be able to recognise the Alignment, which side, and the current distance between the selections before you can really begin doing anything. I tried writing one for this, but the time involved would never really be justified. I do have something (that isn't very flexible but does work) that maybe would help you:

Code:
'==========================================================
'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


I just found this other macro that I had saved too. I have no idea if it works, where it came from, or if I even wrote it, but maybe this one could help?

Ken

Code:
'==========================================================
'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

 
Thanks for all your help and thanks to Ken for thr macros.
I didnt realize how much code it took. I copied the file and attached to my button but doesnt seem to work completely yet. I'll continue to monkey around with it.
Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor