Parallel planes programatically

Top  Previous  Next

The software way of doing this...

 

 

parallel-planes

 

 

...is illustrated below:

 

 

/*

Given two occurrences which contain workplanes to be flush constrained together

this function creates a flush constraint between them

*/

bool AddFlushConstraintOfTwoPlanes (CComPtr<AssemblyComponentDefinition>& pAsmCompDef,

                                    CComPtr<ComponentOccurrence>& pOccA,

                                    CComPtr<WorkPlane>& pWorkPlaneA,

                                    CComPtr<ComponentOccurrence>& pOccB,

                                    CComPtr<WorkPlane>& pWorkPlaneB,

                                    const double kOffsetMm, /*=0.0*/

                                    const wchar_t* const pszConstraintName /*=nullptr*/,

                                    const double kmmMax /*= 0.0*/)

{

    CComPtr<WorkPlaneProxy> pWPProxyA ;

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

    if (FAILED(hRes)) {

        ShowCOMError (hRes,L"AFCOTP could not get pWPProxyA.") ;

        return false ;

    }

 

    CComPtr<WorkPlaneProxy> pWPProxyB ;

    pOccB->CreateGeometryProxy (pWorkPlaneB,(IDispatch**)&pWPProxyB) ;

    if (FAILED(hRes)) {

        ShowCOMError (hRes,L"AFCOTP could not get pWPProxyB.") ;

        return false ;

    }

 

    // Get the list of constraints of the assembly so you can add a new one

    CComPtr<AssemblyConstraints> pConstraintList ;

    hRes = pAsmCompDef->get_Constraints(&pConstraintList) ;

    if (FAILED(hRes)) {

        ShowCOMError (hRes,L"AFCOTP could not get constraints.") ;

        return false ;

    }

 

    CComVariant varOffset(kOffsetMm/10.0); // Convert to offset in cm

    CComPtr<FlushConstraint> pFlushConstraint ;   

    hRes = pConstraintList->AddFlushConstraint(pWPProxyA, pWPProxyB, varOffset,

                                               gkvarEmpty, gkvarEmpty,

                                               &pFlushConstraint);

    if (FAILED(hRes)) {

        ShowCOMError (hRes,L"AFCOTP AddFlushConstraint failed") ;

        return false ;

    }

 

    if (kmmMax > 0.0) {

        // This allows planes to be parallel constrained, but distant from each other

        const double kcmMax = kmmMax/10.0 ;

        CComPtr<ConstraintLimits> pLimits =  pFlushConstraint->GetConstraintLimits() ;

        pLimits->MaximumEnabled = VARIANT_TRUE ;

        CString csMax ;

        csMax.Format (L"%.3f",kcmMax) ;

        CComBSTR TempBstr (csMax) ;

        pLimits->Maximum->Expression = TempBstr.m_str ; //!!!OWEN!!! .Value in cm is also possible

    }

 

 

    if ((pszConstraintName != nullptr) && (wcslen(pszConstraintName) > 0)) {

        const CString kcsConsName = GetFreeConstraintName(pszConstraintName,pAsmCompDef);

        CComBSTR bstrName(kcsConsName);

        pFlushConstraint->put_Name(bstrName);

    }

 

    return true ;

}

 

Enter topic text here.

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