SE API with C++/Occurences-Add part/Move Part/Add 3D Relationships

Valued Contributor
Valued Contributor

 

    SolidEdgeFramework::ApplicationPtr pSEApp;

    SolidEdgeFramework:Smiley Very HappyocumentsPtr pDocs;

    SolidEdgeAssembly::AssemblyDocumentPtr pAsmDoc;

    SolidEdgeAssembly:Smiley SurprisedccurrencesPtr pOccurs;

    SolidEdgeAssembly:Smiley SurprisedccurrencePtr pOccur;

    SolidEdgeAssembly:Smiley SurprisedccurrencePtr pOccur1;

    SolidEdgeAssembly:Smiley SurprisedccurrencePtr pOccur2;

    SolidEdgePart:Smiley TongueartDocumentPtr pPartDoc;

    SolidEdgePart::ModelsPtr pModels;

    SolidEdgePart::ModelPtr pModel;

    SolidEdgePart::RevolvedProtrusionsPtr pRevolvedProtrusions;

    SolidEdgePart::RevolvedProtrusionPtr pRevolvedProtrusion;

    SolidEdgePart::RevolvedCutoutsPtr pRevolveCutOuts;

    SolidEdgePart::RevolvedCutoutPtr pRevolveCut;

    SolidEdgeGeometry::FacesPtr pFaces;

    SolidEdgeGeometry::FacePtr pFace;

    SolidEdgeGeometry::FacePtr pScrewConicalFace;

    SolidEdgeGeometry::FacePtr pNutConicalFace;

    SolidEdgeFramework::ReferencePtr pRefToCylinderInScrew;

    SolidEdgeFramework::ReferencePtr pRefToConeInNut;

    SolidEdgeAssembly::Relations3dPtr pRelations3d;

    SolidEdgeAssembly::AngularRelation3dPtr pAngularRelation3d;

    SolidEdgeAssembly::AxialRelation3dPtr pAxialRelation3d;

    SolidEdgeAssembly::GroundRelation3dPtr pGroundRelation3d;

    SolidEdgeAssembly:Smiley TonguelanarRelation3dPtr pPlanarRelation3d;

    SolidEdgeAssembly:Smiley TongueointRelation3dPtr pPointRelation3d;

    SolidEdgeAssembly::AxialRelation3dPtr pRelNutToScrew;

 

    IDispatchPtr pDispatch;

    HRESULT hr;

    pSEApp.GetActiveObject("SolidEdge.Application");

    pDocs=pSEApp->GetDocuments();

    pDispatch=pDocs->Add("SolidEdge.AssemblyDocument",vtMissing);

    pDispatch->QueryInterface(&pAsmDoc);

    pOccurs=pAsmDoc->Occurrences;

 

    /*pOccur=pOccurs->AddByFilename("C:\\1.par",vtMissing);

 

    pOccur=pOccurs->AddByFilename("C:\\1.par",vtMissing);

    pOccur->Move(0,0,0.05);

 

    pOccur=pOccurs->AddByFilename("C:\\1.par",vtMissing);

    pOccur->Rotate(0,0,0,0,1,0,-3.1415926/2.0);

    pOccur->Move(-0.05,0,0.05);*/

 

    pOccur1=pOccurs->AddByFilename("C:\\screw.par",vtMissing);

    pDispatch=pOccur1->OccurrenceDocument;

    hr=pDispatch->QueryInterface(&pPartDoc);

    pModels=pPartDoc->Models;

    pModel=pModels->Item((long)1);

    pRevolvedProtrusions=pModel->RevolvedProtrusions;

    pRevolvedProtrusion=pRevolvedProtrusions->Item((long)1);

    pFaces=pRevolvedProtrusion->SideFaces;

    long count=pFaces->Count;

    for(long i=1;iCount;i++)

    {

        DISPID rgDispId = 0;

        OLECHAR *Names[]= {L"Type"};

        IDispatchPtr geometry;

        VARIANT varResult;

        VariantInit(&varResult);

        V_VT(&varResult) = VT_I4;

        DISPPARAMS disp = { NULL, NULL, 0, 0 };

        pDispatch=pFaces->Item(i);

 

        pDispatch->QueryInterface(&pFace);

 

        geometry=pFace->Geometry;

 

        hr = geometry->GetIDsOfNames(IID_NULL,

                                     Names,

                                     1,

                                     LOCALE_USER_DEFAULT,

                                     &rgDispId );

 

        hr = geometry->Invoke( rgDispId,

                                  IID_NULL,

                                  LOCALE_USER_DEFAULT,

                                  DISPATCH_PROPERTYGET,

                                  &disp,

                                  &varResult,

                                  NULL,

                                  NULL );

 

        SolidEdgeGeometry::GNTTypePropertyConstants typeProperty=(GNTTypePropertyConstants)varResult.lVal;

        if(typeProperty==SolidEdgeGeometry::GNTTypePropertyConstants::igCylinder)

        {   

            pScrewConicalFace=pFace;

            break;

        }

    }

    _variant_t tempFace(pScrewConicalFace,true);

 

    pDispatch=pAsmDoc->CreateReference(pOccur1,&tempFace.Detach());

 

    hr=pDispatch->QueryInterface(&pRefToCylinderInScrew);

 

    pOccur2=pOccurs->AddByFilename("C:\\Nut.par",vtMissing);

    pDispatch=pOccur2->OccurrenceDocument;

    pDispatch->QueryInterface(&pPartDoc);

    pModels=pPartDoc->Models;

    pModel=pModels->Item((long)1);

    pRevolveCutOuts=pModel->RevolvedCutouts;

    pRevolveCut=pRevolveCutOuts->Item((long)1);

    pFaces=pRevolveCut->SideFaces;

 

    for(long i=1;iCount;i++)

    {

        DISPID rgDispId = 0;

        OLECHAR *Names[]= {L"Type"};

        IDispatchPtr geometry;

        VARIANT varResult;

        DISPPARAMS disp = { NULL, NULL, 0, 0 };

 

        pDispatch=pFaces->Item(i);

 

        pDispatch->QueryInterface(&pFace);

 

        geometry=pFace->Geometry;

 

        hr = geometry->GetIDsOfNames(IID_NULL,

                                     Names,

                                     1,

                                     LOCALE_SYSTEM_DEFAULT,

                                     &rgDispId );

 

        hr = geometry->Invoke( rgDispId,

                                  IID_NULL,

                                  LOCALE_SYSTEM_DEFAULT,

                                  DISPATCH_PROPERTYGET,

                                  &disp,

                                  &varResult,

                                  NULL,

                                  NULL );

 

        GNTTypePropertyConstants typeProperty=(GNTTypePropertyConstants)varResult.lVal;

        if(typeProperty==GNTTypePropertyConstants::igCylinder)

        {pNutConicalFace=pFace;break;}

    }

    _variant_t tempRefFace(pNutConicalFace,true);

    pDispatch=pAsmDoc->CreateReference(pOccur2,&tempRefFace.Detach());

    hr=pDispatch->QueryInterface(&pRefToConeInNut);

 

    pRelations3d=pAsmDoc->Relations3d;

    pDispatch=pRelations3d->Item((long)2);

    hr=pDispatch->QueryInterface(&pGroundRelation3d);

    pGroundRelation3d->Delete();

 

    pRelNutToScrew=pRelations3d->AddAxial(pRefToConeInNut,pRefToCylinderInScrew,VARIANT_FALSE);

 

 

Posted by: assassin 007
Post date: 5/16/2010 7:48:33 PM