I am modifying some code which adds components selected from a list view to a new assembly.
Once these components are inserted, I am comparing a value stored in a database for each component, to a current value. If the value of the component equals this stored value, the component is selected. Once this component is selected, I create a folder with the name of this value, which should have all of my selected components inside it. After this code runs, all components should be inside a folder(s) with a predefined name.
What's actually happening - If all of my selected components aren't together in the feature tree, if there are un-selected components separating them in the hierarchy, only the top selected components get put in the folder.
For example - components : 1, 2, 3, 4 selected 5, 6, 7, 8 NOT selected 8, 9 selected
Only components 1, 2, 3, 4 would get put in the folder, even though 8, 9 are also selected. If there happens to be another already created folder between these selected locations, say between components 5 & 6, even though this pre-created folder is NOT selected, it gets copied into the new folder containing 1, 2, 3, 4. Mouse selecting a component within this copied folder will also highlight the same component within the original folder.
Anyone know whats happening, and how I can get around this - Thanks for any replies - Sean
Code follows:
-----------------------------------------------------------------------------------
Dim swMyModel As ModelDoc2 Dim swMyChldModel As ModelDoc2 Dim swMyFtrMngr As FeatureManager Dim swMyFeat As feature Dim swMyComp As Component2 Dim swConfig As Configuration Dim swMyCnfgMngr As ConfigurationManager
Set swMyModel = swApp.ActiveDoc Set swMyFtrMngr = swMyModel.FeatureManager Set swMyCnfgMngr = swMyModel.ConfigurationManager Set swConfig = swMyCnfgMngr.ActiveConfiguration Set swMyComp = swConfig.IGetRootComponent2
strCurClass = "whatever"
'>>>>>>Select components that meet my criteria - all components are being selected properly vntComponents = swMyComp.GetChildren For Each vntCurComp In vntComponents Set swMyComp = vntCurComp Set swMyChldModel = swMyComp.GetModelDoc strCompPth = swMyChldModel.GetPathName
'>>>>>>Function to retrieve my pre-defined category strCompCat = GetCategory_ByPath(strCompPth) If strCurClass = strCompCat Then blnRet = swMyComp.Select2(True, intMrk) End If Next vntCurComp
'>>>>>>Insert selected components into new folder If blnRet = True Then blnRet = False 'Insert feature tree folder Set swMyFeat = swMyModel.FeatureManager.InsertFeatureTreeFolder2(swFeatureTreeFolder_Containing) 'ReName swMyModel.SelectedFeatureProperties 0, 0, 0, 0, 0, 0, 0, 1, 0, strCurClass 'Deselect Component swMyModel.ClearSelection2 True swMyFtrMngr.UpdateFeatureTree Set swMyFeat = Nothing End If