Visual Studio.NET for AutoCAD Programmers

Similar documents
Unit 1: Visual Basic.NET and the.net Framework

TRAINING GUIDE FOR OPC SYSTEMS.NET. Simple steps to successful development and deployment. Step by Step Guide

To get started with Visual Basic 2005, I recommend that you jump right in

Developing Microsoft.NET Applications for Windows (Visual Basic.NET)

COPYRIGHTED MATERIAL. Visual Basic: The Language. Part 1

A NET Refresher

CT862 Section 1 Introduction

Skill Area 336 Explain Essential Programming Concept. Programming Language 2 (PL2)

Interacting with External Applications

UNIT 1. Introduction to Microsoft.NET framework and Basics of VB.Net

Welcome Application. Introducing the Visual Studio.NET IDE. Objectives. Outline

Developing Microsoft.NET Applications for Windows (Visual Basic.NET)

DEVELOPING OBJECT ORIENTED APPLICATIONS

GUI Design and Event- Driven Programming

1. Create your First VB.Net Program Hello World

Microsoft.NET: The Overview

Part I. Integrated Development Environment. Chapter 2: The Solution Explorer, Toolbox, and Properties. Chapter 3: Options and Customizations

Getting started 7. Setting properties 23

Upgrading Applications

INFORMATICS LABORATORY WORK #2

Introduction. In this preliminary chapter, we introduce a couple of topics we ll be using DEVELOPING CLASSES

Tutorial 03 understanding controls : buttons, text boxes

Getting Started With AutoCAD Civil 3D.Net Programming

Visual Basic 2008 The programming part

Chapter 2 Exploration of a Visual Basic.Net Application

CIS 3260 Intro. to Programming with C#

Microsoft Visual Basic 2005: Reloaded

Migration Made Easy! Speaker: Bud Schroeder, Autodesk Inc.

Fundamental C# Programming

Konark - Writing a KONARK Sample Application

Using the TekScope IVI-COM Driver from C#.NET

Learning VB.Net. Tutorial 19 Classes and Inheritance

Introduction to.net Framework and Visual Studio 2013 IDE MIT 31043, Rapid Application Development By: S. Sabraz Nawaz

IMS1906: Business Software Fundamentals Tutorial exercises Week 5: Variables and Constants

Darshan Institute of Engineering & Technology for Diploma Studies

Department of Computer Applications

ADO.NET 2.0. database programming with

Migrating from Autodesk Land Desktop to Autodesk Civil 3D CV42-3L

A Complete Tutorial for Beginners LIEW VOON KIONG

Custom Tables with the LandXML Report Extension David Zavislan, P.E.

Business Insight Authoring

A Quick Tour GETTING STARTED WHAT S IN THIS CHAPTER?

New programming language introduced by Microsoft contained in its.net technology Uses many of the best features of C++, Java, Visual Basic, and other

CS708 Lecture Notes. Visual Basic.NET Object-Oriented Programming. Implementing Client/Server Architectures. Part (I of?) (Lecture Notes 5A)

FOR 240 Homework Assignment 4 Using DBGridView and Other VB Controls to Manipulate Database Introduction to Computing in Natural Resources

2609 : Introduction to C# Programming with Microsoft.NET

Integrating Microsoft Access with AutoCAD VBA dave espinosa-aguilar Toxic Frog Multimedia

CX-Server OPC User Manual

VB.NET. Exercise 1: Creating Your First Application in Visual Basic.NET

Chapter 12 Microsoft Assemblies. Software Architecture Microsoft Assemblies 1

Building Windows Applications with.net. Allan Laframboise Shelly Gill

Event-based Programming

Text box. Command button. 1. Click the tool for the control you choose to draw in this case, the text box.

Programming Microsoft Visual C# 2005: The Base Class Library (Developer Reference) By Francesco Balena 196

Introduction to.net Framework and Visual Studio 2013 IDE MIT 31043, Visual Programming By: S. Sabraz Nawaz

Team Developer 6.1. Configure the color-coding in the Tools Preferences dialog under the Outline tab.

DOWNLOAD PDF VISUAL STUDIO 2008 LEARNING GUIDE

2. A GUI A. uses buttons, menus, and icons B. should be easy for a user to manipulate C. both (a) and (b) D. stands for Graphic Use Interaction

TRAINING GUIDE FOR OPC SYSTEMS.NET. Simple steps to successful development and deployment. Step by Step Guide

Introduction to Programming Microsoft.NET Framework Applications with Microsoft Visual Studio 2005 Course #MS4994A 5 Days COURSE OUTLINE

REVIEW OF CHAPTER 1 1

Appendix G: Writing Managed C++ Code for the.net Framework

CHAPTER 1 COPYRIGHTED MATERIAL. Finding Your Way in the Inventor Interface

Chapter. Web Applications

Working with AutoCAD in Mixed Mac and PC Environment

Microsoft Visual C++.NET Professional Projects By Sripriya

Chapter 12. OOP: Creating Object- Oriented Programs. McGraw-Hill. Copyright 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved.

Achieving Contentment with the AutoCAD Architecture Content Browser Douglas Bowers, AIA

IBM Rational Rhapsody Gateway Add On. User Manual

First Visual Basic Lab Paycheck-V1.0

Introduction to.net Framework Week 1. Tahir Nawaz

Lecture 10 OOP and VB.Net

Lab 4: Introduction to Programming

HOUR 4 Understanding Events

Introduction to Microsoft.NET Framework Programming using VS 2005 (C#)

Visual Basic Program Coding STEP 2

Visual Basic 2008 Anne Boehm

Revision for Final Examination (Second Semester) Grade 9

Departme and. Computer. CS Intro to. Science with. Objectives: The main. for a problem. of Programming. Syntax Set of rules Similar to.

Microsoft.NET Programming (C#, ASP.NET,ADO.NET, VB.NET, Crystal Report, Sql Server) Goal: Make the learner proficient in the usage of MS Technologies

PROGRAMMING WITH THE MICROSOFT.NET FRAMEWORK USING MICROSOFT VISUAL STUDIO 2005 Course No. MS4995A 5 Day PREREQUISITES COURSE OUTLINE

M Introduction to Visual Basic.NET Programming with Microsoft.NET 5 Day Course

Drawing an Integrated Circuit Chip

INSTALLATION GUIDE. Trimble PipeDesigner 3D Software

Introduction to.net Framework

Managing Content with AutoCAD DesignCenter

COPYRIGHTED MATERIAL. Part I The C# Ecosystem. ChapTEr 1: The C# Environment. ChapTEr 2: Writing a First Program

10262A VB: Developing Windows Applications with Microsoft Visual Studio 2010

Learning VB.Net. Tutorial 17 Classes

Developing Windows Applications with Microsoft Visual Studio 2010

The following are required to duplicate the process outlined in this document.

AutoCAD Plus: What You Get When You Add.NET!

Copyright. Trademarks Attachmate Corporation. All rights reserved. USA Patents Pending. WRQ ReflectionVisual Basic User Guide

Industrial Strength Add-Ins: Creating Commands in Autodesk Inventor

Getting started 7. Setting properties 23

M4.1-R4: APPLICATION OF.NET TECHNOLOGY

Las Vegas, Nevada, December 3 6, Kevin Vandecar. Speaker Name:

COPYRIGHTED MATERIAL. Starting Strong with Visual C# 2005 Express Edition

Program and Graphical User Interface Design

Visual Programming 1. What is Visual Basic? 2. What are different Editions available in VB? 3. List the various features of VB

Transcription:

December 2-5, 2003 MGM Grand Hotel Las Vegas Visual Studio.NET for AutoCAD Programmers Speaker Name: Andrew G. Roe, P.E. Class Code: CP32-3 Class Description: In this class, we'll introduce the Visual Studio.NET environment, including VB.NET, C#.NET, and C++.NET, and discuss how AutoCAD programmers can tap into the multi-language platform. Using.NET, developers have a new alternative to automate AutoCAD and more readily exchange code, develop Internetbased applications, and build more sophisticated programs. Class Outline: Introduction to VS.NET Overview of the.net Environment Building a.net Application Converting an Existing VB Application to.net Other Possibilities Getting More Information About the Speaker: Andrew G. Roe is a registered civil engineer and president of AGR Associates, Inc., a technology consulting firm based in Minneapolis, MN. He has over 18 years of experience in engineering, computer applications, and technical writing, and is the author of Using Visual Basic with AutoCAD, published by Autodesk Press. He has developed and documented custom applications for numerous clients, developed training material for Microsoft and Autodesk products, and written regularly for Engineering News-Record and CADENCE magazines. AGRoe@AGRassociates.com

Introduction to VS.NET What Is VS.NET? Visual Studio.NET is an integrated set of development tools for building custom applications using Visual Basic.NET, Visual C#.NET, Visual C++.NET, and Visual J#.NET. The same integrated development environment (IDE) is used for all programming languages, which allows developers to share components and build multi-language solutions..net is built around a common language specification (CLS), which provides the same services to individual languages. Why Use It? VS.NET offers several advantages over previous programming environments: State-of-the-Art Programming Tools Multi-Language Solutions Internet Applications Mobile Applications The Wave of the Future Why Use It With AutoCAD? Drive AutoCAD with Stand-alone Applications (COM Interface) Develop ObjectARX Applications (Visual Studio 2002 with AutoCAD 2004) Take Advantage of Advanced Programming Tools Use Components Developed in Multi-Language Environments Prepare for the Future Hurdles Learning Curve Cost Language Summary Chart Below is a brief summary of the various languages included in VS.NET. Language VB.NET C#.NET C++.NET J#.NET Predecessor Visual Basic -- C++ J++ Year Introduced 1990 2001 1983 1996 Key Characteristic Rapid Application Development (RAD) New Hybrid of C/C++ High-End Apps Web Apps 2

Overview of the.net Environment The IDE VS.NET provides a single IDE for all programming languages. It is similar to familiar IDEs such as that of Visual Basic 6.0, with a few differences. Some highlights: Form Designer Allows you to add controls to a form, arrange them, and write code for their events; much improved over VB 6, allowing you to easily resize, anchor, and dock forms; click tab above to switch to Code window. Properties window displays design-time properties and events of selected objects; click buttons above to sort and categorize. Solution Explorer Similar to the Project Explorer in VB; displays projects and their files; click buttons above to display code and forms. Toolbox displays controls and other items available for.net projects. The tabs and items available from the Toolbox change, depending upon the designer or editor currently in use. 3

Fundamentals Still Applicable While.NET includes numerous new concepts and tools, fundamentals from previous programming environments still apply. Here are some of the key terms of interest to AutoCAD programmers. Objects Generically Speaking In programming-speak, objects are building blocks for applications. Objects can be graphical items, such as forms, buttons, and text boxes, as well as code and data. In short, an object is something that acts as a unit. Objects AutoCAD Style In AutoCAD, a wide variety of application-specific objects are exposed, where they can be accessed programmatically. This includes tangible drawing objects, such as lines, arcs, and text, as well as other elements such as layers, groups, and viewports. These objects are all part of the AutoCAD Object Model. Discipline-specific products, such as Architectural Desktop, Land Desktop, and Mechanical Desktop, expose additional objects unique to each particular discipline. Properties and Methods Properties are attributes or characteristics of objects. Methods are functions that perform actions on an object. In a grammatical analogy, objects are nouns, properties are adjectives, and methods are verbs. Classes Classes are templates for creating objects. An object is a usable instance of a class. Each instance is a unique copy of its class. Events Events are actions recognized by an object. A mouse click is an event, as is the pressing of a key at the keyboard. AutoCAD has unique events, such as the modification of a drawing object and the saving of a drawing. Variables and Expressions Variables hold or store data in a specific memory location. Variables can represent numbers (Integer, Double, etc.), text (String), objects (Object, AcadLine, AcadText, etc.), dates (Date), and various other data types. Program Control and Logic While.NET offers some new twists in program control and logic, some of the familiar approaches still apply. For example, in VB.NET you still use the familiar If Then and Select Case structures to perform decision branching. Differences Between VB.NET and VB 6 (VB.NET is not VB 7!) Common Language Runtime (CLR) Source code is converted into Microsoft intermediate language (MSIL), a set of instructions that can be converted to native code. Some rework of the VB language was required to conform to CLS. Data Types Several new types; no more Variants; multiple variables declared on one line. 4 No Set Keyword Instead of Set MyObject =, it s just MyObject = Inheritance Allows you to define classes that serve as the basis for new classes. Exception Handling Replaces error handling; In VB. NET, Try Catch replaces On Error. Garbage Collection Automatically releases unused objects, optimizing memory management. Menu Editing Menus can be designed visually, much easier than in VB 6. Forms and Controls New IDE allows docking/anchoring of controls, unique controls, etc. Command Line Compiler Allows testing of code fragments outside the IDE. Others

Building a.net Application A VB.NET Example To demonstrate how to use.net with AutoCAD, the following example shows how to build a VB.NET application that starts AutoCAD, draws an AutoCAD entity, extracts some information about AutoCAD entities, and quits AutoCAD. 1. Start VS.NET to display the Start Page. 2. On the Start Page, click New Project to display the New Project dialog box. 3. In the New Project dialog box, select a project type of Visual Basic Projects, use the Windows Application template, specify a project name and location, and click OK. 4. In the Solution Explorer, right-click References and select Add Reference. 5

5. In the Add Reference dialog box, select the COM tab, then select AutoCAD 2004 type library. Click Select and OK to close the dialog box. 6. In the Code window, declare variables for the AutoCAD application object and a Boolean variable to track whether AutoCAD is running, as shown in the following code. Public Class Form1 Inherits System.Windows.Forms.Form Dim objacad As AutoCAD.AcadApplication Dim blnstarted As Boolean 7. In the Form Designer, insert four buttons named cmdconnect, cmddisconnect, cmddrawline, and cmdidentity, and arranged as shown below. 8. Double-click on the Connect to AutoCAD button and assign the code show below to it. This code checks to see if AutoCAD is running, and if not, starts it. Private Sub cmdconnect_click(byval sender As System.Object, ByVal e As _ System.EventArgs) Handles cmdconnect.click If blnstarted <> True Then Try objacad = GetObject(, "AutoCAD.Application.16") Catch exc As Exception objacad = CreateObject("AutoCAD.Application.16") End Try cmddisconnect.enabled = True cmddrawline.enabled = True cmdidentity.enabled = True blnstarted = True blnstarted = True MsgBox(objAcad.Name + vbcrlf + "Version " + objacad.version) objacad.visible = True End If End Sub 9. In a similar manner, assign the code shown below to the Quit AutoCAD button. This code executes the Quit method to close AutoCAD. Private Sub cmddisconnect_click(byval sender As System.Object, ByVal e As _ System.EventArgs) Handles cmddisconnect.click If blnstarted = True Then objacad.quit() objacad = Nothing Me.Close() End If End Sub 10. Assign the following code to the Draw Line button and allow the user to draw a line. 6

Private Sub cmddrawline_click(byval sender As System.Object, ByVal e As _ System.EventArgs) Handles cmddrawline.click Dim dblstartpoint(2) As Double Dim dblendpoint(2) As Double Dim objmyline As AutoCAD.AcadLine dblstartpoint(0) = 0 dblstartpoint(1) = 0 dblstartpoint(2) = 0 dblendpoint(0) = 5 dblendpoint(1) = 5 dblendpoint(2) = 0 objmyline = objacad.activedocument.modelspace.addline(dblstartpoint,_ dblendpoint) objacad.zoomextents() End Sub 11. Assign the following code to the ID Entity button and allow the user to determine an entity type. Private Sub cmdidentity_click(byval sender As System.Object, ByVal e As _ System.EventArgs) Handles cmdidentity.click Dim objent As AutoCAD.AcadEntity Dim objpoint As Object objacad.activedocument.utility.getentity(objent, objpoint, "Select _ an object.") MsgBox("The object name is: " & objent.objectname) End Sub 12. Add the following code to the Form Load event. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles MyBase.Load blnstarted = False cmddisconnect.enabled = False cmddrawline.enabled = False cmdidentity.enabled = False End Sub 13. Run the program and click the Start AutoCAD button to activate AutoCAD. 14. Click the Draw Line button to create a line, followed by the ID Entity button to obtain information about the entity. 15.Click the Quit AutoCAD button to close AutoCAD. The Same Example in C# To build the same example in C#, the procedure is similar. When selecting a project type, select Visual C# Projects. The equivalent code segments in C# are as follows. public class Form1 : System.Windows.Forms.Form private AcadApplication objacad; private AcadDocument objacaddoc; bool started; 7

private void cmdconnect_click(object sender, System.EventArgs e) if (started) return; try objacad=(acadapplication)marshal.getactiveobject("autocad.application.16"); started = true; catch try objacad = new AutoCAD.AcadApplicationClass(); objacad.visible = true; started = true; catch throw; cmddisconnect.enabled = true; cmddrawline.enabled = true; cmdidentity.enabled = true; private void cmddisconnect_click(object sender, System.EventArgs e) if(started) objacad.quit(); started = false; cmddisconnect.enabled = false; cmddrawline.enabled = false; cmdidentity.enabled = false; private void cmddrawline_click(object sender, System.EventArgs e) if (!started) return; double[] StartPoint = new double[3]; double[] EndPoint = new double[3]; StartPoint[0] = 0; StartPoint[1] = 0; StartPoint[2] = 0; EndPoint[0] = 5; EndPoint[1] = 5; EndPoint[2] = 0; objacad.activedocument.modelspace.addline(startpoint, EndPoint); objacad.zoomextents(); 8

private void cmdidentity_click(object sender, System.EventArgs e) Object objent = new Object(); Object objpoint = new Object(); objacad.activedocument.utility.getentity(out objent, out objpoint, "Select an object"); AcadEntity ent; ent = (AcadEntity)objEnt; MessageBox.Show("The object name is: " + ent.objectname); private void Form1_Load(object sender, System.EventArgs e) cmddisconnect.enabled = false; cmddrawline.enabled = false; cmdidentity.enabled = false; 9

Converting a VB Application to.net VB.NET includes an Upgrade Wizard to convert programs developed in VB 6.0. The steps for using the Upgrade Wizard are as follows. 1. Start VS.NET. From the File menu, select Open>Project. 2. In the Open Project dialog box, select a Visual Basic 6.0 project (.vbp) file. This launches the Visual Basic Upgrade Wizard. 3. Click Next to display the second page of the wizard, and choose from the available upgrade options. 4. On the third page of the wizard, enter the location where the new project will be created. 5. On the fourth page of the wizard, click Next to begin the upgrade process. 6. In Solution Explorer, double-click the _UpgradeReport.htm node to open the upgrade report. 7. Review the upgrade report and fix any errors. Examine warnings to ensure they do not affect application behavior. 8. On the Debug menu, choose Start. Run the application and make sure the behavior is the same as it was in Visual Basic 6.0. 10

Other Possibilities ObjectARX ObjectARX TM (AutoCAD Runtime Extension) is a compiled-language programming environment for developing AutoCAD applications. Using ObjectARX, you can create applications that run in the same address space as AutoCAD and operate directly with core AutoCAD data structures and code. This allows you to create custom AutoCAD objects and new commands that operate exactly the same way as native AutoCAD commands. You can use VS.NET to develop ObjectARX applications for AutoCAD 2004. VS.NET 2002 is the only version currently supported. VS.NET 2003 is not supported due to compatibility problems. You must use Visual C++ 6.0 when building ObjectARX applications for AutoCAD 2000, 2000i or 2002. Developing Multi-Language Applications Because the VS.NET framework provides a common application programming interface (API) for all of its programming languages, developers can choose which language to use. A VS.NET solution can contain components from multiple languages, meaning you could have a component developed in VB.NET, along with another component developed in C#.NET, and another developed in C++.NET all part of the same solution. On large projects with multiple developers skilled in different languages, this opens up new doors for collaboration. Internet Applications VS.NET greatly simplifies development of distributed Internet applications. It allows you to create Web Forms, which are used to create programmable Web pages. Using Web Forms, you can create Web pages by dragging and dropping controls onto the designer and then adding code, similar to the way that you create Visual Basic forms. VS.NET also allows you to create XML Web services applications that can receive requests and data using Extensible Markup Language (XML) over the Internet. XML provides a method for describing structured data and exchanging data across disparate applications. VS.NET includes an XML Designer to help edit XML and create XML schemas. Future Possibilities Autodesk is actively pursuing the development of a native.net interface for a future release of AutoCAD. This holds the promise of delivering the power of ObjectARX through the more userfriendly VB.NET. 11

Getting More Information Online Help The VS.NET online help system includes a vast amount of information about using the product, including sample code, links to Web sites, and more. Compared with earlier online help systems, it can be a bit intimidating initially due to the volume of information, but use it frequently to get comfortable with it. From the Help menu, select one of the following: Dynamic Help to get help on the current operation Contents a list of topics arranged hierarchically Index a list of topics arranged alphabetically Search to search for a specific topic or question Microsoft Web Sites Information can be found in several locations. A good starting place is the Microsoft Knowledge Base. http://support.microsoft.com/ Another is a special site set up for.net developers. http://www.gotdotnet.com/ Online videos are also available. http://msdn.microsoft.com/vbasic/using/migrating/default.aspx Autodesk Web Sites Autodesk-specific sites about.net are still in development, but some information is available on discussion groups and the Autodesk Support page. Autodesk Developer Network (ADN) members have access to additional information via the Knowledge Base for ADN members. http://discussion.autodesk.com/ (Discussion Groups) http://usa.autodesk.com/ (Support) Independent Web Sites A variety are available, and the landscape changes often. Use an Internet search engine to take a peek. Periodicals Electronic and print magazines are available. Here are a couple of popular ones. www.visualstudiomagazine.com (Visual Studio Magazine) www.devx.com/vsm/ (a clearinghouse of developer information) Books Many VS.NET books are available. Check your local bookstore or online source. 12