xpcb layout automation and scripting · vbscript basics — variables ..... 38. table of contents...

12
2016 Mentor Graphics Corporation All rights reserved. This document contains information that is trade secret and proprietary to Mentor Graphics Corporation or its licensors and is subject to license terms. No part of this document may be photocopied, reproduced, translated, distributed, disclosed or provided to third parties without the prior written consent of Mentor Graphics. xPCB ® Layout Automation and Scripting Student Workbook

Upload: buikhanh

Post on 24-Jul-2018

247 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: xPCB Layout Automation and Scripting · VBScript Basics — Variables ..... 38. Table of Contents xPCB Layout Automation and Scripting II Expressions Summary

2016 Mentor Graphics Corporation

All rights reserved.

This document contains information that is trade secret and proprietary to Mentor Graphics Corporation or its licensors and

is subject to license terms. No part of this document may be photocopied, reproduced, translated, distributed, disclosed or

provided to third parties without the prior written consent of Mentor Graphics.

xPCB® Layout Automation and Scripting

Student Workbook

Page 2: xPCB Layout Automation and Scripting · VBScript Basics — Variables ..... 38. Table of Contents xPCB Layout Automation and Scripting II Expressions Summary

This document is for information and instruction purposes. Mentor Graphics reserves the right to make changes

in specifications and other information contained in this publication without prior notice, and the reader should, in

all cases, consult Mentor Graphics to determine whether any changes have been made.

The terms and conditions governing the sale and licensing of Mentor Graphics products are set forth in written

agreements between Mentor Graphics and its customers. No representation or other affirmation of fact

contained in this publication shall be deemed to be a warranty or give rise to any liability of Mentor Graphics

whatsoever.

MENTOR GRAPHICS MAKES NO WARRANTY OF ANY KIND WITH REGARD TO THIS MATERIAL

INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS

FOR A PARTICULAR PURPOSE.

MENTOR GRAPHICS SHALL NOT BE LIABLE FOR ANY INCIDENTAL, INDIRECT, SPECIAL, OR

CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING BUT NOT LIMITED TO LOST PROFITS)

ARISING OUT OF OR RELATED TO THIS PUBLICATION OR THE INFORMATION CONTAINED IN IT, EVEN

IF MENTOR GRAPHICS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

U.S. GOVERNMENT LICENSE RIGHTS: The software and documentation were developed entirely at private

expense and are commercial computer software and commercial computer software documentation within the

meaning of the applicable acquisition regulations. Accordingly, pursuant to FAR 48 CFR 12.212 and DFARS

48 CFR 227.7202, use, duplication and disclosure by or for the U.S. Government or a U.S. Government

subcontractor is subject solely to the terms and conditions set forth in the license agreement provided with the

software, except for provisions which are contrary to applicable mandatory federal laws.

TRADEMARKS: The trademarks, logos and service marks ("Marks") used herein are the property of Mentor

Graphics Corporation or other parties. No one is permitted to use these Marks without the prior written consent

of Mentor Graphics or the owner of the Mark, as applicable. The use herein of a third- party Mark is not an

attempt to indicate Mentor Graphics as a source of a product, but is intended to indicate a product from, or

associated with, a particular third party. A current list of Mentor Graphics’ trademarks may be viewed at:

www.mentor.com/trademarks.

End-User License Agreement: You can print a copy of the End-User License Agreement from:

www.mentor.com/eula.

Mentor Graphics Corporation

8005 S.W. Boeckman Road, Wilsonville, Oregon 97070-7777

Telephone: 503.685.7000

Toll-Free Telephone: 800.592.2210

Website: www.mentor.com

SupportNet: supportnet.mentor.com/

Send Feedback on Documentation: supportnet.mentor.com/doc_feedback_form

Part Number: 073510

Page 3: xPCB Layout Automation and Scripting · VBScript Basics — Variables ..... 38. Table of Contents xPCB Layout Automation and Scripting II Expressions Summary

Table of Contents

xPCB Layout Automation and Scripting I

Module 1: Introduction ...................................................................................... 11

Objectives ........................................................................................................................................... 12

Note .................................................................................................................................................... 13

Course Key Topics ............................................................................................................................. 14

Terminology ....................................................................................................................................... 15

What Is Automation? ......................................................................................................................... 16

What can I do With Automation?....................................................................................................... 17

How can You Use Automation? ......................................................................................................... 18

What Products Support Automation? ................................................................................................. 19

Supported Platforms ........................................................................................................................... 20

Languages ........................................................................................................................................... 21

Automation Clients ............................................................................................................................ 22

Launching VX Applications ............................................................................................................... 25

Versioned Automation ....................................................................................................................... 26

Scripting Tools ................................................................................................................................... 28

Help .................................................................................................................................................... 29

SupportNet – Login/Register ............................................................................................................. 30

Module 1 Lab: Introduction to Scripting ............................................................................................ 31

Module 2: Basic Scripting Concepts ................................................................. 33

Objectives ........................................................................................................................................... 34

Note .................................................................................................................................................... 35

Overview VBSCRIPT versus Visual Basic ....................................................................................... 36

PCB Script Elements Overview ......................................................................................................... 37

VBScript Basics — Variables ............................................................................................................ 38

Page 4: xPCB Layout Automation and Scripting · VBScript Basics — Variables ..... 38. Table of Contents xPCB Layout Automation and Scripting II Expressions Summary

Table of Contents

xPCB Layout Automation and Scripting II

Expressions Summary ........................................................................................................................ 41

VBScript I/O — Message/Input Boxes .............................................................................................. 42

VBScript Basics — Miscellaneous .................................................................................................... 44

VBScript Basics — Conditional Script Control ................................................................................. 46

For...Each and While...Wend — Examples........................................................................................ 49

If/Then/Else and For...Next Example ................................................................................................. 50

Select Case Example .......................................................................................................................... 51

VBScript Basics – Functions and Subroutines ................................................................................... 52

VBScript I/O — FileSystemObject .................................................................................................... 53

Error Checking ................................................................................................................................... 54

String Manipulations .......................................................................................................................... 55

String Manipulations — Example ...................................................................................................... 56

String Manipulations — Results ........................................................................................................ 57

Module 2 Lab: Basic Scripting ........................................................................................................... 58

Module 3: Environment/GUI Customizations .................................................. 59

Objectives ........................................................................................................................................... 60

Startup Scripts .................................................................................................................................... 61

scripts.ini Directory Search ................................................................................................................ 62

Scripts.ini File Format ........................................................................................................................ 63

Scripts.ini File Format Example ......................................................................................................... 64

Scripts.ini File Search Rules .............................................................................................................. 66

Scripts.ini File – File Types Executed ............................................................................................... 68

Using the Run Command ................................................................................................................... 69

Using the WDIR Variable .................................................................................................................. 70

WDIR and xDX Designer (Except DxDesigner.xml) ........................................................................ 71

Page 5: xPCB Layout Automation and Scripting · VBScript Basics — Variables ..... 38. Table of Contents xPCB Layout Automation and Scripting II Expressions Summary

Table of Contents

xPCB Layout Automation and Scripting III

Searching for DxDesigner.xml Support File ...................................................................................... 72

Keybindings ....................................................................................................................................... 73

Keybinding Files ................................................................................................................................ 74

Shortcut Key Modifiers ...................................................................................................................... 75

Connecting to the Key Binding Server .............................................................................................. 76

Xpedition xPCB Layout Keybinding File Example ........................................................................... 77

xDX Designer Keybinding File Example .......................................................................................... 78

Module 3 Lab 3.1: Startup Scripts ..................................................................................................... 79

Command Bar Server ......................................................................................................................... 80

Command Bar Server — Objects ....................................................................................................... 81

Connecting to the Command Bar Server ............................................................................................ 82

Adding a New Menu .......................................................................................................................... 83

Adding a Command to a Menu .......................................................................................................... 84

Command Execution .......................................................................................................................... 85

Adding a Separator ............................................................................................................................. 86

Adding a Sub Menu ............................................................................................................................ 87

"Graying Out" User Menu Items ........................................................................................................ 89

Deleting a Command .......................................................................................................................... 90

Example in Context – Xpedition xPCB Menu Bar ............................................................................ 91

Example in Context – xDX Designer ................................................................................................. 93

Summary: Adding Menu Entries ....................................................................................................... 94

Module 3 Lab 3.2: Scripting Menu Changes ..................................................................................... 95

Toolbars .............................................................................................................................................. 96

Adding an Xpedition xPCB Toolbar Button ...................................................................................... 97

Adding a xDX Designer Toolbar Button ........................................................................................... 98

Page 6: xPCB Layout Automation and Scripting · VBScript Basics — Variables ..... 38. Table of Contents xPCB Layout Automation and Scripting II Expressions Summary

Table of Contents

xPCB Layout Automation and Scripting IV

Toolbar — Command Execution ....................................................................................................... 99

Summary: Adding Toolbar Icons .................................................................................................... 101

Things to Consider ........................................................................................................................... 102

Acquiring Environment Information ................................................................................................ 103

WDIR Acquisition and Disassemble ................................................................................................ 104

Locate/Confirm File Exists in WDIR ............................................................................................... 105

Create FileSystem Object for Copy ................................................................................................. 106

Quick Reference: xDX Designer Menus .......................................................................................... 107

Quick Reference: xDX Designer Toolbars - Default ....................................................................... 108

Quick Reference: xDX Designer Toolbars - Classic........................................................................ 109

Quick Reference: xDX Designer – Addins ...................................................................................... 110

Quick Reference – Xpedition xPCB Layout .................................................................................... 118

Quick Reference: Xpedition xPCB Layout – Toolbars .................................................................... 119

CommandBarButton Object Model Summary ................................................................................. 123

Module 3 Lab 3.3: Working with Toolbars ...................................................................................... 124

Module 4: Object Programming ..................................................................... 125

Objectives ......................................................................................................................................... 126

Terminology ..................................................................................................................................... 127

Type Library ..................................................................................................................................... 129

Object Browsers ............................................................................................................................... 130

VBA Object Browser — xDX Designer Example ........................................................................... 132

Objects .............................................................................................................................................. 134

Collections ........................................................................................................................................ 136

xPCB Layout Example — Input/Output/Collections ....................................................................... 139

LockServer (PCB Only) ................................................................................................................... 140

Page 7: xPCB Layout Automation and Scripting · VBScript Basics — Variables ..... 38. Table of Contents xPCB Layout Automation and Scripting II Expressions Summary

Table of Contents

xPCB Layout Automation and Scripting V

Finding Objects ................................................................................................................................ 141

Finding Objects – xPCB Layout Example ....................................................................................... 142

Example – xPCB Layout Object Data .............................................................................................. 144

Transactions (PCB Only) ................................................................................................................. 145

Transactions — Example 1 .............................................................................................................. 147

Transactions — Example 2 .............................................................................................................. 148

Automation Licensing ...................................................................................................................... 149

Review — Script Initialization Constructs ....................................................................................... 150

Review — Conditional Script Control ............................................................................................. 151

Review — Objects and Collections ................................................................................................. 152

Review — Input/Output/File System ............................................................................................... 153

Review — Xpedition xPCB Layout Licensing Construct................................................................ 154

Module 4 Lab: Object Programming ............................................................................................... 155

Module 5: Designing and Creating Forms ...................................................... 157

Objectives ......................................................................................................................................... 158

Integrated Development Environment (IDE) ................................................................................... 159

Accessing Form Files ....................................................................................................................... 161

Creating a New Form — xDX Designer .......................................................................................... 162

Opening a Form — xDX Designer .................................................................................................. 163

Creating a New Form – xPCB Layout ............................................................................................. 164

Opening a Form – xPCB Layout ...................................................................................................... 165

Creating/Editing Form Graphics ...................................................................................................... 166

Types of Widgets ............................................................................................................................. 167

Widget Usage ................................................................................................................................... 168

Widget Properties ............................................................................................................................. 169

Page 8: xPCB Layout Automation and Scripting · VBScript Basics — Variables ..... 38. Table of Contents xPCB Layout Automation and Scripting II Expressions Summary

Table of Contents

xPCB Layout Automation and Scripting VI

Widget Events .................................................................................................................................. 170

Graphic/Code Statements Suggestions ............................................................................................. 171

Form Example – Graphics Properties .............................................................................................. 172

Form Example – Subroutines ........................................................................................................... 173

Module 5 Lab: Creating and Using Forms ....................................................................................... 174

Module 6: xPCB Layout Output Engines ....................................................... 175

Objectives ......................................................................................................................................... 176

Note .................................................................................................................................................. 177

Manufacturing Engines .................................................................................................................... 178

Currently Supported Manufacturing Engines................................................................................... 179

Future Engines .................................................................................................................................. 180

Common Script Concepts ................................................................................................................. 181

Add Engine Library Type Examples ................................................................................................ 182

Create the Engine Object .................................................................................................................. 183

COM Version ................................................................................................................................... 184

Example Script Gerber Export — Using Predefined Setups ............................................................ 185

Some Gerber Export Statements — No Predefined Setups ............................................................. 186

Gerber Output Files .......................................................................................................................... 187

Module 6 Lab: Scripting Output Engines ........................................................................................ 188

Module 7: xPCB Layout .................................................................................. 189

Objectives ......................................................................................................................................... 190

PCB Automation in a Nutshell ......................................................................................................... 191

Type Libraries .................................................................................................................................. 192

Acquiring the Server in VBScript .................................................................................................... 193

PCB Automation Data Model .......................................................................................................... 195

Page 9: xPCB Layout Automation and Scripting · VBScript Basics — Variables ..... 38. Table of Contents xPCB Layout Automation and Scripting II Expressions Summary

Table of Contents

xPCB Layout Automation and Scripting VII

PCB Automation Hierarchy ............................................................................................................. 196

Geometry Object .............................................................................................................................. 199

Typical Script Beginnings ................................................................................................................ 200

Automation Licensing ...................................................................................................................... 201

Document Licensing ........................................................................................................................ 202

Code Example — InputBox/Component Collection ........................................................................ 203

Output Result of InputBox/Component Collection .......................................................................... 204

Code Example/Output Results — Net Collection Labels ................................................................ 205

Review VBScript I/O — FileSystemObject ..................................................................................... 206

Code Example — Net/Refdes/Pin Report ........................................................................................ 207

Output Result of Net/Refdes/Pin Report .......................................................................................... 209

Filters ................................................................................................................................................ 210

Non-Filtered Statements ................................................................................................................... 211

Filtering Statements .......................................................................................................................... 212

Filter Enumerator Example Statements ............................................................................................ 213

Example Code Not Using a Filter .................................................................................................... 214

Example Code Using a Filter ........................................................................................................... 215

Module 7 lab 7A: Basic xPCB Layout Scripting ............................................................................. 216

Adding/Modifying Data ................................................................................................................... 217

PutVia Example ................................................................................................................................ 218

PutVia Example — Status Bar and TransactionStart ....................................................................... 219

PutVia Example — Operate on the Via ........................................................................................... 220

PutVia Example — Error Handlers and Prompted For Exit ............................................................ 221

PutVia Example — TransactionEnd ................................................................................................ 222

xPCB Events .................................................................................................................................... 223

Page 10: xPCB Layout Automation and Scripting · VBScript Basics — Variables ..... 38. Table of Contents xPCB Layout Automation and Scripting II Expressions Summary

Table of Contents

xPCB Layout Automation and Scripting VIII

Events — Infinite Loop .................................................................................................................... 225

Example Code — Event; OnSelectionChange ................................................................................. 226

Available Pick Methods ................................................................................................................... 229

Pick Methods Statements ................................................................................................................. 230

Pick Object Example ........................................................................................................................ 231

Pick Components Example .............................................................................................................. 232

Command Object .............................................................................................................................. 233

Motion Graphics ............................................................................................................................... 234

Motion Graphics Form ..................................................................................................................... 235

Motion Graphics and Command Object Example ........................................................................... 236

Writing to the Xpedition xPCB Layout Status Bar .......................................................................... 241

Writing to the Status Bar — Example Code /Result ........................................................................ 242

Other Useful Objects and Methods .................................................................................................. 243

Accessing Other Editors ................................................................................................................... 244

Review .............................................................................................................................................. 245

Module 7 Lab: Working with Events ............................................................................................... 246

Module 8: xDX Designer .................................................................................. 247

Objectives ......................................................................................................................................... 248

Typical xDX Designer Script Tasks ................................................................................................. 249

xDX Designer Automation in a Nutshell ......................................................................................... 250

xDX Designer Type Library............................................................................................................. 251

Acquiring the Server in VBScript .................................................................................................... 252

xDX Designer Automation Data Model ........................................................................................... 254

xDX Designer Automation Hierarchy .............................................................................................. 255

xDX Designer Automation — Accessing Design Data ................................................................... 258

Page 11: xPCB Layout Automation and Scripting · VBScript Basics — Variables ..... 38. Table of Contents xPCB Layout Automation and Scripting II Expressions Summary

Table of Contents

xPCB Layout Automation and Scripting IX

xDX Designer Automation Model Overview .................................................................................. 259

Typical Script Beginnings ................................................................................................................ 260

Automation Licensing ...................................................................................................................... 261

Scopes ............................................................................................................................................... 262

Working With Queries ..................................................................................................................... 263

Schematic Page – Decision Tree ...................................................................................................... 264

Code Example – Sheet Component Collection ................................................................................ 265

Flat Design Traversal — Decision Tree ........................................................................................... 267

Code Example – Multi-Sheet Acquiring Net Labels........................................................................ 268

Hierarchical Design Traversal - Decision Tree ................................................................................ 271

Example Code — Hierarchical Traversal ........................................................................................ 272

Enumerations .................................................................................................................................... 288

xDX Designer Filters ....................................................................................................................... 289

Adding/Deleting Objects in xDX Designer...................................................................................... 290

Modifying Objects in xDX Designer ............................................................................................... 291

xDX Designer Events ....................................................................................................................... 292

xDX Designer Events – Members .................................................................................................... 294

xDX Designer Events – Script Example .......................................................................................... 295

xDX Designer Events – User Created Commands ........................................................................... 296

xDX Designer Events – Register/Bind Command Example ............................................................ 297

xDX Designer Events – UnRegister Command Example ................................................................ 298

xDX Databook Events ...................................................................................................................... 299

Loading a Script for xDX Databook ................................................................................................ 300

xDX Databook Example .................................................................................................................. 301

The Viewport Object ........................................................................................................................ 303

Page 12: xPCB Layout Automation and Scripting · VBScript Basics — Variables ..... 38. Table of Contents xPCB Layout Automation and Scripting II Expressions Summary

Table of Contents

xPCB Layout Automation and Scripting X

The Viewport Object – Example Code ............................................................................................ 304

The Viewport Object – Example Code Results................................................................................ 305

Other Useful Application Controls .................................................................................................. 306

Status Bar ......................................................................................................................................... 307

VBScript I/O - FileSystemObject .................................................................................................... 308

Module 8 Lab: xDX Designer Scripting .......................................................................................... 309