Solidworks macro - mating planes

Discussion in 'SolidWorks' started by yochris77, Apr 28, 2007.

  1. yochris77

    yochris77 Guest

    I have no knowledge on how to create macros in Solidworks.

    I have used the Macro recorder and came up with a macro which is
    nearly what I want. I would like to be in any assembly, select 2
    parts, assemblies or a part and an assembly and have it mate the Top
    plane of one to the top plane of another, Front plane of other to
    Front plane etc.

    Is there a better way to do this??

    This is what I have so far - it will not work if the parts/assemblies
    are different names:

    Dim swApp As Object
    Dim Part As Object
    Dim SelMgr As Object
    Dim boolstatus As Boolean
    Dim longstatus As Long, longwarnings As Long
    Dim Feature As Object
    Sub main()

    Set swApp = Application.SldWorks

    Set Part = swApp.ActiveDoc
    Set SelMgr = Part.SelectionManager
    boolstatus = Part.Extension.SelectByID2("Front@Dual Base Plate
    Assy-1@QX10 Dual Base Assy", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
    boolstatus = Part.Extension.SelectByID2("Front", "PLANE", 0, 0, 0,
    True, 0, Nothing, 0)
    Set Feature = Part.AddMate2(0, -1, False, 0, 0, 0, 1, 1,
    1.570796326795, 0.5235987755983, 0.5235987755983, longstatus)
    Part.ClearSelection2 True
    boolstatus = Part.Extension.SelectByID2("Top", "PLANE", 0, 0, 0, True,
    1, Nothing, 0)
    boolstatus = Part.Extension.SelectByID2("Top@Dual Base Plate
    Assy-1@QX10 Dual Base Assy", "PLANE", 0, 0, 0, True, 1, Nothing, 0)
    Set Feature = Part.AddMate2(0, -1, False, 0.0107, 0, 0, 1, 1, 0,
    0.5235987755983, 0.5235987755983, longstatus)
    Part.ClearSelection2 True
    boolstatus = Part.Extension.SelectByID2("Right@Dual Base Plate
    Assy-1@QX10 Dual Base Assy", "PLANE", 0, 0, 0, True, 1, Nothing, 0)
    boolstatus = Part.Extension.SelectByID2("Right", "PLANE", 0, 0, 0,
    True, 1, Nothing, 0)
    Set Feature = Part.AddMate2(0, -1, False, 0, 0, 0, 1, 1,
    1.570796326795, 0.5235987755983, 0.5235987755983, longstatus)
    Part.ClearSelection2 True
    End Sub


    Any help appreciated.
    Chris
     
    yochris77, Apr 28, 2007
    #1
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.