Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim swAssm As AssemblyDoc
Dim vComp As Variant
Dim Count As Integer
Dim swComp As Component2
Dim swDoc As ModelDoc2
Dim swConf As Configuration
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swAssm = swModel
vComp = swAssm.GetComponents(True)
For Count = 0 To UBound(vComp)
Set swComp = vComp(Count)
Set swDoc = swComp.GetModelDoc2
Set swConf = swDoc.GetConfigurationByName("Simplified")
If Not swConf Is Nothing Then
swComp.ReferencedConfiguration = "Simplified"
Debug.Print swComp.Name2 & " is not having Simplified configuration"
Worked great man , I like the .GetComponents better than the way I was trying to do it. Thank you very much !
TL;DR: Instead of choosing configuration based off of exact match, how would I select config. based off of an InStr search for each config. name?
I have a similar task that I'm trying to accomplish with selecting configurations that I'm hoping you could help with as well.
I need to create a unique assembly and drawing that will vary in size as required by the customer. Each of the parts in this assembly have many configurations that can be selected depending on the required size. The problem that I am running into is that the configurations of the parts do not share the same naming convention, which means I cannot use an exact match to select the configurations. They do however share the same 'size' in their configuration names, which is what I want to use to select the parts' configurations.
My assembly has 4 parts in it: a tee, 2 flanges, and a blind flange. Customer puts an order in for a Strainer of size NPS 12. So now I'd like pull that size requirement from an excel file (I already have the code for this) and select the configuration that has "NPS 12" in the configuration name for each of the parts, and then generate the drawing.
Of course a lot more code is required to generate the drawing. I'm just having trouble getting the traversal loop to work with my requirements. I'm thinking using GetConfigurationNames() and then using InStr to search the string for "NPS 12" could work, but the compiler is throwing errors when I try to implement that.
Any help would be greatly appreciated!
Dim Str As String
Str = "Test NPS 12"
Dim newStr As String
newStr = Mid(Str, InStr(1, Str, "N")) 'Wil Retrun NPS 12
Dim sVal As Variant
sVal = Split(Str, " ") 'Will Return Split Array