AnsweredAssumed Answered

Macro Crashing Solidworks when adding configuration

Question asked by Rob Edwards on Jan 28, 2021
Latest reply on Jan 29, 2021 by Rob Edwards

Hi Guys


I've been working on a macro that's been working great, but then it started crashing when I added an InsertAxis Feature.

The axis is added perfectly, it is only later when the second new configuration is added that the crash happens.


I've written a simpler example that illustrates the problem..



this works just fine


As Does This


But run both together and I get this splendid error



and then a hard crash!


full code below




Option Explicit

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swPart As SldWorks.PartDoc

Sub main()

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swPart = swModel

Dim RightPlane As SldWorks.Feature
Dim TopPlane As SldWorks.Feature

Set RightPlane = swPart.FeatureByName("Right Plane")
Set TopPlane = swPart.FeatureByName("Top Plane")

Dim newPlane As SldWorks.Feature
Set newPlane = RightPlane

Dim swConfig As SldWorks.Configuration

Dim i As Long
For i = 1 To 10

Set swConfig = swModel.AddConfiguration3("C" & CStr(i), "", "", swConfigOption_SuppressByDefault)

newPlane.Select2 Append:=False, Mark:=0
Set newPlane = swModel.FeatureManager.InsertRefPlane(swRefPlaneReferenceConstraint_Distance, 0.01, 0, 0#, 0, 0#)

newPlane.Select2 Append:=False, Mark:=0
TopPlane.Select2 Append:=True, Mark:=0
swModel.InsertAxis2 True

Next i

End Sub