question~ SolidWorks 2005 API: using IGetChildren

Discussion in 'SolidWorks' started by yung, Jun 6, 2006.

  1. yung

    yung Guest

    I have a question about using IGetChildren in SolidWorks 2005 API in
    Visual C++ 6.0

    Suppose I have an Assembly file containing 3 part files.
    I would like to use the IGetChildren function to get the name of each
    part (component) one by one, using the code below.
    But after IGetChildren is called, in the pChildren array, only the
    first element gets the first part. The remaining elements could
    retrieve nothing.

    Would someone figure out why IGetChildren() cannot get all the children
    (parts) in this case?
    Many many thanks!





    IComponent2** pChildren = NULL;
    CComQIPtr<IModelDoc2> pModel;
    CComQIPtr<IConfiguration> pConfiguration;
    int nChildren, i;
    if (pModel->IGetActiveConfiguration(&pConfiguration) == S_OK )
    {
    if ( pConfiguration->IGetRootComponent2(&pRootComponent) == S_OK )
    {

    HRESULT hres = pComponent->IGetChildrenCount(&nChildren);
    if ( S_OK == hres && nChildren > 0 )
    {
    pChildren = new IComponent2* [nChildren];
    hres = pComponent->IGetChildren(pChildren);
    if (S_OK == hres)
    {
    for ( i=0; i<nChildren; i++ )
    {
    // code to do tasks like getting name, ...

    // but now only OK for the first element!
    }
    }
    }
    }
    }
     
    yung, Jun 6, 2006
    #1
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.