> Create Cylinder Example (C++ COM)
Welcome
Getting Started
SolidWorks API Help
FeatureWorks API Help
SolidWorks Document Manager API Help
eDrawings API Help
SolidWorks Routing API Help
SolidWorks Simulation API Help
SolidWorks Utilities API Help
SolidWorks Workgroup PDM API Help
Hide Table of Contents Show 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;

}



Related SolidWorks Forum Content

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:  
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) 2012 SP05

The search functionality within the web help is in a beta test phase and you may experience periodic delays or interruptions in its performance. These are the normal and ordinary features of a beta test and shall not under any circumstances give rise to any liability on the part of DS SolidWorks or its licensors. The topics within the Web-based help are not beta topics; they document API Help (English only) 2012 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.