{"id":1284,"date":"2012-12-10T21:39:12","date_gmt":"2012-12-10T16:09:12","guid":{"rendered":"http:\/\/mohamediqbalp.wordpress.com\/?p=1284"},"modified":"2012-12-10T21:39:12","modified_gmt":"2012-12-10T16:09:12","slug":"autocad-with-net-2","status":"publish","type":"post","link":"https:\/\/venusimportexport.com\/wordpress\/index.php\/2012\/12\/10\/autocad-with-net-2\/","title":{"rendered":"AutoCAD with .NET 2"},"content":{"rendered":"<h1>Lesson 2: Getting to Know your Development Environment<\/h1>\n<div class=\"columns\">\n<table class=\"columns\">\n<tbody>\n<tr>\n<td class=\"col1\">\n<div id=\"section1\" class=\"section normal\">\n<p>In<br \/> the previous lesson, you saw how you can increase productivity in <br \/>AutoCAD by implementing a plug-in built from a small amount of Visual <br \/>Basic .NET code. <\/p>\n<p style=\"text-align:left;\" align=\"left\">.NET (or<br \/> the .NET Framework) is a technology created by Microsoft that enables <br \/>programmers to create and extend software applications. A programmer may<br \/> use the ,NET Framework to create a new software application from <br \/>scratch, to implement communication or interoperability between two <br \/>software applications, or to extend a software application by <br \/>implementing a plug-in for it (as you are doing here for AutoCAD). If <br \/>you are interested in learning more, you will find information in the <a href=\"http:\/\/usa.autodesk.com\/adsk\/servlet\/index?siteID=123112&amp;id=18171347#at\">Additional Topics<\/a>&nbsp;section.<\/p>\n<p style=\"text-align:left;\" align=\"left\">You will now look more closely at what happened when you built and executed the code in the previous lesson.<\/p>\n<\/div>\n<\/td>\n<td class=\"col2\">\n<div id=\"section2\" class=\"section normal\">\n<div style=\"background:#ececec;padding:10px;\"><b>Provide Feedback<\/b>: Please provide feedback about this AutoCADTraining or this lesson via email: <a href=\"mailto:myfirstplugin@autodesk.com?subject=My%20First%20AutoCAD%20Plug-in%20Feedback\">myfirstplugin@autodesk.com<\/a> <\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div id=\"section3\" class=\"section normal\">\n<p class=\"columnheader\"><b>What does it mean to \u201cbuild\u201d code?<\/b><\/p>\n<p style=\"text-align:left;\" align=\"left\">The code you typed into Visual Basic Express in Lesson 1 was a set of human-readable instructions (<i>source<\/i><br \/> code) that needed to be converted into code that could be understood <br \/>and executed by the computer. The \u201cbuild\u201d you performed did just that: <br \/>it packaged up the resulting executable code into a <i>DLL<\/i> (Dynamic-Link Library) that can be loaded into AutoCAD.<\/p>\n<p>The<br \/> following screenshot shows the output in DLL form along with the <br \/>associated program debug database (which provides additional information<br \/> when troubleshooting the DLL) that you built using Visual Basic Express<br \/> in Lesson 1. The path to where the DLL gets compiled is specified in <br \/>the Visual Basic Express project settings and is set, by default, to the<br \/> binRelease or binDebug sub-folder of the Visual Basic Express project<br \/> folder (depending if you\u2019re building a Release or Debug version of your<br \/> DLL \u2013 we\u2019ll talk about that later).<\/p>\n<p><img fetchpriority=\"high\" decoding=\"async\" src=\"http:\/\/images.autodesk.com\/adsk\/images\/Image-2-1.gif\" alt=\"\" height=\"104\" width=\"560\" \/><\/p>\n<\/div>\n<div class=\"clear\"> <\/div>\n<div id=\"section4\" class=\"section normal\">\n<p class=\"columnheader\">Choosing a Programming Language and Development Tool<\/p>\n<p style=\"text-align:left;\" align=\"left\">Just<br \/> as humans use different languages to communicate, you have various <br \/>language options available to you when creating an AutoCAD plug-in:&nbsp; for<br \/> the purposes of this guide we have chosen Visual Basic .NET, a strong <br \/>general-purpose programming language. Visual Basic .NET is particularly <br \/>popular with people learning to program, because the language syntax is <br \/>more easily readable than many other languages (such as C# or C++). <\/p>\n<p style=\"text-align:left;\" align=\"left\">There<br \/> are a number of tools available for developing Visual Basic .NET code. <br \/>They range from open source tools such as SharpDevelop and MonoDevelop <br \/>to Microsoft\u2019s flagship, professional development environment, Visual <br \/>Studio. This tutorial assumes you\u2019re using Visual Basic Express, a free <br \/>version of Visual Studio for building Visual Basic .NET applications.<\/p>\n<p style=\"text-align:left;\" align=\"left\">Visual Basic Express is an <i>Integrated Development Environment<\/i> (IDE) because it is composed of various tools, menus and toolbars which ease the creation and management of your code. <\/p>\n<p style=\"margin:0 0 10pt;\">The project system in Visual Basic Express comprises <i>Solution <\/i>and <i>Project<\/i> files as well as <i>Project Items<\/i>,<br \/> the individual files belonging to projects. A solution is a container <br \/>for one or more projects. Each project can in turn be considered a <br \/>container for project items \u2013 such as source files, icons, etc. \u2013 most <br \/>of which get compiled into the resultant executable file (EXE or DLL). <br \/>Visual Basic Express provides a Solution Explorer that organizes and <br \/>displays the contents of the loaded solution in a tree-view format:<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/images.autodesk.com\/adsk\/images\/Image-2-2.gif\" alt=\"\" height=\"441\" width=\"617\" \/><\/p>\n<p style=\"text-align:left;\" align=\"left\">The<br \/> Visual Basic Express interface also contains a text editor and <br \/>interface designer. These are displayed in the main window depending on <br \/>the type of file being edited. The text editor is where you will enter <br \/>the Visual Basic .NET code for your AutoCAD plug-in. This editor <br \/>provides advanced features such as IntelliSense and collapsible code <br \/>sections along with the more classic text-editing features such as <br \/>bookmarks and the display of line numbers.<\/p>\n<p style=\"text-align:left;\" align=\"left\"><i>IntelliSense<\/i><br \/> is an extremely valuable feature of the Visual Studio family that <br \/>greatly improves programmer productivity: it automatically provides <br \/>suggestions for the code being written based on the objects available <br \/>and the letters that are being typed. You will have already seen <a>IntelliSense <\/a>at work if you typed in the code in Lesson 1. That is one reason we suggested you didn\u2019t copy and paste. <\/p>\n<p style=\"text-align:left;\" align=\"left\">Clearly<br \/> one of the key features of Visual Basic Express is its ability to build<br \/> Visual Basic .NET code into an executable file. During the build <br \/>process, the language compiler performs various checks and analyses on <br \/>the code. One such check is to ensure the code conforms to the <br \/>syntactical rules of the Visual Basic .NET language. The compiler also <br \/>performs various other checks, such as whether a variable has been <br \/>appropriately defined or not. Detected errors are reported via the Error<br \/> List window, typically found at the bottom of the main window. If you <br \/>made a mistake typing in the code in lesson 1, you may already have seen<br \/> this when you tried to build your plug-in.<\/p>\n<p style=\"text-align:left;\" align=\"left\"><img decoding=\"async\" src=\"http:\/\/images.autodesk.com\/adsk\/images\/Image-2-3.gif\" alt=\"\" height=\"394\" width=\"617\" \/><\/p>\n<\/div>\n<div class=\"clear\"> <\/div>\n<div id=\"section5\" class=\"section normal\">\n<p class=\"columnheader\">Reviewing your use of Visual Basic Express <\/p>\n<p style=\"text-align:left;\" align=\"left\">In<br \/> this section, you will review the steps performed using Visual Basic <br \/>Express from the previous lesson. However, we will put them in the <br \/>context of what you have just learned about programming in general and <br \/>building your code. <\/p>\n<ol start=\"1\">\n<li>In the first step, you simply launched Visual Basic Express.\n<\/li>\n<li>You then created a new Visual Basic .NET project of type <b>AutoCAD plug-in<\/b>. This project template was added when you installed the AutoCAD .NET Wizards.\n<p>Since<br \/> the development language used for this guide is Visual Basic .NET, you <br \/>are working with Visual Basic Express, and therefore you see <b>Visual Basic<\/b> under the <b>Installed Templates<\/b> portion of the <b>New Project<\/b> dialog. The <b>AutoCAD plug-in template<\/b> is essentially a <b>Class Library<\/b> template, but with some additional settings.<\/p>\n<p>In<br \/> the middle section of this dialog, you saw various types of <br \/>applications that can be created; you select the template according to <br \/>the type of application you wish to create.<\/p>\n<p>The nam<br \/>\ne you entered at the bottom of the dialog is used to identify the project within the solution.<\/p>\n<\/li>\n<li>Your<br \/> blank project was created, containing a few standard project references<br \/> to core .NET components along with references to the two files that <br \/>define the AutoCAD API (AcMgd.dll and AcDbMgd.dll). The project also <br \/>includes two Visual Basic .NET class files (<b>MyCommands.vb<\/b> and <b>MyPlugin.vb<\/b> &#8211; you may have optionally deleted the <i>MyPlugin.vb<\/i><br \/> file from the project because it\u2019s not needed for this tutorial). These<br \/> files contained some simple boilerplate code. Clicking on one of those <br \/>files in Solution Explorer displays the code it contains in the text <br \/>editor window.\n<\/li>\n<li>You looked at the References section of the \u2018My Project\u2019 project settings and checked that <b>AcDbMgd.dll<\/b> and <b>AcMgd.dll<\/b> were correctly referenced (and AcCoreMdg.dll for AutoCAD 2013 and higher).<\/li>\n<li>Saving<br \/> the solution created physical files representing the contents of your <br \/>project on the computer\u2019s hard drive, allowing you to open and edit it <br \/>at another time in the future. You closed and reopened the project to <br \/>ensure Visual Basic Express had correctly parsed the project files.\n<\/li>\n<li><i>AcMgd.dll<\/i> and <i>AcDbMgd.dll<\/i><br \/> contain definitions of the AutoCAD APIs you will most commonly use in <br \/>your plug-ins. You will always reference these two files in your AutoCAD<br \/> plug-in projects. You will sometimes reference others too.\n<ul>\n<li><i>AcMgd.dll <\/i>contains the APIs for controlling the AutoCAD application itself \u2013 defining custom commands <br \/>opening and closing documents, plotting, etc.<\/li>\n<li><i>AcDbMgd.dll <\/i>contains the APIs for creating, editing or querying the contents of a DWG file.<\/li>\n<li>From<br \/> AutoCAD 2013, the APIs in AcMdg.dll were split between AcMgd.dll and <br \/>AcCoreMgd.dll. AcCoreMgd.dll contains APIs related to the AutoCAD <br \/>application login (such as selections set, comamnds and keywords), and <br \/>AcMgd.dll contains \u2018User Interface\u2019 related APIs (such as dialogs).<\/li>\n<\/ul>\n<p>When<br \/> you created your AutoCAD plug-in project, the AutoCAD .NET Wizard <br \/>Configurator dialog had these selected by default (you can\u2019t unselect <br \/>them). There were options to include other API definition files that we <br \/>ignored.<\/p>\n<\/li>\n<li>Next you added Visual Basic .NET code using the<br \/> AutoCAD API into your project. In other words providing AutoCAD with <br \/>instructions on how to modify how a block attribute behaves when it is <br \/>rotated. <\/li>\n<\/ol>\n<p>While developing code, it\u2019s a good idea to build <br \/>the solution from time to time, to check whether errors have been <br \/>introduced in the code. The code does not necessarily have to be <br \/>complete or functional when building the solution. This approach can <br \/>help avoid potentially lengthy troubleshooting once the code is <br \/>complete, and has the side benefit of automatically saving any edited <br \/>source files before the build starts.<\/p>\n<p style=\"text-align:left;\" align=\"left\">To build a solution inside Visual Basic Express, select <b>Build Solution<\/b> from the <b>Debug<\/b> pull-down menu.<\/p>\n<p>If the build process was successful, you would see a <b>Build Succeeded<\/b><br \/> status in the bottom left corner of the Visual Basic Express <br \/>application frame. If there was an error in your code, Visual Basic <br \/>Express will display an error list explaining the errors it has found. <br \/>It will also underline the error in your code in blue.&nbsp; Here\u2019s an <br \/>example where we deliberately added a mistake to the code you typed in <br \/>lesson one:<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/images.autodesk.com\/adsk\/images\/Image-2-3.gif\" alt=\"\" height=\"394\" width=\"617\" \/><\/p>\n<p style=\"text-align:left;\" align=\"left\">In<br \/> this lesson you took a brief look at what happens when you build a <br \/>project, as well as some background information on Visual Basic .NET and<br \/> Visual Basic Express. You reviewed the steps you had taken in the <br \/>previous lesson to build your basic AutoCAD plug-in, putting it in the <br \/>context of what you have learned about programming.<\/p>\n<\/div>\n<div class=\"clear\"> <\/div>\n<div id=\"section6\" class=\"section normal\"><a name=\"at\"><\/a><\/p>\n<p id=\"at\" class=\"columnheader\"><b>Additional Topics<\/b><\/p>\n<\/div>\n<div class=\"clear\"> <\/div>\n<div id=\"section7\" class=\"section normal\">\n<h3>Visual Basic Express vs. Visual Studio Professional<\/h3>\n<p style=\"text-align:left;\" align=\"left\">In<br \/> this guide, you are using Visual Basic Express. This is a free version <br \/>of Visual Studio and so it\u2019s a great tool to start learning with. <br \/>Microsoft has targeted the Express editions of Visual Studio at <br \/>students, hobbyists and other part-time programmers. While it provides <br \/>most of the features of Visual Studio Professional, such as <br \/>IntelliSense, it does have certain limitations. For instance, it <br \/>contains fewer project templates and has limited options for debugging <br \/>and troubleshooting your code. If you are serious about plug-in <br \/>development beyond this introductory guide \u2013 and particularly if you <br \/>want to start developing commercial plug-ins \u2013 we recommend investing in<br \/> one of the more fully-featured members of the Visual Studio product <br \/>family.<\/p>\n<p style=\"text-align:left;\" align=\"left\"><i>*There are several \u2018professional\u2019 versions of Visual Studio. Visit the <\/i><a href=\"http:\/\/www.microsoft.com\/visualstudio\"><i>Microsoft Visual Studio website<\/i><\/a><i> for more information.<\/i><\/p>\n<\/div>\n<div class=\"clear\"> <\/div>\n<div id=\"section8\" class=\"section normal\">\n<h3>What is .NET?<\/h3>\n<p style=\"text-align:left;\" align=\"left\"><i>The<br \/> remainder of this lesson includes quite a bit of technical jargon. <br \/>Don\u2019t worry if you don\u2019t completely understand it all when you first <br \/>read it. It will make more sense once you\u2019ve become more familiar with <br \/>.NET after writing a few of your own plug-ins.<\/i><\/p>\n<p style=\"text-align:left;\" align=\"left\">The<br \/> .NET Framework is a software framework that sits on top of the <br \/>Microsoft\u00ae Windows\u00ae operating system* and provides the underlying <br \/>platform, libraries and services for all .NET applications. The services<br \/> include memory management, garbage collection, common type system, <br \/>class libraries, etc.<\/p>\n<p><i>* Subsets of .NET are also available on <br \/>other operating systems, whether via the open source Mono project or via<br \/> Microsoft\u00ae Silverlight\u00ae, but these are not topics for this guide. You <br \/>will focus solely on using.NET on Microsoft Windows.<\/i><\/p>\n<\/div>\n<div class=\"clear\"> <\/div>\n<div id=\"section9\" class=\"section normal\">\n<h3>What does the .NET Framework Contain?<\/h3>\n<p id=\"clr\">The framework contains two main components: <\/p>\n<ol start=\"1\">\n<li><b>Common Language Runtime (CLR)<\/b> \u2013 <span style=\"color:#232323;\">This<br \/> is the agent (or execution engine) in the .NET Framework responsible <br \/>for managing the execution of code. Which is why code written to target <br \/>this runtime is also known as managed code. All managed code runs under <br \/>the supervision of the CLR, but what does this mean? The CLR manages <br \/>code by providing core services such as memory management (which <br \/>includes automatically releasing the computer\u2019s memory for reuse on <br \/>other tasks when it is no longer needed), error (or exception) handling,<br \/> managing the use of multiple threads of execution and ensuring rules <br \/>around the use of different types of object are adhered to. The CLR is <br \/>really the foundation of the .NET Framework.<\/span>\n<\/li>\n<li><b><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms229335.aspx\"><b>.NET Framework Class Library<\/b><\/a><\/b> \u2013 <span style=\"color:#232323;\">As<br \/> the name suggests, this is a library or collection of object types that<br \/> can be used from your own code when developing .NET applications. These<br \/> .NET applications&nbsp;are targeted fo<br \/>\nr Windows (whether command-prompt <br \/>based or with a graphical user interface), the web or mobile devices. <br \/>This library is available to all languages using the .NET Framework.<\/span> <\/li>\n<\/ol>\n<p><span style=\"color:#232323;\">As<br \/> mentioned above, the CLR improves code robustness by making sure the <br \/>executing code conforms to a common type system (CTS). The CTS ensures <br \/>that all .NET (or managed) code \u2013 irrespective of the language \u2013 uses a <br \/>similar set of object types and can work together in the same <br \/>environment. It is this feature that makes it possible for you to write <br \/>applications in the development language of your choice and yet make use<br \/> of components\/code written by programmers using other .NET languages.<\/span><\/p>\n<\/div>\n<div class=\"clear\"> <\/div>\n<div id=\"section10\" class=\"section normal\">\n<h3>Building Executables<\/h3>\n<p style=\"margin:0 0 10pt;background:white;\">When<br \/> you built your code into an EXE, it was compiled into Common <br \/>Intermediate Language (CIL \u2013 also known as MSIL) code using the <br \/>language-specific compiler. CIL is a CPU-independent set of instruction <br \/>that can be executed by the CLR on Windows operating systems. CIL is <br \/>typically portable across 32- and 64-bit systems and even \u2013 to some <br \/>extent \u2013 to non-Windows operating systems. The CIL code generated from <br \/>your VB source code was then packaged into a .NET assembly. Such an <br \/>assembly is a library of CIL code stored in Portable Executable (PE) <br \/>format (which contains both the CIL and its associated metadata). <br \/>Assemblies can either be process assemblies (EXEs) or library assemblies<br \/> (DLLs).<\/p>\n<p style=\"background:white;\">During the course of this <br \/>guide, you will focus on developing a particular type of AutoCAD <br \/>plug-in: a process assembly (EXE) which communicates with AutoCAD. <br \/>Because of the overhead associated with developing them, you will not <br \/>spend time looking at AutoCAD AddIns, which are usually library <br \/>assemblies (DLLs) that get loaded into and executed within the memory <br \/>space of AutoCAD. One reason that implementing an EXE to work with <br \/>AutoCAD is simpler than developing an AddIn is related to its user <br \/>interface: Executables do not need to integrate seamlessly with the <br \/>AutoCAD user interface by adding ribbon buttons (for instance).<\/p>\n<\/div>\n<div class=\"clear\"> <\/div>\n<h3>Running Executables<\/h3>\n<table border=\"0\">\n<tbody>\n<tr>\n<td><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/images.autodesk.com\/adsk\/images\/Lesson2-0.jpg\" alt=\"\" height=\"428\" width=\"250\" \/><\/td>\n<td valign=\"top\">\n<p>During<br \/> execution of a .NET assembly, CIL (residing in the assembly) is passed <br \/>through the CLR\u2019s just-in-time (JIT) compiler to generate native (or <br \/>machine) code. JIT compilation of the CIL to native code occurs when the<br \/> application is executed. As not all of the code is required during <br \/>execution, the JIT compiler only converts the CIL when it is needed, <br \/>thus saving time and memory. It also stores any generated code in <br \/>memory, making it available for subsequent use without the need to <br \/>recompile. <\/p>\n<p>In the last step of this process, the native code gets executed by the computer\u2019s processor. <\/p>\n<p>If you would like more details on the process of building .NET applications, please refer to the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/k5532s8a.aspx\">MSDN Library<\/a><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<blockquote>\n<p><\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Lesson 2: Getting to Know your Development Environment In the previous lesson, you saw how you can increase productivity in AutoCAD by implementing a plug-in built from a small amount of Visual Basic .NET code. .NET (or the .NET Framework) is a technology created by Microsoft that enables programmers to create and extend software applications.&hellip; <br \/> <a class=\"read-more\" href=\"https:\/\/venusimportexport.com\/wordpress\/index.php\/2012\/12\/10\/autocad-with-net-2\/\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-1284","post","type-post","status-publish","format-standard","hentry","category-islam"],"_links":{"self":[{"href":"https:\/\/venusimportexport.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/1284","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/venusimportexport.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/venusimportexport.com\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/venusimportexport.com\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/venusimportexport.com\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=1284"}],"version-history":[{"count":0,"href":"https:\/\/venusimportexport.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/1284\/revisions"}],"wp:attachment":[{"href":"https:\/\/venusimportexport.com\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=1284"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/venusimportexport.com\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=1284"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/venusimportexport.com\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=1284"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}