Hello everyone I have problem with mate width. Basicly macro opening two parts making assembly after that selecting two faces adding mate "concident" after that selecting two faces from one item and two faces from second item. It should connect them by mate width (one item between the other). I'm using similar mate instruction
like with mate "concident" "Set myMate = AssyDoc.AddMate5(11, 0, True, 0#, 0#, 0.001, 0.001, 0.001, 0#, 0#, 0#, False, False, 0, longstatus)" but it's not adding this mate. I don't know what I should do to add this mate...
Thanks for the help in advanced!
Below is my code:
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Sub main()
Dim CompName As String
Dim boolstatus As Boolean
Dim faceName As String
Dim AssyDoc As Object
Dim SelMgr As Object
Dim Comp As Object
Dim Body As Object
Dim Face As Object
Dim FFaceName As String
Dim CurFaceName As String
Dim CCompName As String
Dim longstatus As Long
Dim myMate As Object
Dim myComp1 As Component2
Dim myComp2 As Component2
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swAssy As SldWorks.AssemblyDoc
Dim strings As Variant
Dim AssemblyName As String
Dim AssemblyTitle As String
Dim SecondSelection As String
Set swApp = CreateObject("SldWorks.Application")
Set Part = swApp.ActiveDoc
Set Part = swApp.NewDocument("C:\Solidworks\Vorlagen\Dokumentvorlagen\Baugruppe.asmdot", 0, 0, 0)
swApp.ActivateDoc2 "Assem8", False, longstatus
Set Part = swApp.ActiveDoc
Dim myModelView As Object
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized
krzyzak = "C:\Makro\cardan\models\Gelenkkreuz_1_106_0_106-+-AUX-102665_1.sldprt"
kolnierz = "C:\Makro\cardan\models\Gabelflansch_1_106_300_0201_1_106_300_001_2.sldprt"
boolstatus = Part.AddComponent(krzyzak, 0, 0, 0)
boolstatus = Part.AddComponent(kolnierz, 0, 0, 0)
If boolstatus = False Then
Set swModel = swApp.OpenDoc6(krzyzak, 1, 0, "", longwarnings, longstatus)
Set swModel = swApp.OpenDoc6(kolnierz, 1, 0, "", longwarnings, longstatus)
swApp.ActivateDoc Part.GetPathName
boolstatus = Part.AddComponent(krzyzak, 0, j, i)
boolstatus = Part.AddComponent(kolnierz, 0, j, i)
swApp.CloseDoc swModel.GetPathName
swModel.ClearSelection2 True
End If
Const swSelCOMPONENTS = 20
Set swApp = CreateObject("SldWorks.Application")
Set AssyDoc = swApp.ActiveDoc()
AssyDoc.ClearSelection2 True
CompName = Application.SldWorks.ActiveDoc.GetTitle()
CompName = "Gelenkkreuz_1_106_0_106-+-AUX-102665_1-1"
faceName = "krzyzak_1"
CCompName = CompName
FFaceName = faceName
SelectComponentFaceByName CCompName, FFaceName
CompName = "Gabelflansch_1_106_300_0201_1_106_300_001_2-1"
faceName = "kolnierz_1_2"
CCompName = CompName
FFaceName = faceName
SelectComponentFaceByName CCompName, FFaceName
Set myMate = AssyDoc.AddMate5(1, 0, True, 0#, 0#, 0.001, 0.001, 0.001, 0#, 0#, 0#, False, False, 0, longstatus)
Part.ClearSelection2 True
CompName = "Gelenkkreuz_1_106_0_106-+-AUX-102665_1-1"
faceName = "czolowa1"
CCompName = CompName
FFaceName = faceName
SelectComponentFaceByName CCompName, FFaceName
CompName = "Gelenkkreuz_1_106_0_106-+-AUX-102665_1-1"
faceName = "czolowa2"
CCompName = CompName
FFaceName = faceName
SelectComponentFaceByName CCompName, FFaceName
CompName = "Gabelflansch_1_106_300_0201_1_106_300_001_2-1"
faceName = "kolnierz_2"
CCompName = CompName
FFaceName = faceName
SelectComponentFaceByName CCompName, FFaceName
CompName = "Gabelflansch_1_106_300_0201_1_106_300_001_2-1"
faceName = "kolnierz_2_1"
CCompName = CompName
FFaceName = faceName
SelectComponentFaceByName CCompName, FFaceName
Set myMate = AssyDoc.AddMate5(11, 0, True, 0#, 0#, 0.001, 0.001, 0.001, 0#, 0#, 0#, False, False, 0, longstatus)
End Sub
Public Sub SelectComponentFaceByName(CompName As String, faceName As String)
Dim swApp As Object
Dim AssyDoc As Object
Dim swAssy As SldWorks.AssemblyDoc
Dim swComp As SldWorks.Component2
Dim SelMgr As Object
Dim SelData As SldWorks.SelectData
Dim Comp As Object
Dim Body As Object
Dim Face As Object
Dim CurFaceName As String
Dim boolstatus As Boolean
Const swSelCOMPONENTS = 20
Set swApp = CreateObject("SldWorks.Application")
Set AssyDoc = swApp.ActiveDoc()
Set SelMgr = AssyDoc.SelectionManager()
Set SelData = SelMgr.CreateSelectData
Set Comp = AssyDoc.GetComponentByName(CompName)
Set Body = Comp.GetBody() ' Get the Component Body
If (Body Is Nothing) Then
swApp.SendMsgToUser "Component Body Unavailable."
swApp.SendMsgToUser "Make sure not lightweight or suppressed"
Exit Sub
End If
Set Face = Body.GetFirstFace
Do While Not Face Is Nothing
CurFaceName = AssyDoc.GetEntityName(Face)
If (CurFaceName = faceName) Then
boolstatus = Face.Select4(True, SelData)
Exit Do
End If
Debug.Print CurFaceName
Set Face = Face.GetNextFace
Loop
End Sub