Hide Table of Contents

Get Names of Creators of Features Example (C++ COM)

This example shows how to get the names of the creators of the features in multiple part documents.




   * SOLIDWORKS is open and the specified input file exists in this folder:


   * The SOLIDWORKS part documents listed in the input file and used by

     this application were installed when SOLIDWORKS was installed:

     - c:\Program Files\SOLIDWORKS\samples\tutorial\toolbox\braceleft.sldprt

     - c:\Program Files\SOLIDWORKS\samples\tutorial\toolbox\braceright.sldprt

     - c:\Program Files\SOLIDWORKS\samples\tutorial\toolbox\baseplate.sldprt



   * The specified output file is created in the specified folder:


   * The names of the SOLIDWORKS part documents and their features

     and the names of the creators of those features.


#include "stdafx.h"

#include <fstream> //Stream class to both read from and write to files

#include <string>


CComBSTR makeBstr(string input);//makeBstr function prototype


using namespace std;


int _tmain()


ifstream infile;

ofstream outfile;


//Iniitalize COM



//Use ATL smart pointers

CComPtr<ISldWorks> swApp;

CComPtr<IModelDoc2> swModel;

CComPtr<IFeature> swFeat;

CComPtr<IFeature> swNextFeat;


long lErrors;

long lWarnings;


string sSOLIDWORKSFilename;


CComBSTR sDefaultConfiguration(L"Default");

CComBSTR sFeatureName(L"");

CComBSTR sFeatureCreator(L"");




//Open input file

infile.open("C:\\SOLIDWORKSFilenames.txt", std::ios_base::in);

//Make sure input file exists



cout << "ERROR: Cannot open the input file." << endl;

return 1;



//Open output file

outfile.open("c:\\SOLIDWORKSFilenamesFeatureCreators.txt", std::ios_base::out );

//Make sure output file exists

if( !outfile)  


cout << "ERROR: Cannot open the output file." << endl;


return 1;



outfile << "=============================================================================" << endl;


//Connect to currently running instance of SOLIDWORKS

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


//Check results

if (S_OK != hres)

return 1;


while (!infile.eof())


//Read SOLIDWORKS part document name from SOLIDWORKSFilenames.txt

getline (infile, sSOLIDWORKSFilename);


//Convert string to CComBSTR by calling function makeBstr

CComBSTR sSWFilename = (makeBstr(sSOLIDWORKSFilename));


cout << sSOLIDWORKSFilename << endl;


//Open part document

hres = swApp->OpenDoc6(sSWFilename, swDocPART, swOpenDocOptions_Silent, sDefaultConfiguration, &lErrors, &lWarnings, &swModel);


//Check results

if (S_OK != hres || swModel == NULL)

return 1;


//Write name of SOLIDWORKS part document in SOLIDWORKSFilenamesFeatureCreators.txt

outfile << sSOLIDWORKSFilename << endl;

outfile << "=============================================================================" << endl;


//Get first feature



//Iterate over features in this part document in the FeatureManager design tree



//Get feature name



//Get creator of feature



//Convert feature name and creator of feature to

//string and write to output file

 CW2CT sFeatureNameString(sFeatureName);

 CW2CT sFeatureCreatorString(sFeatureCreator);


 string sFNS = _bstr_t(sFeatureNameString);

 string sFCS = _bstr_t(sFeatureCreatorString);

 outfile << "Feature " << sFNS << " created by " << sFCS << endl;

//Get next feature in this part document




swFeat = swNextFeat;




outfile << "=============================================================================" << endl;


//Close the part document







//Close input and output files






//Uninitialize COM



return 0;



//Function to convert string to CComBSTR

CComBSTR makeBstr(string input)


char* CStyleString = (char*) input.c_str();

CComBSTR retval(CStyleString);

return retval;



Back to top


/// stdafx.h : include file for standard system include files,

// or project-specific include files that are used frequently, but

// are changed infrequently



#pragma once


#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers

#include <stdio.h>

#include <tchar.h>

#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit


#include <windows.h>

#include <atlbase.h>

#include <iostream>


using namespace std;  //We will use the standard C++ libraries for text output.


#import "sldworks.tlb" raw_interfaces_only, raw_native_types, no_namespace, named_guids  //the SOLIDWORKS type library

#import "swconst.tlb"  raw_interfaces_only, raw_native_types, no_namespace, named_guids  //the SOLIDWORKS constant type library

Back to top


// stdafx.cpp : source file that includes just the standard includes

// FeatureCreatedBy.pch will be the pre-compiled header

// stdafx.obj will contain the pre-compiled type information

#include "stdafx.h"

Back to top

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

Subject:   Feedback on Help Topics
Page:   Get Names of Creators of Features Example (C++ COM)
*   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:


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

Web Help Content Version: API Help (English only) 2016 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.