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

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

oransen
Collaborator Collaborator
474 Views
4 Replies
Message 1 of 5

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

oransen
Collaborator
Collaborator

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...

 

0 Likes
475 Views
4 Replies
Replies (4)
Message 2 of 5

JelteDeJong
Mentor
Mentor

im no good with c++ (i guess that this is c++) and i can reproduce the problem, but often when i run in this kind of problems a update helps. In iLogic it would look like this:

Dim doc As Document = ThisDoc.Document
doc.Update2()

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 5

oransen
Collaborator
Collaborator

@JelteDeJong,  the update icon is not showing and even if I save and reopen the file it remains with two different names...

 

 

0 Likes
Message 4 of 5

oransen
Collaborator
Collaborator

@JelteDeJong, I tried the Update, but no change.  😞

0 Likes
Message 5 of 5

oransen
Collaborator
Collaborator

Is this a bug in Inventor?

0 Likes