Hide Table of Contents

Get Configuration Information Example (C#)

This example shows how to use the SOLIDWORKS Document Manager API to get configuration-related information for an external part document whose custom properties were transferred from the original part document.

//--------------------------------------------------------------------------
// Preconditions: 
// 1. Read the SOLIDWORKS Document Manager API Getting Started topic 
//    and ensure that the required DLLs have been registered. 
// 2. Copy and paste this class into a C# console application in Microsoft 
//    Visual Studio. 
// 3. Add the Solidworks.Interop.swdocumentmgr.dll and Microsoft.CSharp references
//    to the project: 
//    a. Right-click the solution in Solution Explorer. 
//    b. Click Add Reference
//    c. Click Browse
//    d. Click install_dir\api\redist\CLR2\Solidworks.Interop.swdocumentmgr.dll.
//    e. Click Add.
//    f. Click Microsoft.CSharp
//    g. Click Add.
//    h. Click OK.

// 4. In the code, substitute your_license_key with your SOLIDWORKS 
//    Document Manager license key. 
// 5. Press F5 to run the program. 
// 
// Postconditions: 
// 1. Examine the Immediate Window.
// 2. Verify that both fromparent+ prefaced and non-prefaced custom property
//    values are shown.
//--------------------------------------------------------------------------
 
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using SolidWorks.Interop.swdocumentmgr; 
 
 
    class Program
    {
    
    public static void ProcessDocCustomProperties(SwDMDocument17 swDoc) 
    { 
        
        string[] vCustPropNameArr = null
        string sCustPropStr = null
        SwDmCustomInfoType nPropType = 0; 
        
        vCustPropNameArr = (string[])swDoc.GetCustomPropertyNames(); 
        if ((vCustPropNameArr == null)) return
 
        Debug.Print(" Document Custom Properties:");
 
        foreach (string vCustPropName in vCustPropNameArr)
        { 
            sCustPropStr = swDoc.GetCustomProperty(vCustPropName, out nPropType);    
            Debug.Print("   Prefaced      = " + vCustPropName + " <" + nPropType + "> = " + sCustPropStr);
 
            sCustPropStr = swDoc.GetCustomProperty2(vCustPropName, out nPropType);
            Debug.Print("   Not prefaced  = " + vCustPropName + " <" + nPropType + "> = " + sCustPropStr);
 
            Debug.Print("");
        } 
           
        Debug.Print(""); 
    } 
    
    
    public static void ProcessConfigCustomProperties(SwDMConfiguration14 swCfg) 
    { 
        string[] vCustPropNameArr = null
        string sCustPropStr = null
        SwDmCustomInfoType nPropType = 0; 
         
        vCustPropNameArr = (string[])swCfg.GetCustomPropertyNames(); 
        
        if ((vCustPropNameArr == null)) return
        Debug.Print(" Configuration Custom Properties:");
 
        foreach (string vCustPropName in vCustPropNameArr)
        { 
            sCustPropStr = swCfg.GetCustomProperty(vCustPropName, out nPropType); 
            Debug.Print("   Prefaced     = " + vCustPropName + " <" + nPropType + "> = " + sCustPropStr);
 
            sCustPropStr = swCfg.GetCustomProperty2(vCustPropName, out nPropType);
            Debug.Print("   Not prefaced = " + vCustPropName + " <" + nPropType + "> = " + sCustPropStr);
 
            Debug.Print("");
        } 
        
        Debug.Print(""); 
    }
 
 
    static void Main(string[] args)
    { 
 
        const string sLicenseKey = "your_license_key"
        //Specify license key 
        
        const string sDocFileName = "C:\\Program Files\\SOLIDWORKS Corp\\SOLIDWORKS\\samples\\tutorial\\api\\ExternalReferencedPart.sldprt"
        //Specify document 
        
        SwDMClassFactory swClassFact = default(SwDMClassFactory); 
        SwDMApplication swDocMgr = default(SwDMApplication); 
        SwDMDocument17 swDoc = default(SwDMDocument17); 
        SwDMConfigurationMgr swCfgMgr = default(SwDMConfigurationMgr); 
        string[] vCfgNameArr = null
        SwDMConfiguration14 swCfg = default(SwDMConfiguration14); 
        SwDmDocumentType nDocType = 0; 
        SwDmDocumentOpenError nRetVal = 0; 
        
        // Determine type of SOLIDWORKS file based on file extension 
        
        if (sDocFileName.EndsWith("sldprt")) { 
            nDocType = SwDmDocumentType.swDmDocumentPart; 
        } 
        else if (sDocFileName.EndsWith("sldasm")) {   
            nDocType = SwDmDocumentType.swDmDocumentAssembly; 
        } 
        else if (sDocFileName.EndsWith("slddrw")) {  
            nDocType = SwDmDocumentType.swDmDocumentDrawing; 
        } 
        else { 
            
            // Not a SOLIDWORKS file 
            nDocType = SwDmDocumentType.swDmDocumentUnknown; 
            
            // So cannot open 
            return
        } 
        
        // Because drawing documents do not have configurations, 
        // only continue running the project if the document 
        // is a part or assembly document 
        
        if ((nDocType != SwDmDocumentType.swDmDocumentDrawing)) { 
            
            swClassFact = new SwDMClassFactory(); 
            swDocMgr = swClassFact.GetApplication(sLicenseKey); 
            swDoc = (SwDMDocument17)swDocMgr.GetDocument(sDocFileName, nDocType, falseout nRetVal); 
            Debug.Assert(SwDmDocumentOpenError.swDmDocumentOpenErrorNone == nRetVal); 
            swCfgMgr = swDoc.ConfigurationManager
            
            Debug.Print("File = " + swDoc.FullName); 
            Debug.Print(" ActiveCfgName = " + swCfgMgr.GetActiveConfigurationName()); 
            Debug.Print(""); 
            Debug.Print(" Version = " + swDoc.GetVersion()); 
            Debug.Print(" Author = " + swDoc.Author); 
            Debug.Print(" Comments = " + swDoc.Comments); 
            Debug.Print(" CreationDate (string) = " + swDoc.CreationDate);
            Debug.Print(" CreationDate (numeric) = " + swDoc.CreationDate2);
 
            Debug.Print(" Keywords = " + swDoc.Keywords); 
            Debug.Print(" LastSavedBy = " + swDoc.LastSavedBy); 
            Debug.Print(" LastSavedDate (string) = " + swDoc.LastSavedDate);
            Debug.Print(" LastSavedDate (numeric) = " + swDoc.LastSavedDate2); 
            Debug.Print(" Subject = " + swDoc.Subject); 
            Debug.Print(" Title = " + swDoc.Title); 
            Debug.Print(" LastUpdateStamp = " + swDoc.GetLastUpdateStamp()); 
            Debug.Print(" IsDetachedDrawing = " + swDoc.IsDetachedDrawing()); 
            Debug.Print(""); 
         
            ProcessDocCustomProperties(swDoc); 
            vCfgNameArr = (string[])swCfgMgr.GetConfigurationNames(); 
            
            foreach (string vCfgName in vCfgNameArr) { 
                
                swCfg = (SwDMConfiguration14)swCfgMgr.GetConfigurationByName(vCfgName); 
                
                Debug.Print(" " + vCfgName); 
                Debug.Print(" Description = " + swCfg.Description); 
                Debug.Print(" ParentCfgName = " + swCfg.GetParentConfigurationName()); 
                Debug.Print(" LastUpdateStamp = " + swCfg.GetLastUpdateStamp()); 
                Debug.Print(""); 
                   
                ProcessConfigCustomProperties(swCfg); 
            } 
        }      
    }   

 
 



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 Configuration Information 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) 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.