AnsweredAssumed Answered

API Help!  Creating a derived mirror configuration.

Question asked by Michael Halbleib on Jun 8, 2017
Latest reply on Jun 14, 2017 by Michael Halbleib

Hello, I am making the switch from lurking on the forums to asking a question.  The reason for this change is that I cannot find an answer to my problem anywhere I have looked.  Sorry if this is a simple request, but I have no formal training in making macros.

 

My problem is that I am trying to make a macro to created a derived mirror configuration of an open part file.  Manually we always open an assembly, insert the part and run the mirror function, ticking off the same selections each time.  I did not see any simpler existing way in SolidWorks 2016 so I decided to write a macro to do it.  Below is the code I have so far, however, I continually get a "Run-time error '438': Object doesn't support this property or method"  What am I doing wrong, what needs changed to make this work, or is there a simpler way to get the same result?  Thanks for any help.

 

Dim swPart As Object
Dim swAssy As Object
Dim Result As Long
Dim ActiveConfig As Object
Dim boolstatus As Boolean
Dim errors As Long
Dim warnings As Long

 

Public Sub CreateMirror()
    Set swApp = Application.SldWorks
    swApp.Visible = True
    Set swDoc = swApp.ActiveDoc

 

    Set swPart = swApp.ActiveDoc
    Set ActiveConfig = swPart.GetActiveConfiguration

    Dim ConfigName As String
        ConfigName = ActiveConfig.Name
    Dim PartPathName As String
        PartPathName = swPart.GetPathName()
        PartPath = InStrRev(PartPathName, "\") + 1
        PartExten = InStrRev(PartPathName, ".")
    Dim PartName As String
        PartName = Mid$(PartPathName, PartPath, PartExten - PartPath)


    Set swDoc = swApp.NewDocument("C:\WTI-Vault\WTI Templates\Assembly.asmdot", 0, 0, 0)
    Set swAssy = swApp.ActiveDoc
    Dim AssyName As String
        AssyName = swAssy.GetTitle


    boolstatus = swAssy.AddComponent(PartPathName, 0, 0, 0)


    Dim MirrorPlane As SldWorks.Feature
    Set MirrorPlane = swAssy.FeatureByName("Right Plane")


    Dim CompToMirror(0) As Object
    Set CompToMirror(0) = swAssy.GetComponentByName(PartName & "-1")


    Dim NameModifier As String
        NameModifier = ""

 

    Dim DerivedName As String
        DerivedName = "_Mirror2"


    Dim CompToInstance As Object
    Set CompToInstance = Nothing

 

    Dim Orientations As Object
    Set Orientations = Nothing

 

    Dim OrientAboutCoM As Boolean
        OrientAboutCoM = False

 

    Dim CreateDerivedConfigs As Boolean
        CreateDerivedConfigs = True

 

    Dim NameModifierType As swMirrorComponentNameModifier_e
        NameModifierType = swMirrorComponentName_Custom

 

    Dim FileLocation As String
        FileLocation = Left$(PartPathName, PartPath)

 

    Dim ImportOptions As Integer
        ImportOptions = swMirrorPartOptions_ImportSolids

 

    Dim BreakLinks As Boolean
        BreakLinks = False

 

    Dim PreserveZAxis As Boolean
        PreserveZAxis = False

 

    Dim FlexSync As Boolean
        FlexSync = False

 

    Dim DerivedMirror As Object
        DerivedMirror = swAssy.MirrorComponents3(MirrorPlane, CompToInstance, Orientations, OrientAboutCoM, _
                        CompToMirror, CreateDerivedConfigs, DerivedName, NameModifierType, NameModifier, _
                        FileLocation, ImportOptions, BreakLinks, PreserveZAxis, FlexSync)

  
    swApp.CloseDoc AssyName

    boolstatus = swPart.EditRebuild3()

 

End Sub

Outcomes