250 likes | 603 Views
EMBED AUTOACTIVE INTO YOUR CUSTOMERS FLOW September 2007. KENDALL HILES Sr. GLOBAL APPLICATIONS ENGINEER CONSULTANT GLOBAL SALES TEAM DURHAM, NC USA 919.484.2509 Kendall_Hiles@mentor.com. Agenda. Download Area Ample vs. Standard language
E N D
EMBED AUTOACTIVE INTO YOUR CUSTOMERS FLOWSeptember 2007 KENDALL HILES Sr. GLOBAL APPLICATIONS ENGINEER CONSULTANT GLOBAL SALES TEAMDURHAM, NC USA 919.484.2509 Kendall_Hiles@mentor.com
Agenda • Download Area • Ample vs. Standard language • What is in the Expedition Enterprise Auto Active Toolkit (AATK) • Startup Scripts/Environment Variables • Marketing Presentation • Demo • VB and Auto Completion KH, AutoActive Automation, September 2007
Before You Begin • Download the AATK slides and examples from SourceForge • http://sourceforge.net/projects/uwtoolbox/ • Look over the MGC standard examples in the release tree: • C:\MentorGraphics\2004\wg\win32\vbexppcb\Samples\Automation • C:\MentorGraphics\MGC_HOME-2004.ixn\pkgs\autoactivere\Samples\Automation • For 2004 You May need to set these environment variables MGC_ENABLE_AUTOMATION MGC_ENABLE_AUTOMATION_PRO MGC_ENABLE_PRO_FUNCTION_KEYS • F:\MentorGraphics\2005EXP\SDD_HOME\standard\examples\pcb\Automation • Read the help included in the tool • Load the AATK RTP Toolkit and use it KH, AutoActive Automation, September 2007
Scripting for Dummies • Use Visual Basic 6.0 ORMicrosoft Excel VB Editor to get started writing and debugging the bulk of your code (Some customers use VB.NET I have no experience with this tool) • Excel has almost the same functionality as VB 6.0 so users can get started before they buy it. • The IDE editor built into Expedition is the same as the editor in CES and Dx and it helps with the GUI but not the meat of the code. • Convert the VB to VBS and copy the code to the IDE editor and add a GUI. You need the PRO license to edit the IDE. (You can also do the GUI VB but then you will need to compile the VB into an exe to run it.) Source: Are in Arial. 8 Point, Italic. Place in this location. KH, AutoActive Automation, September 2007
VBS/VB/IDE LAB • In this lab you will learn • The differences between VBS and VB code • How to access the AutoActive Series Type Library for command completion in VB • How to access all the methods exposed in AutoActive • How to convert VB to VBS • How to create an IDE form and add the VBS code KH, AutoActive Automation, September 2007
VBS • VBS or Visual Basic Script • This is useful because you can drag and drop it onto an Expedition window. • For Linux/Unix you need to do type run xxx.vbs in the key in command window. If you put the script in one of the directories in your WDIR path there is no need to use a pathname. • It is hard to write in VBS because you have to read the manual to code KH, AutoActive Automation, September 2007
Copy a Standard Example • Copy this file to your $WDIR and Open for Edit MentorGraphics…\Automation\HelpSamples\Component_Move.vbs • Look over the script and notice the sections. • For the layout tools the license call is needed (Cost $) • Component_Move is the meat of the code • This line is not in a Function or Sub This is fine for VBS. It is what you the user wishes to do. • Call Component_Move ("R1",400.0,-600.0) • On you design find a component you want to move and hardcode values into the script and try it. KH, AutoActive Automation, September 2007
Adding a simple GUI in VBS • If all you want to do is add a simple GUI to ask the user for a Component, X location and Y location: Dim app Set app = GetObject(,"MGCPCB.Application") Dim Comp, X, Y Comp = app.GUI.Inputbox(“Component”, “R1”) X= app.GUI.Inputbox(“X”, “0”) Y= app.GUI.Inputbox(“Y”, “0”) Call Component_Move(Comp, X, Y) • Save the file and drag and drop onto the document • Make sure you comp/nets is not locked KH, AutoActive Automation, September 2007
Editing Made Easy • We will move it to VB, use the debugger to write the code then convert it back to VBS for ease of use • If you have VB6.0 use it • If you have Excel • Tools>Macro>Visual Basic Editor • In the Editor Insert>Module • Copy the whole file text • Paste into the Module KH, AutoActive Automation, September 2007
VB6.0 or Microsoft Excel • Lets add the AutoActive reference to get command completion • Right click on the Module window and open the Object Browser • Right click on the classes and open the References KH, AutoActive Automation, September 2007
VB6.0 or Microsoft Excel • Add the MGCPCB (AA Series) Type Library “OK”٧↓ • The Microsoft Scripting Runtime is needed if need to read or write to the file system • Open the MGCPCB Library • Browse the Class/Members ↓ • To view the code • Close the Object Browser or • Click on the Module in the Navigator • Adding the references enables the command completion which is the key to productivity in writing the VB code! KH, AutoActive Automation, September 2007
Editing VB Code • VB needs a Main to run so add a sub Main(), End Sub around the Testing Code part at the Bottom Sub Main() ' ' Testing code for the sample ' Dim app As MGCPCB.Application Set app = GetObject(,"MGCPCB.Application") Dim Comp, X, Y Comp = app.GUI.Inputbox(“Component”, “R1”) X= app.GUI.Inputbox(“X”, “0”) Y= app.GUI.Inputbox(“Y”, “0”) Call Component_Move(Comp, X, Y) End Sub • Setup the Auto completion part of VB. When you Dim a variable in VB set it to its class with the “As” statement Sub Component_Move(RefDes, X, Y) Dim app As MGCPCB.Application Dim docObj As MGCPCB.Document Dim resultMess Dim compObj As Component Set app = GetObject(, "MGCPCB.Application") … KH, AutoActive Automation, September 2007
Editing VB Code • Now go back to the section that you edited in VBS and re-type the lines again in VB with command completion Sub Main() ‘ This is a comment field ' Testing code for the sample ' Dim app As MGCPCB.Application Set app = GetObject(,"MGCPCB.Application") Dim Comp, X, Y Comp = app.GUI.Inputbox(“Component”, “R1”) X= app.GUI.Inputbox(“X”, “0”) Y= app.GUI.Inputbox(“Y”, “0”) Call Component_Move(Comp, X, Y) End Sub • See how the command completion works. • Try it again • In the Sub Component_move section re-type any of the lines that have variable that are set to Dim xxx AS yyyy KH, AutoActive Automation, September 2007
Editing VB Code • As you play with the code you can see how the Auto completion helps. If you need more info on Methods and Classes use the Object Browser and you can search through the added Library. KH, AutoActive Automation, September 2007
Debugging VB Code • Turn on the debug toolbar in VB • View>Toolbars>Debug • Roll the mouse over the Icons to see the help. I use the function keys to control it but you can use either. • F5 = Run • F8 = Step Into • F9 = Toggle Breakpoint • Turn on the Locals window • Put a breakpoint on a line KH, AutoActive Automation, September 2007
Debugging VB Code • Run the code • You may have to pop Expedition to the top and answer the GUI questions • When it stops look at the locals • Use F8 to step into the code and watch the variables change • Play with the code and get familiar with the debug environment KH, AutoActive Automation, September 2007
Saving VB • If you are running in Excel just save the Excel workbook and the code will be preserved with the Type Library references • To save it as a .vbs you will need to copy the text to a file and name it xxx.vbs • If you are in VB6.0 Personally I do like saving the VB project because it creates a lot of overhead. I use the File>Save and re-write the xxx.vbs file but every time you open it you will need to add the Type Library references. • In VB6.0 you can create a form and compile your code as an .exe file to distibute. But it will only work on windows platfoms. KH, AutoActive Automation, September 2007
Converting Back to VBS for Drag and Drop or Menu Calls • In VBS you need to add a call to Main OR Comment Out the Sub Main() ‘Sub Main() ' ' Testing code for the sample ……. Call Component_Move(RefDes, X, Y) ‘End Sub Or Main Sub Main() ' ' Testing code for the sample ……. Call Component_Move(RefDes, X, Y) End Sub KH, AutoActive Automation, September 2007
Converting Back to VBS for Drag and Drop or Menu Calls • Comment out the AS … Since VBS can’t use the object classes Sub Component_Move(RefDes, X, Y) Dim app ‘As MGCPCB.Application Dim docObj ‘As MGCPCB.Document Dim resultMess Dim compObj ‘As Component Set app = GetObject(, "MGCPCB.Application") … • Drag your saved script onto an Expedition document to test it. Edit any lines that cause the script to fail. KH, AutoActive Automation, September 2007
Adding an IDE Form • Open a new Script Form from AutoActive • Choose VBScript KH, AutoActive Automation, September 2007
Adding an IDE Form • Add 3 Text Boxes • Add Text to Describe Each Box • Add a Button Labeled “Apply” • Click on the View Code Icon add paste your VBS code KH, AutoActive Automation, September 2007
Adding an IDE Form • Double click on each of the blank Text boxes and give them defaults. Sub EditBox1_EventInitialize() Dim This : Set This = EditBox1 this.Text = "R?" End Sub Sub EditBox2_EventInitialize() Dim This : Set This = EditBox2 this.Text = “0" End Sub Sub EditBox3_EventInitialize() Dim This : Set This = EditBox3 this.Text = “0" End Sub • You can name each of the boxes if you like to make the coding easy but, in my case • EditBox1 = RefDes • EditBox2 = X • EditBox3 = Y KH, AutoActive Automation, September 2007
Adding an IDE Form • Double Click on the Apply Button and add the following Code. You will notice Form attributes to have auto complete but the General Code does not. Sub Button1_EventClick() Dim This : Set This = Button1 ‘Call Component_Move(EditBox1.text, EditBox2.text+1-1, EditBox3.text+1-1) Call Component_Move(EditBox1.text, Cint(EditBox2.text), Cint(EditBox3.text)) End Sub • The + 1 – 1 you may see in some of the code is the same as Cint, it changes a text string to an integer KH, AutoActive Automation, September 2007
Adding an IDE Form • Click on the Run Button and see what happens! • Run Time Error? • Click End and it will go to the line of code in Error KH, AutoActive Automation, September 2007
Running Scripts • If written correctly most VBS can be dragged onto Expedition or run from a Form • VB can be compiled into an executable (.exe) file • .efm form can be dragged or run from the menu with the Open Script Form. It also can be compiled for security. KH, AutoActive Automation, September 2007