I wrote a macro to select a component by name from an assembly and then change its dimensions as required to automate the process.
Since I used dimension names, this script cannot be currently used for other similar assemblies.
My question is, how can I get all the dimensions of the selected component in the assembly file.
Including a part of my code here:
Dim vComponents As Variant
Dim vComp As Variant
Dim Part As Object
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
vComponents = Part.GetComponents(True)
For Each vComp In vComponents
Set swComp = vComp
If InStr(swComp.Name2, "_ST_") > 0 Then swComp.Select4 True, Nothing, False
Next
Set swSelMgr = Part.SelectionManager
Set swSelComp = swSelMgr.GetSelectedObjectsComponent4(1, -1)
Set swReferenceModel = swSelComp.GetModelDoc2
originalStello = swReferenceModel.Parameter("D7@Schizzo1").Value // this is where I am hard coding the name
In the last line, you can see that I am getting the dimension value by hard coding its name. I would rather like to get all dimensions of the SELECTED component and then write logic to get a particular dimension from that list.
I started working with Solidworks API 2 days ago. Please help!
you could read all "Parameters" from the referenced model of your selected component like. To do so you first have to get the ActiveConfiguration of the referenced model and then use GetParameters to fill the variant variables.
The variable vParamNames is containing the parameter names and the variable vParamValues is containing the belonging values. You maybe have to filter out the needed dimensions.
Dim swSelMgr As SldWorks.SelectionMgr
Set swSelMgr = Part.SelectionManager
Dim swSelComp As SldWorks.Component2
Set swSelComp = swSelMgr.GetSelectedObjectsComponent4(1, -1)
Dim swReferenceModel As SldWorks.ModelDoc2
Set swReferenceModel = swSelComp.GetModelDoc2
Dim swConfig As SldWorks.Configuration
Set swConfig = swReferenceModel.ConfigurationManager.ActiveConfiguration
Dim vParamNames As Variant
Dim vParamValues As Variant
swConfig.GetParameters vParamNames, vParamValues