Transcription of Programming with - Amazon S3
1 BC105 BONUS CHAPTER 4 Programming with .NET IN THIS CHAPTER Understanding .NET and autocad Creating code Using the command line to obtain user input Using dialog boxes to obtain complex user input Modifying objects using constants and functions Troubleshooting errors .NET is an application development platform that allows you to create applications using pro-gramming languages like Visual ( ) or C# (pronounced C sharp). is an evolution of the Visual Basic and Visual Basic for Applications (VBA) Programming lan-guages. Unlike VBA, the development environment is stand-alone and not part of an applica-tion like Microsoft Word or autocad .
2 Prior to deploying .NET applications, you need to install the .NET Framework on all computers that will run your programs. Fortunately, autocad installs the .NET Framework if it is not already on your computer, because several commands in autocad require the .NET Framework. LAYERS, CUI, and EATTEXT are examples. autocad ONLY autocad LT does not support .NET or VBA. This entire chapter applies to autocad only. NOTE While VBA is still available in autocad 2015 , Autodesk no longer installs it by default. If you want to use and develop VBA applications, you can download and install the VBA module from . On the website, choose the file for your operating system.
3 After installing the VBA enabler, VBA commands and functions work as they did in previous releases. The reason for this change is because Microsoft had dropped VBA support for third-party developers. is ideal for situations in which you need to work with more than one application at a time because it supports .NET APIs and ActiveX. (API is short for application Programming interface.) APIs are used to store common classes and methods that you can use to create your own programs. We talk about classes and methods later in this chapter. VBA and ActiveX, which we discuss in Bonus Chapter 3 , enables you to access autocad objects in other applications.
4 This chapter introduces you to BC1058/6/2014 12:25:32 PM8/6/2014 12:25:32 PMBC106 Programming with .NETand shows how you can start to use this powerful language to customize autocad . For more infor-mation, see the sidebar, Using ActiveX with . As previously mentioned, Visual ( ) is a variation of Visual Basic (VB). You must compile code into a stand-alone executable program or as an assembly (DLL) file that you can load into another program. When working with .NET and autocad , you compile your project into an assembly file. does have a learning curve if you re not familiar with it, but once you get past that, you will find that it is a simple way to extend the behavior of autocad and automate complex tasks.
5 Starting to Work with After you decide to program autocad , the first step is to select a Programming language to use. In this chapter, you ll be using Visual ( ). has the following advantages: is faster than AutoLISP and VBA, even when AutoLISP is compiled. is a standard Programming language, so you are more likely to find other pro-grammers who know , compared to those with an understanding of AutoLISP. Companies with an IT or IS department most likely have skilled individuals that are famil-iar with If you ve used VB or VBA before, you should find that you can transfer your existing knowledge to learning is generally easier to learn than AutoLISP because of its syntax and the numerous learning resources available.
6 On the other hand, AutoLISP and VBA have the advantage of backward compatibility with prior autocad releases in many situations. Of course, if you re familiar with AutoLISP but not with , it s hard to beat the ease of working with a language that you already know. programs are saved in projects. A project contains references to all the required parts nec-essary to load and execute the program in autocad . Once you load a assembly into autocad , you use the defined commands and AutoLISP functions just like you would use native commands and AutoLISP functions in autocad . Before you get started, you need to install Microsoft Visual Studio 2013 or Microsoft Visual Studio 2013 Express for Windows Desktop.
7 Which one you install and use will most likely depend on the following: Cost. Microsoft Visual Studio 2013 Express for Windows Desktop is free, while you must purchase Microsoft Visual Studio 2013 after a 90-day trial to continue using it. Features. While Microsoft Visual Studio 2013 Express for Windows Desktop and Microsoft Visual Studio 2013 are similar, Microsoft Visual Studio 2013 Express for Windows Desktop is targeted at hobby programmers and not professional developers. As a result, it lacks fea-tures that are designed to create applications for the cloud, Microsoft SharePoint, and Windows Phone. There are other differences between the two.
8 For a full comparison of the two development environments, visit the Microsoft website ( ) and do a search on Visual Studio 2013 Editions. BC1068/6/2014 12:25:37 PM8/6/2014 12:25:37 PMBC107 B O N U S 4 Programming with .NET Support. Even though you can use Microsoft Visual Studio 2013 Express for Windows Desktop or Microsoft Visual Studio 2013, only Microsoft Visual Studio 2012 is officially supported. If you encounter an issue while using Microsoft Visual Studio 2013 Express for Windows Desktop, you will not get support from Autodesk. NOTE While Microsoft Visual Studio 2013 should work just fine for building custom autocad applications, Microsoft Visual Studio 2012 is the officially supported development platform.
9 This chapter covers using Microsoft Visual Studio 2013 Express for Windows Desktop, but all con-cepts also apply to Microsoft Visual Studio 2012 and Microsoft Visual Studio 2013. To download and install Microsoft Visual Studio 2013 Express for Windows Desktop, follow these steps: 1 . Go to . 2 . On the Visual Studio Express page, under the Express 2013 for Windows Desktop section, click the Download link. 3 . On the Downloads page, from the Download Language drop-down list, select English or the language you want to install. 4 . Click Install Now. 5 . Log into your Microsoft Live account or create an account if needed.
10 6 . Fill out the form and click the Express 2013 for Windows Desktop link. 7 . Click the security banner and click Run. You might need to click Download File before you can click Run. 8 . Follow the prompts for the installation process. For example, you must accept the license terms. Opening the environment To start working with , you must first open the environment. Like AutoLISP with the Visual LISP Editor or VBA with the Visual Basic for Applications Editor, has its own interface. projects are a collection of files that define your program, from functions that perform a specific task to a Windows form (dialog box).