12 Replies Latest reply on Aug 1, 2014 9:45 AM by fuba

    Iterating over DxDatabook Library Elements / Export via Script/VB.Net

    fuba

      Hello Community,

       

      I am trying to iterate over the entries in the DxDatabook from DxDesigner.

      Also Ok would be an idea how to get access via a script to the DxDatabook groups and elements.

       

      Any help is appreciated.

       

      Thanks in advance to all contributors

        • 1. Re: Iterating over DxDatabook Library Elements / Export via Script/VB.Net
          a.sassano

          Hello fuba,

           

          This are the Informations I have for DxDB Scripting:

           

          -1-

          The Dxdatabook Scripting interface doesn't support this.

           

          DxDatabook only gives you events on several actions

            Application_AddComponent Event

            Application_AfterAddComponent Event

            Application_AfterAnnotateComponent Event

            Application_AnnotateComponent Event

            Application_LoadComponent Event

            Application_SelectComponent Event

            Application_ViewDocument Event

           

          You cannot access the displayed elements or groups.

           

          -2-

          You can enable and disable the Dxdatabook Addin by Scripting.

           

          -3-

          Maybe you could access the datasource directly, or the dbc file? So you can access the Objects you need?

           

           

          The primary Question for me was: What would you do if you have the objects?

           

          Best Regards

          Angelo

          • 2. Re: Iterating over DxDatabook Library Elements / Export via Script/VB.Net
            fuba

            Dear Angelo,

             

            thanks for the first information.

             

            Well, my problem is, that I work for a globally acting company, and so my Database is also globally.

            When I select a part, I like to check if it is available @ our local stock.

             

            Also I like to get information from the properties for engineering purposes.

             

            I am not shure how to go on, in the past, someone mentioned the DMS-Desktop,

            but since we are on 7.9.3 this is not running anymore.

             

            Do we have a spec how the dbc is setup ???

             

            Thanks

             

            /Stefan

            • 3. Re: Iterating over DxDatabook Library Elements / Export via Script/VB.Net
              Patrick.Cashman

              It is best to think of the DxDatabook as a window that looks at the Central Library and the database.  All the information avaible to Databook is also available through automation methods which access the database and the library directly.  If you can use Databook, your computer can access the database.  Which means you can write a script with the correct connection string for whatever database you have, and get anything you want from it.  There are numerous examples of how to connect to various database flavors using vb.net on the internet.

               

              For example, I use this one to get a list of all the tables in our MS Access database:

               

              Public con_str As String

              Public db_path As String

              Public db_name as String

              Public conn As OleDbConnection

              Public da As OleDbDataAdapter

              Public db_tables as new ArrayList

              Public cmd_bldr As OleDbCommandBuilder

               

               

              Sub get_table_list()

                      Dim dts As DataTable

               

                      con_str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & db_path & ";"

                      conn = New OleDbConnection(con_str)

                      Try

                          table_list.Clear

                          conn.Open()

                          'Get table and view names

                          dts = conn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, Nothing})

                          Dim int As Integer

                          For int = 0 To dts.Rows.Count - 1

                              If dts.Rows(int)!TABLE_TYPE.ToString = "TABLE" Then

                                  If dts.Rows(int)!TABLE_NAME.ToString() = "ALL_PART_NUMBERS" Then GoTo next_table

                                  If dts.Rows(int)!TABLE_NAME.ToString() = "X_central_lib_parts_partitions" Then GoTo next_table

               

                                  'Add items to list box

                                  table_list.Add(dts.Rows(int)!TABLE_NAME.ToString())

                                  'debug.Print("Table name is: " & dts.Rows(int)!TABLE_NAME.ToString())

                              End If

                              next_table:

                          Next

                      Catch ex As Exception

                          MessageBox.Show(ex.Message.ToString(), "Data Load Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

                      End Try

                      conn.Close()

                      dts = Nothing

               

               

                  End Sub

               

               

              I hope this helps you get started.

              • 4. Re: Iterating over DxDatabook Library Elements / Export via Script/VB.Net
                juergen.dickler

                @fuba

                I guess you are in the same company as I. Name is starting with D.

                DMS-Desctop is still running with 7.9.3.

                • 5. Re: Iterating over DxDatabook Library Elements / Export via Script/VB.Net
                  fuba

                  Dear Patrick,

                   

                  thanks for the answer. I will check your code in a few days.

                   

                  Sorry for not answering on your reply. I was on vaction.

                   

                  Thanks & I will come back in a few days.

                   

                  Regads Stefan

                  • 6. Re: Iterating over DxDatabook Library Elements / Export via Script/VB.Net
                    fuba

                    Dear Patrick,

                     

                    Your example is clear to me, regarding the query of an MS-Access database,

                    but I am not getting the point, how to use this for my

                    *.lmc Database access via the DxDesigner.

                     

                    My problem is, that I do not know which type/format the lmc Database is?

                     

                    So do you have another example / idea / a few hints how to get the information

                    listed in the DX-Databook?

                     

                    Thanks again.

                     

                    Stefan

                    • 7. Re: Iterating over DxDatabook Library Elements / Export via Script/VB.Net
                      Patrick.Cashman

                      Here are a set of variables and routines that create a hook to a part editor reference to the central library:

                       

                       

                           Public job As String

                           Public part_ed_dlg As MGCPCBPartsEditor.PartsEditorDlg

                          Public pdb_db As MGCPCBPartsEditor.PartsDB

                       

                          Public partitions As MGCPCBPartsEditor.Partitions

                          Public partition As MGCPCBPartsEditor.Partition

                          Public parts As MGCPCBPartsEditor.Parts

                          Public part As MGCPCBPartsEditor.Part

                          Public cellRefs As MGCPCBPartsEditor.CellReferences

                          Public cellRef As MGCPCBPartsEditor.CellReference

                          Public symbs As MGCPCBPartsEditor.SymbolReferences

                          Public symb As MGCPCBPartsEditor.SymbolReference

                          Public props As MGCPCBPartsEditor.Properties

                          Public prop As MGCPCBPartsEditor.Property

                       

                           Public Sub GetLib()

                              'Creates a handle to the Parts Editor in Library Manager

                              part_ed_dlg =CreateObject("MGCPCBLibraries.PartsEditorDlg")

                              'job is the path to the .lmc file

                              pdb_db = part_ed_dlg.OpenDatabaseEx(job, False)

                              If part_ed_dlg.LockServer() Then

                                        'do nothing

                              else

                                        msgbox("Could not lock database for writing")

                              End If

                          End Sub

                       

                       

                          Private Sub GetPartInfo()

                              'Iterates through each part in each partition and collects the needed info for oracle and DxDatabook

                              'Get the collection of partitions in the parts editor

                              partitions = pdb_db.Partitions

                              'Step through each partition in the parts editor

                              For Each partition In partitions

                                  'Get the collection of parts in the current partition

                                  parts = partition.Parts

                                  'Step through each part in the parts collection

                                  For Each part In parts

                                      'Collect part information here

                                      'Get the collection of cells for the current part

                                      cellRefs = part.CellReferences

                                      'Step through each cell in the cells collection

                                      For Each cellRef In cellRefs

                                          'Collect cell information here

                                      Next

                                      'Get the collection of symbols for the current part

                                      symbs = part.SymbolReferences

                                      'Step through each symbol in the symbols collection

                                      For Each symb In symbs

                                          'Collect symbol information here

                                      Next

                                      'Get the collection of properties on the current part

                                      props = part.Properties

                                      'Step through each property in the properties collection

                                      For Each prop In props

                                          'Collect properties information here

                                      Next

                                      'Do something with the data collected here

                                  Next

                              Next

                          End Sub

                       

                          Public Sub DropLib()

                              'Close the open library and release hooks

                       

                              'part_ed_dlg.SaveActiveDatabase

                              part_ed_dlg.UnlockServer

                              part_ed_dlg.CloseActiveDatabase

                              pdb_db = Nothing

                              part_ed_dlg = Nothing

                          End Sub

                       

                      Once you have a reference to the part editor, you can iterate through partitions, parts, symbol refs, cell refs, etc.  There is information about the part editor in the help, so you should also read up on that. 

                       

                      There is a similar idea for cell editor.  Keep in mind the part editor is somewhat limited in scope - it cannot do everything with everything.  Just gets or sets information about the pdb's and associated objects. Cell editor gives you more access to the actual contents of a cell, pin mapping, and the like.  Also found in the help. 

                       

                      ps all the above I put in a module so that it is accessible by any part of the project. 

                      • 8. Re: Iterating over DxDatabook Library Elements / Export via Script/VB.Net
                        fuba

                        Hi Patrick,

                         

                        thanks again for the Code.I am able to iterate over the symbols and parts and so on, but

                        I have the whole thing not fully understood.

                         

                        I am still looking for all the properties a part has, like

                         

                        * Value,

                        * Tolerance,

                        * Rated Power,

                        * a link to the Drawing,

                        * Temperature

                        * ...

                         

                        pls see the attached screenshot.

                         

                        Where does this information come from?

                         

                        I thought it is part of the Library (lmc-file), or the LMC file contains a link to a "bigger"

                        remote database, but I am not able to find something. I had a look with the Report

                        Writer tool inthe LMC file, but couldnt find any. So ??? Do you have an Idea ?

                         

                        I have also another question, do you know how I can obtain from DxDatabook the active / current selected part ?

                         

                        Thanks again

                         

                        Best regards

                         

                        Stefan

                        • 9. Re: Iterating over DxDatabook Library Elements / Export via Script/VB.Net
                          Patrick.Cashman

                          All of those other properties are stored in the external database that DxDatabook looks to.  You can find this database with the following:

                           

                          1. Got to your central library location and find the .dbc file there.  This is the file that DxDatabook uses to codify what it finds in the external database.

                           

                          2. Do a text search in this file for ODBC;ALIAS=

                           

                          3. What follows the above is the name of the ODBC connection Windows uses to obtain visibility to the external database.

                           

                          4. Open the ODBC data sources Administrator.  This can be found in Windows\System32\odbcad32.exe or (if your database is MS Access) in Windows\SysWOW64\odbcad32.exe

                           

                          5. In the User DSN tab under User Data Sources you should see an entry with the same name as found in step 2 & 3 above.

                           

                          6. Select this entry and click on the Configure button to the right.

                           

                          7. The Database area of the next screen that pops up will show the path to your external database.

                           

                          8. Back in the previous screen, the ODBC Administrator dialog, you will see the driver used for the database. 

                           

                          9. With the combination of the driver, which should give you a clue what kind of database it is, and the path, you shold be able to get the correct connection string.

                           

                          If you are not using Windows, then I have no idea.  Contact your system adminstrator or whoever sets up your DXDatabook configuration to find the location and type of your database.

                           

                          Also be aware that some companies set up their databases with read/write protection and it may be that you cannot get in there directly.  You'll have to hunt around on that one.

                          • 10. Re: Iterating over DxDatabook Library Elements / Export via Script/VB.Net
                            fuba

                            Hello Angelo,

                             

                            roughly one year ago, you responded on my question above. Now my idea / task is similar to the one from the past.

                            In the past you mentioned to use the DxDatabook events like:

                             

                            •   Application_AddComponent Event
                            •   Application_AfterAddComponent Event
                            •   Application_AfterAnnotateComponent Event
                            •   Application_AnnotateComponent Event
                            •   Application_LoadComponent Event
                            •   Application_SelectComponent Event
                            •   Application_ViewDocument Event

                             

                            how do i access them ? What is the underlaying Base Object ? I cannot find them.

                            I am doing my Application in VB.Net, so I need the BaseObject which carries the Events.

                             

                            Do you have a simple DxDatabook script for me wher I can have a look at ?

                             

                            Thanks

                             

                            Stefan

                            • 11. Re: Iterating over DxDatabook Library Elements / Export via Script/VB.Net
                              Patrick.Cashman

                              I just wrote some stuff about this in a recent thread:

                               

                              http://communities.mentor.com/thread/15133?tstart=0

                               

                              Also see the help on Scripting with DxDatabook in the Automation: DxDesigner area.

                               

                              The basic idea is this:

                               

                              - you configure DxDatabook with a script.  It is vbs only.  Right click in a DxDatabook search window, see the Configure > Scripting > Settings.  There you define a file locaion for the script.

                              - you add functions for each event to the script.  For example my Application_ViewDocument function call:

                               

                              Function Application_ViewDocument(properties, document)

                               

                              End Function

                               

                              The help has examples of how to do the function for each of the events.

                               

                               

                              - What happens is that whenever the action takes place as a user is doing things in DxDatabook, the script is called every time and if the function for that action exists, it executes.

                               

                              - The underlying data for DxDatabook resides in a database. It could be any of several kinds of database, as it is accessed through the Windows ODBC connection system.  So you create the database, make an OBDC connection to it, then access this connection with DxDatabook.  This is all controlled via a database configuration file.  You can see the path to this file in DxDesigner Setup > Settings > DxDatabook.

                               

                              - The dbc file references the ODBC connection.  If you read the dbc file with a text editor, you can see what the name of the ODBC connection is.  You can look in your ODBC connections in Windows (C:\Windows\Syswow64\odbcad.exe) to find the actual database referenced by that connection.

                               

                               

                              This system is limited in two ways:

                               

                              1. The functions available from DxDatabook are not very powerful.  There is a lot more capability in DxDatabook that would be nice to have available to automation.

                               

                              2. The script is vbs only.  Thus it is limited by the capability of vbscript.  No Window API access, for example. 

                               

                              So if you want to work with these events, you have to get very creative.

                               

                               

                              That's the basic overview.  Read all the help on the subject and you will have a somewhat better idea of where to go next. 

                              • 12. Re: Iterating over DxDatabook Library Elements / Export via Script/VB.Net
                                fuba

                                Hello Patrick,

                                 

                                thanks for the detailed information. I will check next week.

                                Well, I look for a way, to give a special functionality to the user, by sending him just an "exe-File". Not scripts.

                                So, to work with the DxDatabook I need to modify (maybe manually) the VBS file, you mentioned listed in the DxDatabook Config.

                                 

                                Today I did soemthing, like that on my machine, but it is not straight foreward.

                                I have also taslked to Mentor in the US this afternoon, let me see what they can do for me.

                                 

                                I'll keep you posted on that.

                                 

                                Thanks again man for all the valueable information & have a great weekend.