I have a task to select a part/Subassembly that is in another assembly. For example Assembly3 Containing assembly2, and assembly2 contains assembly1 and assembly1 contains Part1.
Here are few methods that I have tried, please let me know if there is something wrong in implementing these methods and also any new methods that you know.
Things tried:
1: "Select" method, this method is called by IComponent2 object, comming from ImodeldocExtension, by doing GetCorresponding, that returns a Idispatch object and by doing Queryinterface for Icompenent2 obj to call select.
2:"select" method, this method is again called by Icomponent2 object, this time brought by Ifeaturebyname/featurebyname by giving the name of the part/subassemble that we need to select, and doing GetSpecificfeature , that give Idispatch object with which we queryinterface to get IComponent object to call Select.
3:"selectbyId2" method , but I am not sure if Iam passing the correct input parameters because there is partial selection taking place.
here is some sample code that explains above mothod.
Things went wrong
1: In method 1: GetCorresponding doesnot return a Idispatch Object that can give IComponent2 obj on queryInterfacing
CComQIPtr
CComPtr
HRESULT hr = iModext->GetCorresponding(parCompDisp, &newCompDisp); newCompDisp is Null
CComQIPtr
VARIANT_BOOL retx;
pNewComp->Select(VARIANT_FALSE, &retx);
2: In method 2: Ifeaturebyname/featurebyname donot return pCompFeature that is a IFeature object.
CComPtr
hr = pAssyDoc->IFeatureByName(bName, &pCompFeature); IF in topmost level, pCompFeature is NULL
CComPtr
hr = pAssyDoc->GetEditTargetComponent(&parComp);
hr = parComp->FeatureByName(bName, &pCompFeature); If not in toplevel or is in subassembly , pCompFeature is NULL
if(FAILED(hr) || !pCompFeature)
return EditorError;
CComPtr
hr = pCompFeature->GetSpecificFeature2(&pCompDispFromFeature);
CComQIPtr
VARIANT_BOOL retx;
hr = pCompReal->Select(VARIANT_FALSE, &retx);
3: in method 3: I have tried passing fisrt parameter as string i.e name of part "Part1" and the full string like "Part1-1@assembly1-1@assembly2-1@Assembly3" , also I have tried passing the typename as "COMPONENT" , "FEATURE" etc etc. still there is partial slection and not full selection that I need
SolidworksApi macros