0 Replies Latest reply on Aug 21, 2014 10:01 AM by Wasim Ahmed

    Change component reference not working

    Wasim Ahmed

      In an assembly, I have used this code for changing component reference............

      HRESULT SetConFig(IModelDoc2 *p_moddoc, IModelDocExtension *p_modextn, CComBSTR &Name, CComBSTR &type, CComBSTR &Config)

      {

        // Function Sets the Configuration of the component

        //Parameters : ModelDoc, Extension , Name of component, type of component, Configuration to set

        //Discription: Sets the config

        ASSERT(p_moddoc && p_modextn);

        if (!p_moddoc|| !p_modextn)

        return E_FAIL;

       

        VARIANT_BOOL Status;

        HRESULT hr = p_modextn ->SelectByID2(Name, type, 0.0, 0.0, 0.0 ,VARIANT_FALSE, 0, NULL, 0, &Status);

        if(FAILED(hr)) return hr;

       

       

        CComPtr<ISelectionMgr> ip_SelMgr;

        hr = p_moddoc->get_ISelectionManager(&ip_SelMgr);

        if (FAILED(hr)||!ip_SelMgr) return E_FAIL;

       

       

        long l_Ind=1,l_Mk=-1;

        CComPtr<IDispatch> ip_Sel_obj;

        hr = ip_SelMgr->GetSelectedObject6(l_Ind,l_Mk,&ip_Sel_obj);

        ASSERT(ip_Sel_obj);

        if (FAILED(hr) || !ip_Sel_obj) return E_FAIL;

       

       

        CComPtr<IComponent2> Sel_Comp;

        hr = ip_Sel_obj->QueryInterface(&Sel_Comp);

        if (FAILED(hr) || !Sel_Comp) return E_FAIL;

       

       

        CComBSTR bst_CompConfig;

        hr = Sel_Comp->get_ReferencedConfiguration(&bst_CompConfig);

        if (FAILED(hr)) return E_FAIL;

       

       

        hr = Sel_Comp->put_ReferencedConfiguration(Config);

        if (FAILED(hr)) return E_FAIL;

       

       

        VARIANT_BOOL b_Stat;

        hr = p_moddoc->EditRebuild3(&b_Stat);

        if (FAILED(hr)) return E_FAIL;

       

        return S_OK;

      }

       

      It works for a few components and fails for some, when it fails i have to replace the component and then it works....Plz help