Hide Table of Contents

FeatureTraversal.cpp Written in C++

// FeatureTraversal.cpp : Defines the entry point for the console application

// Traverses the FeatureManager design tree

 

#include "stdafx.h"

 

// Add the path to the SolidWorks type libraries to the "Additional Include Directories".

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

#import "swconst.tlb" raw_interfaces_only, raw_native_types, no_namespace, named_guids   // SolidWorks constants type library

 

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

{

// Initialize COM

// Do this before using ATL smart pointers so COM is available.

CoInitialize(NULL);

 

// Use a block, so the smart pointers are destructed when the scope of this block is left

{

// Use ATL smart pointers

CComPtr<ISldWorks>   swApp;

 

if(swApp.CoCreateInstance(__uuidof(SldWorks), NULL, CLSCTX_LOCAL_SERVER) != S_OK) {

return(0);             

}

 

swApp->put_UserControl(VARIANT_TRUE);

swApp->put_Visible(VARIANT_TRUE);

 

CComPtr<IModelDoc2>  swModel;

 

swApp->get_IActiveDoc2(&swModel);

 

if (! swModel) {

return(0);

}

 

CComBSTR  strModelTitle;

long      nDocumentType;  // swDocumentTypes_e

 

swModel->GetTitle(&strModelTitle);

swModel->GetType(&nDocumentType);

 

CComPtr<IFeature>  swFeature;

CComPtr<IFeature>  swSubFeature;

CComBSTR           strFeatureName;

CComBSTR           strFeatureType;

 

swModel->IFirstFeature(&swFeature);

 

while (swFeature) {

swFeature->get_Name(&strFeatureName);

swFeature->GetTypeName2(&strFeatureType);

 

swFeature->IGetFirstSubFeature(&swSubFeature);

 

while (swSubFeature) {

swSubFeature->get_Name(&strFeatureName);

swSubFeature->GetTypeName2(&strFeatureType);

 

CComPtr<IFeature>  swNextSubFeature;

 

swSubFeature->IGetNextSubFeature(&swNextSubFeature);

 

swSubFeature = swNextSubFeature;

}

 

CComPtr<IFeature>  swNextFeature;

 

swFeature->IGetNextFeature(&swNextFeature);

 

swFeature = swNextFeature;

}

 

}

// ATL smart pointers are destructed so all COM objects you held on to are released

// Now you can safely shutdown COM as you do not need it any longer

 

// Stop COM

CoUninitialize();

 

return(0);

}



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:   FeatureTraversalC++
*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) 2013 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.