1 2 First Previous 16 Replies Latest reply on Jan 21, 2013 5:51 AM by jduquette

    Accessing Fields in a macro

    dedelmann

      How do I access the Fields inside a macro?  I am aware of the ActiveDocument.Fields("Sheet Name") command to access the fields in a basic script file.  But I cannot access them in the macros.

        • 1. Re: Accessing Fields in a macro
          jduquette

          Are there specific fields you are having problems with?  In a macro you can pull up the field dialog box and access them there.

           

          <right-click>(Fields...)

           

          I recorded a macro while doing that and got this:

           

          Application.ExecuteCommand("Query Fields")

          FieldsDlg.UserFields.SelectField(1, 2)

          FieldsDlg.UserFields.Cell(1, 2) = "The new value that I typed in"

          FieldsDlg.SystemFields.SelectField(0, 1)

          FieldsDlg.Ok.Click()

          • 2. Re: Accessing Fields in a macro
            dedelmann

            I would like to read the field value in the macro.   I am basicaly trying to use the Fields as a way to pass a value from a basic script to the macro.

            • 3. Re: Accessing Fields in a macro
              dedelmann

              Ok, I just had an amazing discovery.  You can run a macro inside a basic script file with the View.Application.RunMacro(_filename, _macroname) command.  Also, basic allows you to create ASCII files.  So, I will create the macro inside the script file and then run it!

               

              Maybe not the easiest approach, but it should work!

              • 4. Re: Accessing Fields in a macro
                dedelmann

                Well, that didn't work either.  When the macro editor creates the macro, it somehow creates the macro name hidden in the file.  Anyone know where this is hidden?  I can open up the mcr files in Notepad and everything looks like it is there.  Except for the macro name!  When I create the macro in either Notepad or a basic script file, the macro name is not craeted, hence the basic script locks up when trying to run the macro.

                • 5. Re: Accessing Fields in a macro
                  jduquette

                  You can access the field value directly from a script instead of going through a macro:

                   

                  MsgBox ActiveDocument.Fields.Item ("Sheet Size").Value

                   

                  This is from:

                   

                  file:///{insert your PADS path here...}/docs/htmldocs/padslogic_user/wwhelp/wwhimpl/common/html/wwhelp.htm?context=padslogic_user&topic=560&accessible=true&single=true

                   

                  This lets you see the present value.  I'm rusty on scripts so I don't remember how you can change the value (ActiveDocument.Fields.Item...).

                  • 6. Re: Accessing Fields in a macro
                    dedelmann

                    That is the instruction for reading the fields in a basic script (.bas) file.  I would like to access them in the macro (.mcr) files.

                    • 7. Re: Accessing Fields in a macro
                      jduquette

                      It looks like we are going in circles here.  I thought you were only trying the macro as you were having problems in the script.

                       

                      When you are in the new macro dialog you can save and open macros.  I took a macro created with the macro editor and renamed it on the disk and then opened it.  The name tracks the filename.  Does that help?

                      • 8. Re: Accessing Fields in a macro
                        jduquette

                        The only option that I see in a macro that works with the Fields is the 'Add Field'.  I don't know of other field options so fields may have limited support.  It may be time for an SR for a definitive answer.

                         

                        Application.ExecuteCommand("Add Field")

                        DlgAddFieldLabel.FieldName.Text = "Drawn Date"

                        DlgAddFieldLabel.Ok.Click()

                        Application.ExecuteCommand("Place", 610, 2712)

                        DlgAddFieldLabel.Cancel.Click()

                         

                         

                        The fields show up in an ASCII file.  Is that useful?

                         

                        *PADS-LOGIC-V9.0* DESIGN EXPORT FILE FROM PADS LOGIC V9.3

                        *FIELDS*    USER FIELDS

                         

                        "TITLE" Laser Controller

                         

                        "Drawn Date" 12-28-2010

                        • 9. Re: Accessing Fields in a macro
                          dedelmann

                          That is really not useful either.  What I am trying to do is have a basic script file add and remove bill of material (BOM) lines from my title block.  We typically do not use the standard location for BOMs on a title page, that being directly above the description in the lower right corner. Therefore, I created a dialog box using a basic script file that updates all the information in the title block (using Fields) and also has the option to select the number of BOM lines.  I started by first creating a macro file that either adds or removes each line.  Then I run them individually, this works just fine using the View.Application.RunMacro command(_filename, _macroname).  However, I have to have a macro file for each line.  If I want 20 lines, then that requires 40 macro files.

                           

                          Then, I thought I would try to have my basic script file actually create the macro I need using the basic commands:

                           

                          Open "R:\ECAD\PADS_Lib\Midmark\autocreatedmacro.mcr" For Output As #1

                          Print #1, MacroAddBOMHeader

                          Print #1, MacroAddBOMItem(bomitem) {repeat this for the number of bomitems}

                          Close #1

                           

                          Private Function MacroAddBOMHeader As String

                          MacroAddBOMHeader = "Application.ExecuteCommand(" & Chr(34) & "Add 2D Line From Library" & Chr(34) & ")" & Chr(10)

                          MacroAddBOMHeader = MacroAddBOMHeader & "DlgGetDraftFromLibrary.Filter = " & Chr(34) & "R:\ECAD\PADS_Lib\Midmark\Midmark" & Chr(34) & Chr(10)

                          MacroAddBOMHeader = MacroAddBOMHeader & "DlgGetDraftFromLibrary.EditFilter = " & Chr(34) & "BOM_HEADER" & Chr(34) & Chr(10)

                          MacroAddBOMHeader = MacroAddBOMHeader & "DlgGetDraftFromLibrary.Apply.Click()" & Chr(10)

                          MacroAddBOMHeader = MacroAddBOMHeader & "DlgGetDraftFromLibrary.Ok.Click()" & Chr(10)

                          MacroAddBOMHeader = MacroAddBOMHeader & "Application.ModelessCommand(" & Chr(34) & "s" & Chr(34) & ")" & Chr(10)

                          MacroAddBOMHeader = MacroAddBOMHeader & "DlgModelessCmd.Command = " & Chr(34) & "s 11550 2524" & Chr(34) & Chr(10)

                          MacroAddBOMHeader = MacroAddBOMHeader & "DlgModelessCmd.OnOk()" & Chr(10)

                          MacroAddBOMHeader = MacroAddBOMHeader & "Application.ExecuteCommand(" & Chr(34) & "Finish Move" & Chr(34) & ", 11550, 2524)

                          End Function

                           

                          Private Function MacroAddBOMItem (bomitem As Integer) As String

                          Dim ycord As Long

                          ycord = (bomitem - 1) * 250 + 3024

                          MacroAddBOMItem = "Application.ExecuteCommand(" & Chr(34) & "Add 2D Line From Library" & Chr(34) & ")" & Chr(10)

                          MacroAddBOMItem = MacroAddBOMItem  & "DlgGetDraftFromLibrary.Filter = " & Chr(34) & "R:\ECAD\PADS_Lib\Midmark\Midmark" & Chr(34) & Chr(10)

                          MacroAddBOMItem = MacroAddBOMItem  & "DlgGetDraftFromLibrary.EditFilter = " & Chr(34) & "BOM_LINE" & Chr(34) & Chr(10)

                          MacroAddBOMItem = MacroAddBOMItem  & "DlgGetDraftFromLibrary.Apply.Click()" & Chr(10)

                          MacroAddBOMItem = MacroAddBOMItem  & "DlgGetDraftFromLibrary.Ok.Click()" & Chr(10)

                          MacroAddBOMItem = MacroAddBOMItem  & "Application.ModelessCommand(" & Chr(34) & "s" & Chr(34) & ")" & Chr(10)

                          MacroAddBOMItem = MacroAddBOMItem  & "DlgModelessCmd.Command = " & Chr(34) & "s 11100 " & Format$(ycord, "#") & Chr(34) & Chr(10)

                          MacroAddBOMItem = MacroAddBOMItem  & "DlgModelessCmd.OnOk()" & Chr(10)

                          MacroAddBOMItem = MacroAddBOMItem  & "Application.ExecuteCommand(" & Chr(34) & "Finish Move" & Chr(34) & ", 11100, " & Format$(ycord, "#") & ")" & Chr(10)

                          MacroAddBOMItem = MacroAddBOMItem  & "Application.ExecuteCommand(" & Chr(34) & "Select" & Chr(34) & ", 11306, " & Format$(ycord-156, "#") & ")" & Chr(10)

                          MacroAddBOMItem = MacroAddBOMItem  & "MainFrame.ActiveSheetComboB = " & Chr(34) & "Sheet 1" & Chr(34) & Chr(10)

                          MacroAddBOMItem = MacroAddBOMItem  & "Application.ExecuteCommand(" & Chr(34) & "Properties" & Chr(34) & ")" & Chr(10)

                          MacroAddBOMItem = MacroAddBOMItem  & "DlgQueryText.Text = " & Chr(34) & Format$(bomitem, "#") & Chr(34) & Chr(10)

                          MacroAddBOMItem = MacroAddBOMItem  & "DlgQueryText.Ok.Click()"

                          End Function

                           

                          Once created, I use the View.Application.RunMacro("R:\ECAD\PADS_Lib\Midmark\autocreatedmacro.mcr", "autocreatedmacro") to run the macro.  However, when doing this, PADS locks up causing me to have to force the program to close.  Interestingly enough, I can use the script file to create the macro, load it into the macro editor, and then run it, and there are no problems.  I can even load it into the macro editor, save it, and then run it out of the basic script and it works.  I just do not understand why I can not create and then run a macro in the basic script.  Let me also add this, I tried this approach with a simple macro (like only a MsgBox command) and it worked.

                           

                          Still confused and frustrated.

                          • 10. Re: Accessing Fields in a macro
                            jduquette

                            That is very odd about not executing.  I think you need to submit a SR to get the brains inside Mentor to take a look at this.  It may be as simple as a line or two to set up access to the proper design/database/document.

                             

                            On a side note, I wonder if placing text blocks instead of dealing with fields would be simpler?

                             

                            So if I understand this properly, are you trying to get the BOM to show up on the schematic or PCB assembly drawing (hmm, I wonder if this scripting is better supported in Layout than in Logic)?  We used to do that around here until I shot it down because it usually wasn't accurate as it was easy to miss in the ECO process.  I'd love to see it tied directly into the design instead of having to be entered manually.  I hope you'll post your solution for all to use when you get it figured out!

                            • 11. Re: Accessing Fields in a macro
                              dedelmann

                              Ok, I submitted the SR.  We'll see what kind of a response I get.  I have a feeling it will be "Sorry, but we do not support macros or basic script files."  If that is the case, then I am going to ask, "Why even have them?"

                               

                              If you are interested, I have created two very simple scripts, msgbox.bas should work and grid.bas should lock up PADS.  Try them out and let me know what happens.  Also, here is the real kicker, if grid.bas locks up your PADS, do this:

                              1. open the grid.mcr in the macro editor
                              2. Save as... (the same name is ok)
                              3. then open grid.bas and comment out the creation of the macro and just let it run the macro
                              4. It should work now....

                              This shows that the macro editor must be adding some attribute to the file.

                               

                              I realize that what I am doing with this approach isn't the most usefulness.  But, if I can get this to work, there is potentially a lot of things you can do with this approach.

                              • 12. Re: Accessing Fields in a macro
                                jduquette

                                I see the same lock up.  When I search my hard drive for grid.mcr it doesn't exist...

                                • 13. Re: Accessing Fields in a macro
                                  dedelmann

                                  I'm not exactly sure where it places it.  You can also specify a path like this:

                                   

                                  Sub Main

                                  Open "c:\temp\grid.mcr" For Output As #1

                                  Print #1, MacroGrid (2)

                                  Close #1

                                  View.Application.RunMacro ("c:\temp\grid.mcr", "")

                                  End Sub

                                  Private Function MacroGrid (size As Double) As String

                                  MacroGrid = "Application.ModelessCommand(" & Chr(34) & "G" & Chr(34) & ")" & Chr(10)

                                  MacroGrid = MacroGrid & "DlgModelessCmd.Command = " & Chr(34) & "G " & Format$(size, "#") & Chr(34) & "" & Chr(10)

                                  MacroGrid = MacroGrid & "DlgModelessCmd.OnOk()"

                                  End Function

                                  • 14. Re: Accessing Fields in a macro
                                    jduquette

                                    1) Well, I commented out the view.application.runmacro line and was able to successfully generate the grid.mcr file.

                                     

                                    2) I then ran grid.mcr by itself and it worked fine.

                                     

                                    3) I commented out the open, print, and close lines and uncommented the view.application.runmacro line and that works fine.

                                     

                                    4) I uncommented all the lines and now everything runs fine.

                                     

                                     

                                    I believe the trick is thatn in step #2 I loaded the macro file into PADS.  I deleted it from the macro list and ran it again and locked up PADS.  You need a step to load the macro before you run it.

                                    1 2 First Previous