Hide Table of Contents

Create Cylinder Example (C++ COM)

This example shows how to create a cylinder.

 

'------------------------------------

'

' Preconditions: None.

'

' Postconditions: A cylinder is created.

'

'------------------------------------

#include "stdafx.h"

#include "CreateCylinder.h"

 

#ifdef _DEBUG

#define new DEBUG_NEW

#undef THIS_FILE

static char THIS_FILE[] = __FILE__;

#endif

 

#include <atlbase.h>

 

#import "sldworks.tlb" no_namespace raw_interfaces_only

#import "swconst.tlb" no_namespace

 

/////////////////////////////////////////////////////////////////////////////

// The one and only application object

CWinApp theApp;

 

using namespace std;

 

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])

{

int nRetCode = 0;

// initialize MFC and print and error on failure

if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))

{

// TODO: change error code to suit your needs

cerr << _T("Fatal Error: MFC initialization failed") << endl;

nRetCode = 1;

}

else

{

::CoInitialize(NULL);

{

VARIANT_BOOL bRetval = VARIANT_FALSE;

 

CComPtr<ISldWorks> swApp;

swApp.CoCreateInstance(L"SldWorks.Application", NULL, CLSCTX_LOCAL_SERVER);

 

CComPtr<IModelDoc2> swDoc;

CComPtr<IModelDocExtension> swDocExt;

CComPtr<IFeatureManager> swFeatMgr;

 

swApp->get_IActiveDoc2(&swDoc);

swDoc->get_Extension(&swDocExt);

swDoc->get_FeatureManager(&swFeatMgr);

 

CComPtr<ISketch> swSketch;

swDoc->IGetActiveSketch2(&swSketch);

if (swSketch == NULL)

{

swDocExt->SelectByID2(L"Front Plane", L"PLANE", 0.0, 0.0, 0.0, VARIANT_FALSE, 0, NULL, swSelectOptionDefault, &bRetval);

swDoc->InsertSketch2(VARIANT_TRUE);

}

CComPtr<ISketchSegment> swSkSeg;

swDoc->ICreateCircle2(0.0, 0.0, 0.0, 0.025, 0.0, 0.0, &swSkSeg);

 

CComPtr<IFeature> swFeat;

swFeatMgr->FeatureExtrusion2(VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE,

0, 0, 0.100, 0.100,

VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, 0.0, 0.0,

VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE,

VARIANT_TRUE, VARIANT_FALSE, VARIANT_TRUE, 0, 0.0, VARIANT_FALSE, &swFeat);

}

::CoUninitialize();

}

return nRetCode;

}



Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Create Cylinder Example (C++ COM)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:

x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2015 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.