Skip to main content

Fix SOLIDWORKS macro which is using future version APIs

Symptoms

Recently developed SOLIDWORKS macro is run on old (not the latest) version of SOLIDWORKS. When run, Run-time error '438': object doesn't support this property or method is displayed.

Run-time error '438': object doesn't support this property or method displayed when running the macro{ width=400 height=151 }

Alternatively Run-time error '445': object doesn't support this action can be displayed.

Run-time error '445': object doesn't support this action is displayed when running the macro{ width=400 height=171 }

Cause

SOLIDWORKS is backward compatible system which means that older versions of the files or APIs will be compatible with every new release. However SOLIDWORKS is not forward compatible which means that new APIs cannot be used in the older versions of the software. Every release SOLIDWORKS is adding new APIs to the libraries which can be used by the developer to write macros. But those macros cannot be used in the older versions of SOLIDWORKS

Resolution

  • Check SOLIDWORKS API help for the method accessibility which is highlighted by the error

Availability option in SOLIDWORKS API Help Documentation{ width=400 height=216 }

  • If the earliest available version is newer than it is required to replace the method with an alternative one

Usually SOLIDWORKS names the method with an index, e.g. OpenDoc4, OpenDoc5, OpenDoc6 which indicates the superseded version. If this is the case try to see if there is an older version of this method available. If so this can be used. Please note that older version might have different sets of parameters so it is not always enough just to change the version number

Difference between versions of the CompConfigProperties API method{ width=400 height=122 }

  • If no older methods available it will be required to overwrite the logic of the macro using alternative methods.
  • Upgrade SOLIDWORKS software to the never minimum supported version

Example macro which is using the API added to SOLIDWORKS 2017

Dim swApp As SldWorks.SldWorks
Dim swAssy As SldWorks.AssemblyDoc

Sub main()

Set swApp = Application.SldWorks

Set swAssy = swApp.ActiveDoc

swAssy.CompConfigProperties5 swComponentSuppressionState_e.swComponentSuppressed, _
swComponentSolvingOption_e.swComponentRigidSolving, _
True, False, "", False, False

End Sub

Modified macro which enables compatibility with SOLIDWORKS 2005 onwards

Dim swApp As SldWorks.SldWorks
Dim swAssy As SldWorks.AssemblyDoc

Sub main()

Set swApp = Application.SldWorks

Set swAssy = swApp.ActiveDoc

swAssy.CompConfigProperties4 swComponentSuppressionState_e.swComponentSuppressed, _
swComponentSolvingOption_e.swComponentRigidSolving, _
True, False, "", False

End Sub