Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

searching for a configuration specific custom properties in SolidWorks

Status
Not open for further replies.

josephv

Mechanical
Oct 1, 2002
683
0
0
CA
Good day everyone..

Is it possible to search for a configuration specific custom property in SolidWorks 2007?

We did some tests using SolidWorks Explorer 2007 to search for a configuration specific custom property, but it did not work. It was able to search for "regular" custom properties, but not configuration specific custom properties. Is this is a limitation?

If this is a limitation, has anyone found a work around ? For example a possible work around would be to be able to search inside a Design table for the Configuration Specific Custom Property (e.g. $prp@description).

Best regards,

Joseph
 
Replies continue below

Recommended for you

FYI...

Just heard back from the reseller, and this is a limitation.

If anyone knows a good work around, please let us know.

Have a great day,

Joseph
 
Joseph,

You can use a macro to list the custom properties for a configuration. File custom information is stored in the document file. It can be:

General to the file, in which case there is a single value whatever the model's configuration
- or -

Configuration-specific, in which case a different value may be set for each configuration in the model

This is documented in Solidworks Help under Help/Solidworks and Add-Ins API Help Topics.

Here's an example from the Help file:

Code:
This example shows how to list the custom properties for a configuration.

 LIST CUSTOM PROPERTIES EXAMPLE (VB)

'-------------------------------------

'

' Preconditions: SolidWorks document is open to which custom properties have been assigned.

' 

' Postconditions: None

'-------------------------------------

Option Explicit

Public Enum swCustomInfoType_e

    swCustomInfoUnknown = 0

    swCustomInfoText = 30       '  VT_LPSTR

    swCustomInfoDate = 64       '  VT_FILETIME

    swCustomInfoNumber = 3      '  VT_I4

    swCustomInfoYesOrNo = 11    '  VT_BOOL

End Enum

Sub main()

    Dim swApp                           As SldWorks.SldWorks

    Dim swModel                         As SldWorks.ModelDoc2

    Dim vConfigNameArr                  As Variant

    Dim vConfigName                     As Variant

    Dim vCustInfoNameArr                As Variant

    Dim vCustInfoName                   As Variant

    Dim bRet                            As Boolean

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    

    Debug.Print "File = " & swModel.GetPathName

    

    vConfigNameArr = swModel.GetConfigurationNames

    

    ' Is empty if a drawing becasue configurations not supported on drawings

    If IsEmpty(vConfigNameArr) Then

        ReDim vConfigNameArr(0)

        vConfigNameArr(0) = ""

    Else

        ' Add a blank string for the nonconfiguration-specific custom properties

        ReDim Preserve vConfigNameArr(UBound(vConfigNameArr) + 1)

    End If

    

    For Each vConfigName In vConfigNameArr

        Debug.Print "  " & vConfigName

    

        vCustInfoNameArr = swModel.GetCustomInfoNames2(vConfigName)

        If Not IsEmpty(vCustInfoNameArr) Then

            For Each vCustInfoName In vCustInfoNameArr

                Debug.Print "    " & vCustInfoName

                Debug.Print "      Type     = " & swModel.GetCustomInfoType3(vConfigName, vCustInfoName)

                Debug.Print "      Value    = " & swModel.GetCustomInfoValue(vConfigName, vCustInfoName)

                Debug.Print "      Text     = " & swModel.CustomInfo2(vConfigName, vCustInfoName)

            Next

        End If

        Debug.Print "  ---------------------------"

    Next

End Sub

Hope that helps!

Shawn Oelschlager
Production Control Ass't
Transco Products Inc.

SolidWorks Office Premium 2006 - SP4.1
Pentium 4 (2.8 GHz) - 2GB RAM
 
What exactly are you attempting to do? Do you want to check open documents for a certain config-specific custom property, or do you want SolidWorks Explorer type functionality? That is, do you want to be able to search documents without opening them in SolidWorks? This can be done using the undocumented API calls in SwDocumentMgr.dll. The .dll is distributed along with SW. Prior to SW'07 the use of this .dll requires a "license key" string. This can be obtained free (for use inside your own company only) upon request from SolidWorks API support. Starting with '07, this license key string is not required. Any value passed as a key will be ignored.

These .dll functions can be called from any program (Excel, etc) that uses OLE automation. Below is sample SolidWorks macro that will list all the custom properties for each configuration of the active document. Note that these will be read from the stored file on disk rather than the current version in memory, so if you add a new custom property you will have to save the document before the macro will find it. For this macro to work you will need to go to Tools->References in the VBA editor and check the box for SwDocumentMgr 200(x) Type Library. You may have to browse or search for it. Mine is located at C:\Program Files\Common Files\SolidWorks Shared. If you are using SW2006 or earlier you will have to get a license key string and change the value of the constant "DOCMGRLICENSEKEYSTRING" to whatever key you receive from API support.

Code:
Const DOCMGRLICENSEKEYSTRING As String = "Replace this text with your license key string for SW<2007"

Dim swApp As SldWorks.SldWorks
Dim swDocMgr As SwDocumentMgr.SwDMApplication
Dim swDoc As SldWorks.ModelDoc2
Dim myTestConfig As SwDocumentMgr.SwDMConfiguration5
Dim CfgMgr As SwDocumentMgr.SwDMConfigurationMgr
Dim myCfgNames As Variant
Dim myCustPropNames As Variant
Dim myCustPropVals As Variant
Dim myDocMgrClassFactory As SwDocumentMgr.SwDMClassFactory
Dim myDocMgr As SwDocumentMgr.SwDMApplication
Dim mySwDoc As SwDocumentMgr.SwDMDocument7
Dim i As Long
Dim j As Long
Dim msg As String

Sub main()

Set swApp = Application.SldWorks
Set swDoc = swApp.ActiveDoc

Set myDocMgrClassFactory = CreateObject("SwDocumentMgr.SwDMClassFactory")
Set myDocMgr = myDocMgrClassFactory.GetApplication(DOCMGRLICENSEKEYSTRING)
Set mySwDoc = myDocMgr.GetDocument(swDoc.GetPathName, swDmDocumentUnknown, True, Empty)
Set CfgMgr = mySwDoc.ConfigurationManager
myCfgNames = CfgMgr.GetConfigurationNames

msg = "There are " & CfgMgr.GetConfigurationCount & " configurations of " & swDoc.GetTitle

For i = 0 To UBound(myCfgNames)
    Set myTestConfig = CfgMgr.GetConfigurationByName(myCfgNames(i))
    msg = msg & vbCrLf & vbCrLf & myCfgNames(i)
    myCustPropNames = myTestConfig.GetCustomPropertyNames
    For j = 0 To UBound(myCustPropNames)
        msg = msg & vbCrLf & "  " & myCustPropNames(j) & " : "
        msg = msg & myTestConfig.GetCustomPropertyValues(myCustPropNames(j), swDmCustomInfoUnknown, "")
    Next
Next

MsgBox msg

End Sub
 

Thank you Shawn and Handleman, we are looking for SolidWorks Explorer "enhanced" functionality.

We could use the API, but would like to propose a less time consuming solution. So we might just create a database or spreadsheet instead and use it to store and search for information.

Regards,

Joseph

 
Status
Not open for further replies.
Back
Top