4 Replies Latest reply on Aug 5, 2013 9:15 AM by Simon Turner

    How to create a triangle surface with API?

    Wenjie Huang

      Hi,

       

      I am programming on unmanaged c++. I need to create a set of triangle surfaces and create a solid body using these surfaces.

       

      Here is how I do:

        • Re: How to create a triangle surface with API?
          Wenjie Huang

          #include "stdafx.h"

          #import "sldworks.tlb"

          #import "swconst.tlb"

           

          int _tmain(int argc, _TCHAR* argv[])

          {

            CoInitialize(NULL); 

            CComPtr<SldWorks::ISldWorks> swApp;

            CComPtr<SldWorks::IModelDoc2> swModel;

            CComPtr<SldWorks::IPartDoc> swPart;

            CComPtr<SldWorks::IBody2> swBody;

            CComPtr<SldWorks::IBody2> swTempBody;

           

            HRESULT hres = swApp.CoCreateInstance(__uuidof(SldWorks::SldWorks), NULL, CLSCTX_LOCAL_SERVER);

            swApp->Visible = TRUE;

            _bstr_t partTemplate = swApp->GetDocumentTemplate(SwConst::swDocPART,"\0",0,0,0);

            swModel = swApp->INewDocument2(partTemplate,SwConst::swDwgPaperA4size,0,0);

            swPart = swModel;

            swBody = swPart->ICreateNewBody2();

           

            long n  = 3; //number of points

           

            double tri[] = {0, 0, 1, -1, -1, 0, 1, -1, 0};

            double normal[] = {0, -2, -2};

            double* triPoints = (double*)calloc(9, sizeof(double));

            double* norPoints = (double*)calloc(3, sizeof(double));

           

            for(int i=0; i<9; i++)

              triPoints[i] = tri[i];

            for(int i=0; i<3; i++)

              norPoints[i] = normal[i];

           

            HRESULT surface = swBody->ICreatePlanarTrimSurfaceDLL(n,triPoints, norPoints);  //ß------------Problem, always return S_FALSE

            swTempBody = swBody->ICreateTempBodyFromSurfaces(); //ß------------Problem, always return null pointer

            if(swTempBody)

            {

              swTempBody->Display3(swPart, 0, SwConst::swTempBodySelectable);

              printf("num of face: %d", swTempBody->GetFaceCount()); 

            }

            else

              printf("fail");

           

            swApp->ExitApp();

            swBody = NULL;

            swPart = NULL;

            swModel = NULL;

            swApp = NULL;

           

            free(triPoints); free(norPoints);

           

            CoUninitialize();

                 return 0;

          }

           

           

          But it didn't work. Any idea?