Mastering AutoCAD VBA

698 2K 4
Mastering AutoCAD VBA

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Mastering ™ AutoCAD ® VBA San Francisco • Paris • Düsseldorf • Soest • London Marion Cottingham 2871Frontmatter.qxd 3/30/01 8:42 AM Page v 2871Frontmatter.qxd 3/30/01 8:42 AM Page iv Mastering AutoCAD VBA 2871Frontmatter.qxd 3/30/01 8:42 AM Page iii 2871Frontmatter.qxd 3/30/01 8:42 AM Page iv Mastering ™ AutoCAD ® VBA San Francisco • Paris • Düsseldorf • Soest • London Marion Cottingham 2871Frontmatter.qxd 3/30/01 8:42 AM Page v Associate Publisher: Cheryl Applewood Contracts and Licensing Manager: Kristine O’Callaghan Acquisitions and Developmental Editor: Raquel Baker Editor: Carol Henry Production Editor: Nathan Whiteside Technical Editor: Steve Hansen Book Designer: Franz Baumhackl Electronic Publishing Specialist: Jill Niles Proofreaders: Nancy Riddiough, Nanette Duffy, Laurie O’Connell, Emily Hsuan Indexer: Ted Laux CD Coordinator: Erica Yee CD Technician: Kevin Ly Cover Designer: Design Site Cover Illustrator: Sergei Loobkoff, Design Site Copyright © 2001 SYBEX Inc., 1151 Marina Village Parkway, Alameda, CA 94501. World rights reserved. The author created reusable code in this publication expressly for reuse by readers. Sybex grants readers limited permission to reuse the code found in this publication or its accompanying CD-ROM so long as author is attributed in any application containing the reusabe code and the code itself is never distributed, posted online by electronic transmission, sold, or commercially exploited as a stand-alone product. Aside from this specific exception concerning reusable code, no part of this publication may be stored in a retrieval system, transmitted, or reproduced in any way, including but not limited to photocopy, photo- graph, magnetic, or other record, without the prior agreement and written permission of the publisher. Library of Congress Card Number: 2001087093 ISBN: 0-7821-2871-8 SYBEX and the SYBEX logo are either registered trademarks or trademarks of SYBEX Inc. in the United States and/or other countries. Mastering is a trademark of SYBEX Inc. Screen reproductions produced with FullShot 99. FullShot 99 © 1991-1999 Inbit Incorporated. All rights reserved. FullShot is a trademark of Inbit Incorporated. Internet screen shots using Microsoft Internet Explorer 5.5 reprinted by permission from Microsoft Corporation. TRADEMARKS: SYBEX has attempted throughout this book to distinguish proprietary trademarks from descriptive terms by following the capitalization style used by the manufacturer. The author and publisher have made their best efforts to prepare this book, and the content is based upon final release software whenever possible. Portions of the manuscript may be based upon pre-release versions supplied by software manufacturer(s). The author and the publisher make no representation or warranties of any kind with regard to the com- pleteness or accuracy of the contents herein and accept no liability of any kind including but not limited to performance, merchantability, fitness for any particular purpose, or any losses or damages of any kind caused or alleged to be caused directly or indirectly from this book. Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 2871Frontmatter.qxd 3/30/01 8:42 AM Page vi The media and/or any online materials accompanying this book that are available now or in the future contain programs and/or text files (the “Software”) to be used in connection with the book. SYBEX hereby grants to you a license to use the Software, subject to the terms that follow. Your purchase, acceptance, or use of the Software will constitute your acceptance of such terms. The Software compilation is the property of SYBEX unless other- wise indicated and is protected by copyright to SYBEX or other copyright owner(s) as indicated in the media files (the “Owner(s)”). You are hereby granted a single-user license to use the Software for your personal, noncommercial use only. You may not reproduce, sell, distribute, publish, circulate, or commercially exploit the Soft- ware, or any portion thereof, without the written consent of SYBEX and the specific copyright owner(s) of any component software included on this media. In the event that the Software or components include specific license requirements or end-user agreements, statements of con- dition, disclaimers, limitations or warranties (“End-User License”), those End-User Licenses supersede the terms and conditions herein as to that particular Software component. Your purchase, accept- ance, or use of the Software will constitute your acceptance of such End-User Licenses. By purchase, use or acceptance of the Software you further agree to comply with all export laws and regulations of the United States as such laws and regulations may exist from time to time. Reusable Code in This Book The authors created reusable code in this publication expressly for reuse for readers. Sybex grants readers permission to reuse for any purpose the code found in this publication or its accompanying CD-ROM so long as all three authors are attributed in any appli- cation containing the reusable code, and the code itself is never sold or commercially exploited as a stand-alone product. Software Support Components of the supplemental Software and any offers associ- ated with them may be supported by the specific Owner(s) of that material but they are not supported by SYBEX. Information regard- ing any available support may be obtained from the Owner(s) using the information provided in the appropriate read.me files or listed elsewhere on the media. Should the manufacturer(s) or other Owner(s) cease to offer sup- port or decline to honor any offer, SYBEX bears no responsibility. This notice concerning support for the Software is provided for your information only. SYBEX is not the agent or principal of the Owner(s), and SYBEX is in no way responsible for providing any support for the Software, nor is it liable or responsible for any sup- port provided, or not provided, by the Owner(s). Warranty SYBEX warrants the enclosed media to be free of physical defects for a period of ninety (90) days after purchase. The Software is not available from SYBEX in any other form or media than that enclosed herein or posted to www.sybex.com. If you discover a defect in the media during this warranty period, you may obtain a replacement of identical format at no charge by sending the defec- tive media, postage prepaid, with proof of purchase to: SYBEX Inc. Customer Service Department 1151 Marina Village Parkway Alameda, CA 94501 (510) 523-8233 Fax: (510) 523-2373 e-mail: info@sybex.com WEB: HTTP://WWW.SYBEX.COM After the 90-day period, you can obtain replacement media of iden- tical format by sending us the defective disk, proof of purchase, and a check or money order for $10, payable to SYBEX. Disclaimer SYBEX makes no warranty or representation, either expressed or implied, with respect to the Software or its contents, quality, per- formance, merchantability, or fitness for a particular purpose. In no event will SYBEX, its distributors, or dealers be liable to you or any other party for direct, indirect, special, incidental, consequen- tial, or other damages arising out of the use of or inability to use the Software or its contents even if advised of the possibility of such damage. In the event that the Software includes an online update feature, SYBEX further disclaims any obligation to provide this fea- ture for any specific duration other than the initial posting. The exclusion of implied warranties is not permitted by some states. Therefore, the above exclusion may not apply to you. This warranty provides you with specific legal rights; there may be other rights that you may have that vary from state to state. The pricing of the book with the Software by SYBEX reflects the allocation of risk and limitations on liability contained in this agreement of Terms and Conditions. Shareware Distribution This Software may contain various programs that are distributed as shareware. Copyright laws apply to both shareware and ordinary commercial software, and the copyright Owner(s) retains all rights. If you try a shareware program and continue using it, you are expected to register it. Individual programs differ on details of trial periods, registration, and payment. Please observe the requirements stated in appropriate files. Copy Protection The Software in whole or in part may or may not be copy-protected or encrypted. However, in all cases, reselling or redistributing these files without authorization is expressly forbidden except as specif- ically provided for by the Owner(s) therein. Software License Agreement: Terms and Conditions 2871Frontmatter.qxd 3/30/01 8:42 AM Page vii 2871Frontmatter.qxd 3/30/01 8:42 AM Page viii To all my students, past and present, who have inspired me more than they’ll ever know. —Marion Cottingham 2871Frontmatter.qxd 3/30/01 8:42 AM Page ix 2871Frontmatter.qxd 3/30/01 8:42 AM Page x [...]... ADVANTAGES OF USING VBA WITH AUTOCAD Advantages of Using VBA with AutoCAD Visual Basic for Applications (VBA) is a programming environment created by Microsoft that is built into applications to automate operations It provides tools that you can drag and drop to build a graphical user interface (GUI), and a programming language that you can use to interact with AutoCAD objects Using VBA with AutoCAD allows... VBA and have already written some successful VBA code, you may want to skip this chapter—or even just skim over the entire Part I, depending on your experience The material covered in Chapter 4, VBA Programming Concepts,” will always be useful to you as a reference This chapter covers the following topics: • Advantages of using VBA with AutoCAD • The AutoCAD VBA environment • Developing your first application... Contents Introduction xxiii Part 1 • VBA Macros and the Visual Basic Editor 1 Chapter 1 • Developing a Simple VBA Application 3 Advantages of Using VBA with AutoCAD 5 The AutoCAD VBA Environment 6 Creating UserForm Modules ... standalone application, except that it can only be opened from the AutoCAD window and does not remain open after AutoCAD has been closed The term VBA Editor is often used synonymously with the IDE even though the IDE provides more than just editing features The VBA IDE can be opened from the AutoCAD window in a variety of ways: • Type vbaide next to the command prompt in the command line • Choose Tools... Page 1 Part 1 VBA Macros and the Visual Basic Editor In This Part Chapter 1: Developing a Simple VBA Application 3 Chapter 2: Creating VBA Macros 29 Chapter 3: Quick Tour of the IDE 53 Chapter 4: VBA Programming Concepts 79 2871c01.qxd 3/19/01 9:20 AM Page 2 2871c01.qxd 3/19/01 9:20 AM Page 3 Developing a Simple VBA Application... 567 Using AutoCAD with Other Applications 567 Dragging Objects into AutoCAD 567 Using ActiveX Controls in Macros 569 Exchange between AutoCAD and Excel 569 Saving Line Data to an Excel Spreadsheet 570 Drawing an AutoCAD Line from Excel 573 Exchange between AutoCAD and Word... 2871Frontmatter.qxd xxiv 3/30/01 8:42 AM Page xxiv INTRODUCTION same tasks from VBA code, and how to enhance AutoCAD by customizing additional interfaces that make it easier to perform some tasks To the reader who wants to learn how to code macros in VBA, this book assumes no prior knowledge of VBA or any other programming language It is the ideal book for AutoCAD users to learn how to write code to automate routine... complex such as AutoCAD itself Another not-so-obvious advantage of learning AutoCAD VBA is that your skills are transferable to a growing number of other applications that have VBA capability These applications include all those in the Microsoft Office family of applications, such as Access, Word, and Excel, in addition to Microsoft Visual Basic itself and about two hundred other licensees VBA interfaces... successfully developed VBA code that works in the ways you want it to, it’s guaranteed to perform correctly and reliably each time you run it Now there’s an incentive to learn VBA! So let’s begin by examining the interface where you will write your code—the Visual Basic Editor The AutoCAD VBA Environment The Visual Basic Editor is the integrated environment in which you develop all your VBA code As you can... your very own macros and applications that run inside AutoCAD To the reader who has VBA programming experience from other applications, you’ll learn about the numerous objects and collections that AutoCAD has to offer and the methods and properties these contain Since most examples show how to perform a task first from the AutoCAD window and then from VBA code, readers with no coding experience will quickly . 3/30/01 8:42 AM Page iv Mastering AutoCAD VBA 2871Frontmatter.qxd 3/30/01 8:42 AM Page iii 2871Frontmatter.qxd 3/30/01 8:42 AM Page iv Mastering ™ AutoCAD ® VBA San Francisco • Paris • Düsseldorf. Mastering ™ AutoCAD ® VBA San Francisco • Paris • Düsseldorf • Soest • London Marion Cottingham 2871Frontmatter.qxd 3/30/01 8:42 AM Page v 2871Frontmatter.qxd 3/30/01 8:42 AM Page iv Mastering AutoCAD VBA 2871Frontmatter.qxd. . . . . . . . . . . . . . . . . . 3 Advantages of Using VBA with AutoCAD . . . . . . . . . . . . . . . . . . . . . . . . 5 The AutoCAD VBA Environment . . . . . . . . . . . . . . . . . . . .

Ngày đăng: 09/07/2014, 09:22

Mục lục

  • Contents

  • Introduction

    • Who Should Read This Book

    • What You Can Do with VBA

    • What’s In This Book

    • AutoCAD Versions Compatible with This Book

    • Conventions Used in This Book

    • What’s On the CD-ROM

    • Part I: VBA Macros and the Visual Basic Editor

      • Chapter 1: Developing a Simple VBA Application

        • Advantages of Using VBA with AutoCAD

        • The AutoCAD VBA Environment

        • Developing Your First Application

        • Chapter 2: Creating VBA Macros

          • What Is a Macro?

          • Creating a Macro to Add Text to a Drawing

          • Using VBA’s Date and Time Functions

          • Loading VBA Project Files

          • Starting an Application from a Macro

          • Summary

          • Chapter 3: Quick Tour of the IDE

            • VBA IDE Components

            • Printing UserForms

            • Overview of the Code Commands

            • Getting Help

Tài liệu cùng người dùng

Tài liệu liên quan