5 Replies Latest reply on Dec 16, 2014 2:58 AM by peter_festesen

    Start action after Schematic is opened and displayed

    delinquent

      Hi all,

      I like to start some action after a project is loaded and schematic is initially displayed.

      Unfortunately DxDesigner does enter Sub.

      Sub Application_AfterDocumentOpened(VDDT_SCHEMATIC)

      ....[some statements]...

      End Sub

      What's wrong here? Any suggestions?

      I'm sure there is something stupid with my code since I'm newbie on Automation...

       

       

      äääh, yes...

      I also tried

      Sub Application_ProjectChanged(IProjectData)

      ...[some code]...

      End Sub

      That is workling well, but the required:

      Set docObj = SchematicSheetDocuments.Open(schemStr, sheetStr)

      ..to open a schematic sheet, crashes DxDesigner. -> DR

      So that's no option for me, unfortunately.

        • 1. Re: Start action after Schematic is opened and displayed
          peter_festesen

          Hi Oli - this took a little while - I needed to go back and find a script that could help you - then I had to understand my own script again ;-)

           

          What I did back then was to exploit the event called ActivateView2 Event (Application Object) (see DxDEsigenr Automation Ref Manual (Pg 113/114) for details.

           

          My script had the purpose to open a specific Todo.txt file (with Wordpad) after DxDesigner was started, but only if the file existed...

           

          The skeleton of the script itself is fairly simple :

           

          Option Explicit

           

          'Declarations

          Scripting.Dontexit = True

           

          Function Application_ActivateView2(v)

           

          'Do your stuff

           

          End function

           

          I can post the full script here if you are interested (86 lines)

          • 2. Re: Start action after Schematic is opened and displayed
            peter_festesen

            One more remark - I seem to remember playing with AfterDocumentOpened event also, and looking at the above mentioned document, there are three required parameters : 

             

            Sub Application_AfterDocumentOpened(ByVal DocumentType As VdDataType, ByVal

            LibraryAlias As String, ByVal Name As String)

             

            where :

            Arguments

            • DocumentType

            Specifies the document type. This argument takes the form of VdDataType Enum.

            • LibraryAlias

            This is a string that corresponds to the library alias.

            • Name

            This is the name of the document.

             

            I am unsure what the Library alias should be. The name of the document would have to be extracted with automation , probably Application.GetActiveDesign - but I haven't tried...

             

            /Peter

            • 3. Re: Start action after Schematic is opened and displayed
              delinquent

              Hi,

              just want to update on this for all who are interested in this function. Unfortunately this Sub is called for every opened sheet, not just on project start / schematic opened / first sheet load. Means, it triggers an action every time it displays a new sheet.

               

              Anyhow, here is the correct statement:

               

              Sub Application_AfterDocumentOpened(docType, LibraryAlias, Name)

              ..code here

              End Sub

               

              ReturnValues:

              docType = 0 ( means VDDT_SCHEMATIC?)

              LibraryAlias = empty (in my case)

              Name = Top (Schematic Name)

               

               

              Does anyone have an idea how to start a one-time action when design is loaded?

              • 4. Re: Start action after Schematic is opened and displayed
                delinquent

                Hi Peter:

                Yes, please post that code. Would be great

                • 5. Re: Start action after Schematic is opened and displayed
                  peter_festesen

                  Hi - below please find my script. I ran a quick check - it will show the file in question also when switching between multiple boards inside the same project - just so you are aware...

                   

                  I can't seem to find the 'attach button', so I'll just paste in here....

                  Cheers

                  Peter

                   

                  ---- XXXX ----

                  'Start :

                   

                      Option Explicit

                     

                      Dim DxDapp

                      Dim openfile, filename, path

                      Dim patharray, p

                      Dim OldTop, CurrTop

                   

                      Set DxDapp = Application

                   

                   

                  'Main routine : only event handler is used. When project is opened, file is opened.

                  ' Set the Scripting.DontExit property to true to keep the script running.

                  Scripting.DontExit = True

                  OldTop = ""

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

                  Function Application_ActivateView2(v)

                   

                   

                     

                      CurrTop=DxDApp.GetActiveDesign()

                      If OldTop="" Then

                          OldTop=CurrTop

                          Call FileOpen()

                      End If 'OldTop=""

                     

                      If CurrTop<>OldTop Then

                          Call FileOpen()

                          OldTop=CurrTop

                      End If ' CurrTop<>OldTop

                  End Function

                   

                   

                  Sub FileOpen

                      'filename = "ToDo.rtf"

                      filename = "ToDo.txt"

                      path = DxdApp.GetProjectData.GetPCBDesignPath(DxDApp.GetActiveDesign(), True) 'path to PCB including pcb file name

                      ' we need to strip away the filename *.pcb

                      patharray = split(path,"\")

                      path =""

                          for p = 0 to ubound(patharray)-1

                              path = path + patharray(p)

                      next 'p

                   

                    DIM fso   

                    Set fso = CreateObject("Scripting.FileSystemObject")

                       If (fso.FileExists(path & "\doc\"&filename)) Then

                            

                          Dim wscript

                          Set wscript = CreateObject ("Wscript.shell")

                          wscript.Run ("wordpad.exe " & Path & "\doc\" & filename)

                         

                      End If

                   

                   

                   

                  End Sub 'FileOpen