AnsweredAssumed Answered

Assembly component's state won't update with excel vba macro

Question asked by Gregory Oundjian on Nov 3, 2017
Latest reply on Nov 13, 2017 by Gregory Oundjian

Hello,

 

I would like to control dimensions, configurations and state of components of an assembly by means of an excel macro. I am starting slowly with a basic assembly with only 2 components (square and triangle). So far, I managed to control the dimensions and configurations of the components. However, I am stuck on the state changes. It seems that no mater what command I use, it ONLY suppresses the components. I can never resolve the components... Anybody can help me with this? I am quite new to excel vba macro programming for SW...

 

Here is my code:

 

Sub Button1_Click()

 

Dim swApp As SldWorks.SldWorks

Dim Part As Object

Dim swComp As SldWorks.Component2

 

Set swApp = CreateObject("SldWorks.Application")

Set Part = swApp.ActiveDoc

 

'--- Changing dimensions of components in assembly ---

 

Part.Parameter("Side@Sketch1@Square.Part").Value = Range("C5").Value

Part.Parameter("Height@Boss-Extrude1@Square.Part").Value = Range("C6").Value

 

Part.Parameter("Side@Sketch1@Triangle.Part").Value = Range("F5").Value

Part.Parameter("Height@Boss-Extrude1@Triangle.Part").Value = Range("F6").Value

 

'--- Changing mate dimensions in assembly ---

 

retval = Part.Parameter("Square@Distance1@Assembly.Part").SetValue2(Sheet1.Range("I5").Value, 1)

retval = Part.Parameter("Triangle@Distance2@Assembly.Part").SetValue2(Sheet1.Range("I6").Value, 1)

 

'--- Changing configuration of components in assembly ---

 

Set swComp = Part.GetComponentByName("Square-1")

 

swComp.ReferencedConfiguration = "Big"

 

 

'--- Changing state of components in assembly ---

 

'swComp.SetSuppression2 (swComponentSuppressed)

 

swComp.SetSuppression2 (swComponentResolved)

 

 

 

Part.EditRebuild

 

End Sub

Outcomes