- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Dear Community,
i tried to create a code that does the following:
1) define a new model state in an assembly
2) Define a search string
3) Loop through an assembly and find all components that do NOT contain the search string.
4) suppress all found components regardless of their parent
If followed this topic:
Solved: Create a Model State and suppres parts based om modelbrowser name - Autodesk Community
But i could not figure out on how to deal with the case when an sub-assembly has a component name that does NOT include the search string, but included components that DO have the search string in their name. Means, the subassembly has to active, even if its component name includes the "wrong" search string.
Example: Searchstring is "shaft" --> all components that do not contain the string "shaft" should be suppressed. But there is a subassembly called "Group", and that subassembly contains a part called "shaft". in that case, the subassembly should remain active in order to have its children active, even though it should be suppressed because of its name.
i got this so far (which not works for the problem mentioned above):
Dim oAsmDef As AssemblyDocument doc = ThisDoc.Document myCount = 0 'create a counter Dim searchTerm As String = "___" Dim oComp As ComponentOccurrence oComps = doc.ComponentDefinition.Occurrences For Each oComp In oComps oName = oComp.Name If oName.Contains(searchTerm) myCount = myCount+1 'if found increment counter by 1 Else oComp.Suppress End If Next If myCount = 0 MessageBox.Show("None Found", "None Found Message") Else MessageBox.Show(myCount & " of " & searchTerm & " found", "Found This Many") End If
Are there any ideas on how to proceed? Thank you in advance!
Solved! Go to Solution.