10 Replies Latest reply on Jun 13, 2014 10:17 AM by Sanya Shmidt

    Search custom properties in EPDM database using API

    Sanya Shmidt

      Hi guys,

       

      I`m working on a part configurator which will be creating unique ID# for the generated part. ID# will be assigned to a custom propery.

       

      I`m curious if there is a way to search for the custom property in EPDM using API calls?

       

      For example user will type all part parameters in the configurator. ID will be generated in the background. After user clicks generate part, I want to search in EPDM for matching ID`s and give user a suggestion that part with these parameters already exists.

       

      Any help is appreciated.

      Thanks,

      Alex.

        • Re: Search custom properties in EPDM database using API
          Artem Taturevych

          You cannot search y custom properties directly but you can search by ePDM variable. Use this method: IEdmSearch5::AddVariable. Take a look at the examples available under the IEdmSearch5 interface.

          ______________________________________________

          Regards, Artem Taturevych | Snr. Developer | IC3D ANZ

           

          IC3DSteel – New Steel Solution for SolidWorks

          translationXpert – SolidWorks files language translator

          LinkedIn - SolidWorks API Group

          • Re: Search custom properties in EPDM database using API
            Markku Lehtola

            Hi,

             

            I'm using Excel based search tool to check if part exists and get some custom property info, let me know if you're interested..

             

            Performance is pretty much the same as searching by hand I think..

             

            br

            Markku

            www.sloworks.fi

              • Re: Search custom properties in EPDM database using API
                Sanya Shmidt

                Markku thanks,

                Would be great if you could share a part of a code. I do have an app that works with excel, searches , adds new parts. I guess I can use same engine. Below is what I used in a different other then SW area.

                 

                'Checking database Searching Excel document

                    Private Sub but_check_Click(sender As Object, e As EventArgs) Handles but_check.Click

                 

                If File.Exists(pathfile) = False Then

                            MsgBox("Database doesn`t exist or network is down.", MsgBoxStyle.Critical, "Warning!!!")

                            Exit Sub

                        End If

                        Dim xlApp As New Excel.Application

                        Dim xlWb As Excel.Workbook

                        Dim xlsheet As Excel.Worksheet

                        Dim i As Integer

                        lbl_Sswitch.Visible = False

                        With xlApp

                            .Visible = False

                            '~~> Open workbook

                            xlWb = .Workbooks.Open(pathfile)

                            '~~> Set it to the relevant sheet

                            xlsheet = xlWb.Sheets("P17885")

                            On Error GoTo CantFindSwitch

                            bar_1.Visible = True : lbl_searching.Visible = True

                            With xlsheet

                                lastrow = .Range("A" & .Rows.Count).End(Excel.XlDirection.xlUp).Row ' last row

                                ReDim P17885(lastrow + 1, 2)

                                For i = 1 To lastrow

                                    P17885(i, 1) = xlsheet.Cells(i, 1).Value

                                    P17885(i, 2) = xlsheet.Cells(i, 4).Value

                                    bar_1.Maximum = lastrow

                                    bar_1.Step = 1

                                    bar_1.PerformStep()

                                    If P17885(i, 2) = txt_des_level1.Text Then

                                        lbl_Sswitch.Visible = True 'txt_existPart.Visible = True

                                        lbl_Sswitch.Text = P17885(i, 1) : switch_exist = True

                                        Exit For

                                    End If

                                Next

                            End With

                        End With

                        bar_1.Value = 0

                        'bar_1.Visible = False

                        lbl_searching.Visible = False

                        If switch_exist = True Then

                            switch_exist = False

                            GoTo ClearVars

                        End If

                CantFindSwitch:

                        If MsgBox("Cant find switch. Would you like to add it?", MsgBoxStyle.YesNo, "Warning!") = MsgBoxResult.No Then

                            GoTo ClearVars

                        Else

                            gbox_2.Enabled = True

                            txt_level1.Text = txt_des_level1.Text

                                   lbl_NewSwitchNum.Visible = True

                            lbl_NewSwitchNum.Text = "P17885-" + CStr(i - 1)

                            txt_JN.Select()

                         End If

                ClearVars:  '~~> Close workbook and quit Excel

                        xlWb.Close(False)

                        xlApp.Quit()

                        xlApp = Nothing

                        xlWb = Nothing

                        xlsheet = Nothing

                End Sub

                 

                 

                  'adding switch to the database

                    Private Sub but_add_Click(sender As Object, e As EventArgs) Handles but_add.Click

                      If txt_JN.Text = "" Then

                            MsgBox("Job number is required field.", MsgBoxStyle.Exclamation, "Warning!")

                            txt_JN.Select()

                            Exit Sub

                        End If

                        If cbox_description.SelectedIndex = -1 Then

                            MsgBox("Description is required field.", MsgBoxStyle.Exclamation, "Warning!")

                            cbox_description.Select()

                            Exit Sub

                        End If

                        If File.Exists(pathfile) = False Then

                            MsgBox("Database doesn`t exist or network is down.", MsgBoxStyle.Critical, "Warning!!!")

                            Exit Sub

                        End If

                        '~~> Open workbook

                        Dim xlApp As New Excel.Application

                        Dim xlWb As Excel.Workbook

                        Dim xlsheet As Excel.Worksheet

                        lastrow = 0

                        With xlApp

                            xlWb = .Workbooks.Open(pathfile)

                            xlsheet = xlWb.Sheets("P17885")

                            xlsheet.Activate()

                            ' adding new record

                            With xlApp

                                lastrow = .Range("A" & .Rows.Count).End(Excel.XlDirection.xlUp).Row

                                .Range("A" + CStr(lastrow + 1)).Select()

                                .ActiveCell.FormulaR1C1 = "P17885-" + CStr(lastrow)

                                .Range("B" + CStr(lastrow + 1)).Select()

                                .ActiveCell.FormulaR1C1 = txt_JN.Text

                                .Range("C" + CStr(lastrow + 1)).Select()

                                .ActiveCell.FormulaR1C1 = cbox_description.SelectedItem

                                .Range("D" + CStr(lastrow + 1)).Select()

                                .ActiveCell.FormulaR1C1 = txt_level1.Text

                            End With

                        End With

                        MsgBox("Switch P17885-" + CStr(lastrow) + " added. Please write down part number.", MsgBoxStyle.OkOnly, "Switch added")

                        txt_level1.Text = ""

                        txt_JN.Text = ""

                        cbox_description.SelectedIndex = -1

                        txt_des_level1.Text = "1.00" : txt_des_level1.SelectionStart = 0

                        txt_des_level1.SelectionLength = 4 : txt_des_level1.Select()

                        lbl_Sswitch.Visible = False

                       lbl_searching.Visible = False

                        lbl_NewSwitchNum.Visible = False

                        gbox_2.Enabled = False

                        'System.Threading.Thread.Sleep(10000)

                TheEnd:

                        xlWb.Close(True)

                        xlApp.Quit()

                        xlApp = Nothing

                        xlWb = Nothing

                        xlsheet = Nothing

                    End Sub

                  • Re: Search custom properties in EPDM database using API
                    Markku Lehtola

                    Here's the base of the search code. Idea is to check are item numbers found in EPDM and if yes, then read some stuff. hope it helps..

                     

                    Sub SearchEDM()

                    Dim swApp As SldWorks.SldWorks

                    Dim swModel As ModelDoc2

                     

                     

                    Const swDocPart = 1

                    Const swDocAssembly = 2

                     

                     

                    Sheets("Sheet1").Activate

                     

                     

                    'login to vault

                    Dim objVault As IEdmVault8

                    Const vaultname As String = "EDM"

                    Set objVault = New EdmVault5

                    objVault.LoginAuto vaultname, 0

                     

                     

                    Dim search As IEdmSearch7

                    Dim DescriptionID As Integer

                    Dim sr As IEdmSearchResult5

                     

                     

                    'clear old search results

                    Worksheets("Sheet1").Columns(6).ClearContents

                    Worksheets("Sheet1").Columns(7).ClearContents

                    Worksheets("Sheet1").Columns(8).ClearContents

                    Worksheets("Sheet1").Columns(4).ClearContents

                    Worksheets("Sheet1").Columns(13).ClearContents

                     

                     

                    'item number row count from column E

                    LastRow = Worksheets("Sheet1").Range("E65536").End(xlUp).Row

                     

                     

                    For i = 1 To LastRow

                       

                           

                      Set search = objVault.CreateSearch

                              'B2= folder, eg. C:\EDM\COMPONENT LIBRARY

                        search.AddVariable Range("B2").Text, "%" & Range("E" & i).Text

                        Dim retval As Boolean

                      

                        'search options    

                        search.FindFiles = True

                        search.FindFolders = False

                        search.Filename = "%.sldprt"

                        search.SetToken Edmstok_AllVersions, False

                      

                     

                        Set sr = search.GetFirstResult

                        If sr Is Nothing Then

                        Else

                              'fill columns with data if item number in column E is found in EDM

                       

                        Range("G" & i).Value = sr.Path

                        Range("H" & i).Value = sr.Name

                        Range("G" & i).Activate

                       

                     

                    'read item numbers and if match found with N-prefix then get the configuration name from the model for

                    'that item number   

                       Dim File As IEdmFile8

                       Dim Folder As Object

                      

                            Set File = objVault.GetFileFromPath(sr.Path, Folder)

                            Dim cfgList As EdmStrLst5

                            Set cfgList = File.GetConfigurations

                     

                            Dim pos As IEdmPos5

                            Dim pEnumVar As Object

                            Set pEnumVar = File.GetEnumeratorVariable

                            Dim Value As Variant

                            VariableName = "Item Number"

                            Set pos = cfgList.GetHeadPosition

                            Dim cfgName As String

                                While Not pos.IsNull

                                    cfgName = cfgList.GetNext(pos)

                                    If pEnumVar.GetVarFromDb(VariableName, cfgName, Value) Then

                                        If Right(Value, 6) = Range("E" & i).Text Then

                                                                                                    If Left(Value, 1) = "N" Then

                                                Range("D" & i).Value = "N"

                                                Range("M" & i).Value = cfgName

                                               

                                            End If

                                    Else

                                        End If

                                    End If

                                   

                                Wend

                       

                    'add link to model

                       

                        If Dir(sr.Path) <> "" Then

                            ActiveCell.Formula = "=HYPERLINK(" & Chr(34) & sr.Path & Chr(34) & "," & """Open model""" & ")"

                        End If

                       

                        End If

                       

                    Next i

                     

                     

                    MsgBox ("Search finished")

                     

                     

                    End Sub