Top  Previous  Next

Here you go:


            CComPtr<WorkPoint> pTuboOrig ;

            GetPartWorkPointByIndex(pTuboOrig,1,pTubeCompDef) ;


            gLogger.Printf (ekLogMsg,L"TuboOrig è a %6.3f %6.3f %6.3f",pTuboOrig->Point->X,pTuboOrig->Point->Y,pTuboOrig->Point->Z) ;



            CComPtr<WorkPointProxy> pTuboOrigInIam ;

            hRes = pTuboOcc->CreateGeometryProxy(pTuboOrig, (IDispatch**)&pTuboOrigInIam) ;

            if (FAILED(hRes)) {

                gLogger.Printf (ekErrMsg,L"CCollettore::AIT origine tubo") ;

                return false ;




            gLogger.Printf (ekLogMsg,L"Tubo è a %6.3f %6.3f %6.3f",pTuboOrigInIam->Point->X,pTuboOrigInIam->Point->Y,pTuboOrigInIam->Point->Z) ;



You get the first workpoint in the part, which is always 0,0,0 in the part, and convert it to a proxy in the assembly workspace.






You will crash your program if you invert the order of the parameters, idiot.


Here is a function do do that:


// Returns the position (in cm) of a part occurence within an assembly

CVec GetPartPositionInIamCm(CComPtr<ComponentOccurrence>& pOcc, CComQIPtr<PartComponentDefinition>& pCompDef)


    CComPtr<WorkPoint> pOrigin ;

    GetPartWorkPointByIndex (pOrigin,1,pCompDef) ;

    CComPtr<WorkPointProxy> pOriginInAsm ;

    HRESULT hRes = pOcc->CreateGeometryProxy(pOrigin, (IDispatch**)&pOriginInAsm ) ;

    if (FAILED(hRes)) {

        gLogger.Printf (ekErrMsg,L"GPPIICproxy creation failed") ;

        return gkZeroVec ;



    CVec kvecOrigin (pOriginInAsm->Point->X,pOriginInAsm->Point->Y,pOriginInAsm->Point->Z) ;


    return kvecOrigin ;





CreateGeometryProxy may fail if the two inputs are not sensible. For example...


    CComPtr<WorkPlaneProxy> pWPProxyA ;

    HRESULT hRes = pOccB->CreateGeometryProxy (pWorkPlaneA,(IDispatch**)&pWPProxyA) ;


...if pWorkPlaneA is in one part and pOccB references a different part you'll get a 80004005 error in hRes.


See also this page.


Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)