Hello API users,
I am trying to create a macro that allows me to select a ring gakset part and mate the ring gasket's top plane to another parts flat face and to parallel mate the gasket's front plane to the assembly front plane. I know this is a relatively basic thing to do with a macro but I seem to be having some issues.
Everywhere I use a flanged connection I insert a gasket and I have to add the mates over and over again. I would like to select the unmated gasket in the feature tree, select the flat face of the flange, run the macro and be done with it.
I included a picture of what I am talking about as a .bmp screen capture.
So when I create the macro it works fine for the ring gaset I create the macro with. The problem is that my macro only wants to work on that particular ring gasket and not any other ring gaskets, essentially I end up duplicating mates on the same part, see code below.
' ******************************************************************************
' C:\Documents and Settings\TJOHNS\Local Settings\Temp\swx3480\Macro1.swb - macro recorded on 12/28/09 by tjohns
' ******************************************************************************
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
boolstatus = Part.DeSelectByID("Ring Gaskets-4@CS40040", "COMPONENT", 0, 0, 0)
boolstatus = Part.Extension.SelectByID2("Top Plane@Ring Gaskets-4@CS40040", "PLANE", 0, 0, 0, True, 1, Nothing, 0)
Dim myMate As Object
Set myMate = Part.AddMate3(5, 1, False, 0.002286, 0.002286, 0.002286, 0.0254, 0.0254, 0, 0.5235987755983, 0.5235987755983, False, longstatus)
Part.ClearSelection2 True
Part.EditRebuild3
boolstatus = Part.Extension.SelectByID2("Right Plane@Ring Gaskets-4@CS40040", "PLANE", 0, 0, 0, True, 1, Nothing, 0)
boolstatus = Part.DeSelectByID("Right Plane@Ring Gaskets-4@CS40040", "PLANE", 0, 0, 0)
boolstatus = Part.Extension.SelectByID2("Front Plane@Ring Gaskets-4@CS40040", "PLANE", 0, 0, 0, True, 1, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, True, 1, Nothing, 0)
Set myMate = Part.AddMate3(3, 0, False, 0, 0, 0, 0.0254, 0.0254, 0, 0.5235987755983, 0.5235987755983, False, longstatus)
Part.ClearSelection2 True
Part.EditRebuild3
End Sub
I've made bold font the part of the code that I believe is giving me the trouble, Ring Gasket-4 is the 4th instance of the same part used at least 4 other times in the same assembly.
How do I set that value as a variable so that it only grabs the ring gasket I am working on whether its the 1st, 2nd, 3rd, etc instance that I want to mate?
Also CS40040 is the name of the assembly I am working on, How do I set its value as a variable so that this macro works in any assembly?
SolidworksApi macros