API Help please? - Wierd behavior - InsertFeatureTreeFolder2

Discussion in 'SolidWorks' started by What-a-Tool, Jul 27, 2005.

  1. What-a-Tool

    What-a-Tool Guest

    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
     
    What-a-Tool, Jul 27, 2005
    #1
  2. What-a-Tool

    TOP Guest

    Just a thought. When SW puts a folder in the feature tree it is really
    inserting two markers, one for the beginning and one for the end. When
    there would be unselected items between the two markers SW probably
    doesn't know how to handle it so it just puts the end marker after the
    first contiguous selection. SW could reorder the features but this
    would also have to apply to parts and in a part, reordering could have
    unforseen consequences.

    Let's call this a hunch, but I'll bet it isn't far off.
     
    TOP, Jul 27, 2005
    #2
  3. What-a-Tool

    What-a-Tool Guest

    Thanks - took another look at the API today with a fresh mind and noticed
    that it says right down the bottom of the page (where I didn't bother
    scrolling yesterday) that this method will only work on consecutive
    components. (I can be a shithead sometimes)

    Solved this problem by sorting and grouping my array of components before
    inserting them into the assembly - they show up in the feature tree in the
    same order as they appear in the array.

    vcomponents = Part.AddComponents((compNames), (compXforms))
     
    What-a-Tool, Jul 28, 2005
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.