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!
SolidworksApi/macros
Check this example: Traverse all dimensions of component or model using SOLIDWORKS API
Hi,
You can use the below code sample:
I have commented each line so that you can understand why I am using those functions and objects.
This macro will give output on the Immediate Window of Visual Basic Editor.
In case you don't know how to open the Immediate window in VBE then go to this blog.
Since you have just started you will found this blog interested to you.
Thanks
Prashant Baher