- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello all,
Hoping for a bit advice here!
I'm building a product configurator, which makes parts visible/ hidden depending on options picked in a user form.
I'm trying to give the option to colour certain components withing the assembly - for example all of the upholstery panels. The upholstery panels could be identified either by a custom iproperty field (containing the text "UPH", or a custom appearance applied to them (eg "Uph_appearance"). Once they are all selected by Ilogic, the user can then open the appearance browser and apply a finish to all selected components. Even better if the Ilogic can select the relevant components and then open the appearance browser itself : )
I don't want to use component.color, as the user may need to make a custom appearance, and the list of options is too long for the form.
I have found the following code by @g.georgiades which selects components that have the same appearance as one you have selected - which works great - I just can't seem to edit it to correctly select components that meet a certain criteria.
If easier, I could name all of the specific components that need selecting (rather than choosing them based on iproperties or appearance) - I just haven't had much luck with the selectset function to date.
Glad of any thoughts - thanks!
Jack
Public Class Select_By_Appearance Sub main() 'Only operate in assemblies. If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then Exit Sub Dim doc As AssemblyDocument = ThisAssembly.Document 'Collect the occurrences the user has selected currently Dim sel As List(Of ComponentOccurrence) = doc.SelectSet.Cast(Of Object).Where(Function(f) TypeOf f Is ComponentOccurrence).Cast(Of ComponentOccurrence).ToList() If sel.Count = 0 Then Exit Sub 'Collect unique appearances for selected occurrences to match against. Use Appearance name for simplicity. Dim assets As List(Of String) = sel.Select(Function(s) s.Appearance.DisplayName).Distinct().ToList() Dim cpt As ComponentDefinition = doc.ComponentDefinition 'Collect all occurrences from the assembly, both assemblies and sub components. Filter any potential duplicate occurrences. Dim occs As IEnumerable(Of ComponentOccurrence) = cpt.Occurrences.Cast(Of ComponentOccurrence).Concat(cpt.Occurrences.AllLeafOccurrences.Cast(Of ComponentOccurrence)).Distinct() 'List to hold the matches Dim toselect As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection 'Loop over all occurrences and add to selection list if any of the match appearances match. For Each occ As ComponentOccurrence In occs If assets.Any(Function(r) String.Equals(r, occ.Appearance.DisplayName, StringComparison.InvariantCultureIgnoreCase)) Then toselect.Add(occ) End If Next 'Select all matches for viewing or further processing. doc.SelectSet.SelectMultiple(toselect) End Sub End Class
Solved! Go to Solution.