Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
oransen
379 Views, 4 Replies

Changing an assembly fixed workplane name does not show up in 3D

I've written some code to add fixed workplanes in an assembly, offset from one of the std workplanes of that assembly.

 

At the end of the function I change the name of the workplane, I can see the name change in the browser, but not in the 3D View. And when I get the name in the code just to check I correctly get the newly changed name.

 

oransen_0-1624723153990.png

 

Is this a bug or am I doing something wrong? Here is the code:

 

bool AddFixedWorkPlaneInAsm (CComPtr<AssemblyComponentDefinition>& pAsmCompDef,  // where the plane will be added
                             const int ikPlaneIdx, // Which of the standard planes to base the new one on
                             const double kOffsetMm, // Offset,
                             const wchar_t* const pszPlaneName)    // Name of the newly created plane
{
    gLogger.Printf (ekLogMsg,L"AFWPIA %d <%s> starting",ikPlaneIdx,pszPlaneName) ;
    // Get WorkPlanes
    CComPtr<WorkPlanes> pWorkPlanes ;
    HRESULT hRes = pAsmCompDef->get_WorkPlanes(&pWorkPlanes);
    if (FAILED(hRes)) {
        ShowCOMError (hRes,L"AFWPIA, get_WorkPlanes failed") ;
        return false ;
    }

    // Get hold of one of the WorkPlanes. Valid indices are 1 2 3 for standard workplanes
    CComPtr<WorkPlane> pAsmStdWorkPlane ;
    hRes = pWorkPlanes->get_Item(CComVariant(ikPlaneIdx),&pAsmStdWorkPlane);
    if (FAILED(hRes) || (pAsmStdWorkPlane==nullptr)) {
        ShowCOMError (hRes,L"AFWPIA, get_Item (workplane %d) failed",ikPlaneIdx) ;
        return false ;
    }

    // Get the standard plane to use as a base for the offset plane
    PlanePtr ThePlane = pAsmStdWorkPlane->GetPlane() ;
    PointPtr StdPlaneOrigin = ThePlane->RootPoint ;

    CComPtr<TransientGeometry> pTransGeo = GetTransGeomPtr () ;    

    // Internally Inventor always uses cm, so convert...
    const double kOffsetInCm = kOffsetMm/10.0 ;

    CComPtr<Point> pOrigin ;
    hRes = pTransGeom->CreatePoint (StdPlaneOrigin->X,StdPlaneOrigin->Y,StdPlaneOrigin->Z,&pOrigin);
    if (FAILED(hRes) || (pOrigin == nullptr)) {
        ShowCOMError (hRes,L"AFWPIA, could not create origin point") ;
        return false ;
    }

    CComPtr<UnitVector> uVector;
    CComPtr<UnitVector> vVector;
    switch (ikPlaneIdx) {
        case gikXYPlaneIndex :
            pTransGeo->CreateUnitVector (1.0, 0.0, 0.0, &uVector) ;
            pTransGeo->CreateUnitVector (0.0, 1.0, 0.0, &vVector) ;
            pOrigin->PutZ (kOffsetInCm) ;
            break ;

        case gikXZPlaneIndex :
            pTransGeo->CreateUnitVector (1.0, 0.0, 0.0, &uVector) ;
            pTransGeo->CreateUnitVector (0.0, 0.0, 1.0, &vVector) ;
            pOrigin->PutY (kOffsetInCm) ;
            break ;

        case gikYZPlaneIndex :
            pTransGeo->CreateUnitVector (0.0, 1.0, 0.0, &uVector) ;
            pTransGeo->CreateUnitVector (0.0, 0.0, 1.0, &vVector) ;
            pOrigin->PutX (kOffsetInCm) ;
            break ;

        default :
            gLogger.Printf (ekErrMsg,L"AFWPIA unhandled index:%d", ikPlaneIdx) ;
            // Do something anyway...
            pTransGeo->CreateUnitVector (1.0, 0.0, 0.0, &uVector) ;
            pTransGeo->CreateUnitVector (0.0, 1.0, 0.0, &vVector) ;
            pOrigin->PutZ (kOffsetInCm) ;
            break ;
    }

    CComPtr<WorkPlane> pOffsetWorkPlane;
    hRes = pWorkPlanes->AddFixed(pOrigin,uVector,vVector, VARIANT_FALSE,&pOffsetWorkPlane);
    if (FAILED(hRes) || pOffsetWorkPlane == nullptr) { 
        ShowCOMError (hRes,L"AFWPIA, Could not AddFixed plane %d",ikPlaneIdx) ;
        return false ;
    }
    
    CComBSTR bstrName = CString (pszPlaneName) ;
    hRes = pOffsetWorkPlane->put_Name (bstrName) ;
    if (FAILED(hRes)) { 
        ShowCOMError (hRes,L"AFWPIA, Could not set plane name") ;
        return false ;
    }

    CComBSTR bstrNameTest ;
    pOffsetWorkPlane->get_Name (&bstrNameTest) ;

    gLogger.Printf (ekLogMsg,L"AFWPIA <%s> <%s> ending ok",pszPlaneName,(LPWSTR)bstrNameTest) ;

    return true ;
}

 

Follow pszPlaneName in the code above to see what I do...