5 Replies Latest reply on Apr 10, 2015 9:16 AM by jgardner

    How to get the number of list items from a listbox in a macro

    jgardner

      Hi,

       

      I'm using PADS Layout 9.4.1, and I'm trying to figure out how to write a macro/script that will open the CAM dialog box, select all the items in the listbox, and then click run.  If I always knew how many items would be in the list box I would just record a macro and be done with it, but the number will usually be different.  From the reference manual it looks like I should be able to use the ListBox.ListCount property, assign that to a variable, and run a For loop to select all the items in a list, but it doesn't work.  Really I haven't been able to use variables at all in my scripts, and I'm not sure what the problem is.  Here is an example of what I would like to do (in a macro):

       

      Dim i

      Dim x

       

      'Output Cam Files

      Application.ExecuteCommand("Define Cam Documents")

      x = DefineCamDocumentsDlg.CamDocuments.ListCount

      For i = 0 to x-1

      DefineCamDocumentsDlg.CamDocuments.Selected(i) = true

      Next i

      DefineCamDocumentsDlg.CAMDocumentsRun.Click()

      DefineCamDocumentsDlg.Close.Click()

       

      In this case when I run it I get an error when I try to set x=DefineCamDocumentsDlg.CamDocuments.ListCount, but if I just replace the list count with any number, then it will run and crash out (the CAM dialog box just closes without running anything).

       

      I'm open to using this in any combination of a basic script, such as creating a macro string and running that from the script, but I wouldn't know how to get the number of CAM items in the list box in that case.  Any help, or any direction you can point me in to understanding how to use variables or send/return variables to a macro would be great.  I would also love some examples of how to use If statements inside of a macro, if it really is possible (I'm starting to get skeptical of the reference guide...)

       

      Thanks,

      Jens

        • 1. Re: How to get the number of list items from a listbox in a macro
          jgardner

          Oh well I found in another post that you in order to use a variable in a dialog box you have to declare it as modal.  That pretty much solves the problem.

           

          On a related note, is there an easy way of detecting if a dialog box is open, and then what to do if it is?  When I run this script, if the cam documents already exist in that folder, it will ask if I want to overwrite them.  But if they don't already exist, it won't ask.  I'd like to have an If statement that will detect if the dialog box opens, and if it does, just click "yes" to overwrite.

          • 2. Re: How to get the number of list items from a listbox in a macro
            jduquette

            I'm glad you found your problem already!  Can you post the script?  It sounds useful. 

            • 3. Re: How to get the number of list items from a listbox in a macro
              jgardner

              Hi jduquette,

               

              Here is the macro (two thirds of the way down I have commented out the section that I'm not sure how to generate dynamically so that I don't have to answer "yes I actually do want to go ahead and generate the CAM outputs":

               

              modal x

              modal i

               

              'Open the Cam Dialog

                   Application.ExecuteCommand("Define Cam Documents")

               

              'Select all items in the listbox

                   x = DefineCamDocumentsDlg.CamDocuments.ListCount

                   For i = 0 to x-1

                        DefineCamDocumentsDlg.CamDocuments.Selected(i) = true

                   Next i

               

              'Run CAM Outputs

                   DefineCamDocumentsDlg.CAMDocumentsRun.Click()

               

              'Answer "do you want to generate files" dialog

                   'Here is the problem: Depending on what CAM outputs there are, the dialog box name will change

                   'DlgPrompt.Question("Do you wish to generate the following outputs? : [Name of CAM Outputs Here]").Answer(mbYes)

               

              'Close CAM Dialog

                   DefineCamDocumentsDlg.Close.Click()

              • 4. Re: How to get the number of list items from a listbox in a macro
                jduquette

                So what scripting language are you using?  that doesn't look like Sax Basic .  I'll script something every couple of years or so and it looks like you are into a realm that I've never explored before.  Where did you find documentation on "Define Cam Documents"? 

                 

                I wonder if there is a (unexpected) 'dialog opened' option where you can tell the script to answer yes and continue?  If not the CAMDocumentsRun routine would need to be smart enough to have an input that tells it to overwrite the files.

                 

                On a side note, at least in 9.3 they fixed the issue where it used to pop up that dialog asking about overwriting for EACH document; that was a pain!

                • 5. Re: How to get the number of list items from a listbox in a macro
                  jgardner

                  This is a PADS macro.  You can record/edit/play macros in PADS just like you can in Excel.  In the menu bar, go to View->Output Window (and make sure its not collapsed at the bottom of the screen), and then in the tabs on the bottom of the output window click "macros" (or go to Tools->macros->new macro...).

                   

                  The PADS User's Guide and Reference Manual has a section on the macro language.  You can code one from scratch, but the easiest thing is to record one, then modify it using whatever if/else for/next, etc. programming commands you want.

                   

                  You can also record a macro then run it using a Sax Basic script using the Application.RunMacro command.  What I find useful is actually building a macro using text strings in a basic script, then save that to a .mcr macro file, then run the macro using the RunMacro command, and then deleting the .mcr file.  That way the whole macro is contained in the vbscript and you can add dynamic content that is more easily obtained from basic script commands.