I have a routine that makes a mate to an inserted part, butno matter what I put for the distance value, it always makes mydistance mate 1"
I have the same question for my angle mates, I put 45 as my value,but they come out 58.31007809deg in the assembly.
I think it has to do with the values vs units thing?? Is therequired value a real/integer/etc... and it's not equal to my dim?
I'm running the macro in an assembly, and the units are IPS (inchpound second) whichis what I want.
Here are the two commands to make the mates: (the top one is theangle mate and the bottom one is the distance mate)
Thanks!
-Wes
boolstatus = assy.Extension.SelectByID2("Front Plane@" &swComp.Name2 & "@" & swRootComp.Name2, "PLANE", 0, 0, 0,False, 0, Nothing, 0)
boolstatus = assy.Extension.SelectByID2("Front Plane", "PLANE", 0,0, 0, True, 0, Nothing, 0)
assy.AddMate 6, 2, 0, 0.06326275636025, 45
boolstatus = assy.Extension.SelectByID2("Top Plane@" &swComp.Name2 & "@" & swRootComp.Name2, "PLANE", 0, 0, 0,False, 0, Nothing, 0)
boolstatus = assy.Extension.SelectByID2("Top Plane", "PLANE", 0, 0,0, True, 0, Nothing, 0)
assy.AddMate 5, 2, 0, 0.0254, 24
SolidworksApi macros
I have the same question for my angle mates, I put 45 as my value,but they come out 58.31007809deg in the assembly.
I think it has to do with the values vs units thing?? Is therequired value a real/integer/etc... and it's not equal to my dim?
I'm running the macro in an assembly, and the units are IPS (inchpound second) whichis what I want.
Here are the two commands to make the mates: (the top one is theangle mate and the bottom one is the distance mate)
Thanks!
-Wes
boolstatus = assy.Extension.SelectByID2("Front Plane@" &swComp.Name2 & "@" & swRootComp.Name2, "PLANE", 0, 0, 0,False, 0, Nothing, 0)
boolstatus = assy.Extension.SelectByID2("Front Plane", "PLANE", 0,0, 0, True, 0, Nothing, 0)
assy.AddMate 6, 2, 0, 0.06326275636025, 45
boolstatus = assy.Extension.SelectByID2("Top Plane@" &swComp.Name2 & "@" & swRootComp.Name2, "PLANE", 0, 0, 0,False, 0, Nothing, 0)
boolstatus = assy.Extension.SelectByID2("Top Plane", "PLANE", 0, 0,0, True, 0, Nothing, 0)
assy.AddMate 5, 2, 0, 0.0254, 24
SolidworksApi macros

Sub main()
Dim swapp As SldWorks.SldWorks
Dim swmodel As SldWorks.ModelDoc2
Dim assy As SldWorks.AssemblyDoc
Dim boolstatus As Boolean
Dim longwarnings As Long, longerror As Long
Dim swComp As SldWorks.Component2
Dim refModel As SldWorks.ModelDoc2
Dim Filter As String
Dim fileName As String
Dim fileConfig As String
Dim fileDispName As String
Dim fileOptions As Long
Dim sDocType As String
Dim swConfig As SldWorks.Configuration
Dim swRootComp As SldWorks.Component2
Const PI As Double = 3.14159265358979
Set swapp = Application.SldWorks
' This following string has three filters associated with it; notethe use
' of the | character between filters
Filter = "SolidWorks Files (*.sldprt; *.sldasm;*.slddrw)|*.sldprt;*.sldasm;*.slddrw|Filter name (*.fil)|*.fil|AllFiles (*.*)|*.*"
fileName = swapp.GetOpenFileName("File to Attach", "", Filter,fileOptions, fileConfig, fileDispName)
' In the dialog, click the down-arrow associated with Files to Typeto see the filters
' dialogFiles of Type down arrow key
Set swmodel = swapp.ActiveDoc
If swmodel.GetType <> swDocASSEMBLY Then
MsgBox "open assembly first"
Exit Sub
End If
If UCase(swmodel.GetPathName) = UCase(fileName) Then
MsgBox "Can't open same file"
Exit Sub
End If
Set assy = swmodel
Select Case UCase(Right(fileName, 6))
Case "SLDASM"
sDocType = swDocASSEMBLY
Case "SLDPRT"
sDocType = swDocPART
Case Else
MsgBox "Wrong type"
Exit Sub
End Select
swapp.DocumentVisible False, sDocType
Set refModel = swapp.OpenDoc6(fileName, sDocType,swOpenDocOptions_Silent, fileConfig, longerror, longwarnings)
Set swComp = assy.AddComponent4(fileDispName, fileConfig, 0, 0, 0)
swapp.DocumentVisible True, sDocType
Set swConfig = swmodel.GetActiveConfiguration
Set swRootComp = swConfig.GetRootComponent
boolstatus = assy.Extension.SelectByID2("Front Plane@" &swComp.Name2 & "@" & swRootComp.Name2, "PLANE", 0, 0, 0,False, 0, Nothing, 0)
boolstatus = assy.Extension.SelectByID2("Front Plane", "PLANE", 0,0, 0, True, 0, Nothing, 0)
assy.AddMate3 swMateANGLE, 2, 0, 0.632, 0.632, 0.632, 0, 0, 45 * PI/ 180, 45 * PI / 180, 45 * PI / 180, False, longerror
boolstatus = assy.Extension.SelectByID2("Top Plane@" &swComp.Name2 & "@" & swRootComp.Name2, "PLANE", 0, 0, 0,False, 0, Nothing, 0)
boolstatus = assy.Extension.SelectByID2("top plane", "PLANE", 0, 0,0, True, 0, Nothing, 0)
assy.AddMate3 swMateDISTANCE, 2, 0, 0.0254, 0.0254, 0.0254, 0, 0,0, 0, 0, False, longerror
assy.UnfixComponent
assy.ClearSelection2 True
End Sub
http://files.engineering.com/g...InsertMateDistance.swp
Based on the Angle mate code that Ivana provided me, it looks likethe api deals with Radians. I seem to remember something about thatfrom my old college days. Thanks for that!
What about the Distance mates though... do they only deal withmilimeters or something? Why is it that when I replace my code withyours for the distance mate, it still comes out 1"??
Kelvin, when I look at your routine, I see you're adding the mate,then changing it. Is this because Sw won't allow you to add theexact distance to begin with?
void AssemblyDoc.AddMate ( mateType, align, flip, dist, angle)
Your code has 0.0254 for the "dist" argument. This specifies a matedistance of 0.0254 meters, or 1". The 24 in your code is the"angle" argument, which is ignored for a distance mate.
45 radians is about 2578.31 degrees, which corresponds to 58.31degrees after you subtract out 7*360.
All I needed to do was get the correct placement of my dimension,and change it's value to meters instead of inches.
-Thanks!