Hide Table of Contents

Get Contents of FeatureFolder Example (C#)

This example shows how to obtain the contents of feature folders.

//-----------------------------------------------------------------------------
// Preconditions:
// 1. Open a part document.
// 2. Right-click a feature in the FeatureManager design tree.
// 3. Select Add to New Folder.
//    (The feature is moved to the new folder.)
// 4. Rename the namespace of this macro to match the name of your C# project.
// 5. Open an Immediate Window.
// 6. Run this macro.
//
// Postconditions: Inspect the Immediate Window.
//------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System;
using System.Diagnostics;
namespace FeatureFolder_CSharp.csproj
{
    
partial class SolidWorksMacro
    {

        
public void Main()
        {

            
ModelDoc2 swModel = default(ModelDoc2);
            
FeatureManager swFeatMgr = default(FeatureManager);
            
Feature swFeat = default(Feature);
            
IFeatureFolder swFeatFolder = default(IFeatureFolder);
            
Feature swFtrFolder = default(Feature);
            
string FeatType = null;
            
string FeatTypeName = null;

            
object[] Features = null;
            
int i = 0;

            
Feature[] featureArr = new Feature[3];

            swModel = (
ModelDoc2)swApp.ActiveDoc;
            swFeatMgr = swModel.FeatureManager;

            swFeat = (
Feature)swModel.FirstFeature();
            
while ((swFeat != null))
            {
                FeatType = swFeat.Name;
                FeatTypeName = swFeat.GetTypeName2();
              
                
if ((FeatTypeName == "FtrFolder" & !FeatType.Contains("EndTag")))
                {
                    
Debug.Print(FeatType + " [" + FeatTypeName + "]");
                    swFeatFolder = (
IFeatureFolder)swFeat.GetSpecificFeature2();
                    Features = (
object[])swFeatFolder.GetFeatures();
                    
Debug.Print(" Number of Features: " + swFeatFolder.GetFeatureCount());
                    
for (i = 0; i <= (swFeatFolder.GetFeatureCount() - 1); i++)
                    {
                        swFtrFolder = (
Feature)Features[i];
                        
Debug.Print(" Name of feature: " + swFtrFolder.Name);
                        
Debug.Print(" Type of feature: " + swFtrFolder.GetTypeName2());
                    }
                }
                swFeat = (
Feature)swFeat.GetNextFeature();

            }
        }
        
public SldWorks swApp;
    }
}



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:   Get Contents of FeatureFolder Example (C#)
*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) 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.