SolidEdge ST: How to write functions that work for Sync and Classic Assemblies

 

HI,

 

now with SolidEdgeAssembly and SolidEdgeAssemblySync

 

i must write two functions that change only for the type!!

 

void SolidEdge::GetPhysicalProperties (SolidEdgeAssembly::AssemblyDocumentPtr pModel,MassProperties *massProps)

void SolidEdge::GetPhysicalProperties (SolidEdgeAssemblySync::AssemblyDocumentPtr pModel,MassProperties *massProps)

 

This will double the code and effort for any SolidEdge application

that use Solidedge with both classic and sync data.

 

There must be a way to create a single function that work for both type.

 

I tried with template, but with no success.

 

Can you give me an example of how to do that?

Thanks in advance.

Best Regards

Massimo

---------------------------------------------------------------

 

void SolidEdge::GetPhysicalProperties (SolidEdgeDocumentPtr pModel,MassProperties *massProps)

{

    PhysicalProperties *pPhysicalProperties ;

    CoordinateSystemPtr pCoordSys ;

    HRESULT hr ;

 

 

 

    if (pModel != NULL) {

...

..

 

 

 

void SolidEdge::GetPhysicalProperties (AssemblyDocumentPtr pModel,MassProperties *massProps)

{

    PhysicalProperties *pPhysicalProperties ;

    CoordinateSystemPtr pCoordSys ;

    HRESULT hr ;

 

    if (pModel != NULL) {

        pPhysicalProperties = pModel->PhysicalProperties ;

        pCoordSys =    pModel->CoordinateSystems->Add(0, 0, 0, 0, 0, 0, 0) ;

        if (pPhysicalProperties != NULL)

        {

            pPhysicalProperties->Update () ;

            //pPhysicalProperties->WriteToFile ("e:\\solidedge\\at.txt") ;

 

            try {

                //hr = pPhysicalProperties->GetAsmPhysicalPropsRelativeToCoordSystem (pCoordSys, &massProps->Mass, &massProps->Volume, &massProps->Area, &massProps->CenterOfMass, &massProps->CenterOfVolume, &massProps->GlobalMoments, &massProps->PrincipalAxis1, &massProps->PrincipalAxis2, &massProps->PrincipalAxis3, &massProps->PrincipalMoments, &massProps->RadiiOfGyration, &massProps->IsSick, &massProps->UpdateStatus) ;

                hr = pPhysicalProperties->GetAssemblyPhysicalProperties ( \

                &massProps->Mass, \

                &massProps->Volume, \

                &massProps->Area, \

                &massProps->CenterOfMass, \

                &massProps->CenterOfVolume, \

                &massProps->GlobalMoments, \

                &massProps->PrincipalAxis1, \

                &massProps->PrincipalAxis2, \

                &massProps->PrincipalAxis3, \

                &massProps->PrincipalMoments, \

                &massProps->RadiiOfGyration, \

                &massProps->IsSick, \

                &massProps->UpdateStatus) ;

 

            } //catch (...)

                catch( _com_error e )

            {

                hr = E_FAIL ;

                ;

            }

        }

    } else

    {

        hr = E_FAIL ;

    }

}

 

Posted by: Massimo Magris
Post date: 2/23/2009 11:36:53 PM

1 REPLY

RE: SolidEdge ST: How to write functions that work for Sync and Classic Assemblies

 

Massimo,

 

While it's certaily possible to use late binding via IDispatch, GetIdOfNames() & InvokeMember(), I don't think this will be the best long term solution. My worry is that, yes, the SolidEdgeAssembly::AssemblyDocumentPtr and SolidEdgeAssemblySync::AssemblyDocumentPtr have similar methods and parameters now, but they may branch and vary in the future and break your code. Yes, it puts more work on us but I think you're going to be much better off handling each document type in it's own function. That's just my opinion.

 

Posted by: Jason Newell
Post date: 2/24/2009 6:28:25 AM