AutoCAD Programming using C# with Windows Forms | Arnold H. | Skillshare

AutoCAD Programming using C# with Windows Forms

Arnold H., Sr. Software Developer, MCSD, MCAD

AutoCAD Programming using C# with Windows Forms

Arnold H., Sr. Software Developer, MCSD, MCAD

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
21 Lessons (2h 41m)
    • 1. Welcome

    • 2. Section 1 - List of Topics

    • 3. Section 1 - Introduction

    • 4. Section 1 - Who is this course for

    • 5. Section 1 - Tools

    • 6. Section 2 - What will you learn

    • 7. Section 3 - Windows Form and Controls - Overview

    • 8. Section 3 - Identify Project Requirement

    • 9. Section 3 - Creating the Project

    • 10. Section 3 - Designing the User Interface

    • 11. Section 3 - Creating the ControlDemoUtility Class

    • 12. Section 3 - Coding the Combobox Control

    • 13. Section 3 - Coding the Textbox Control

    • 14. Section 3 - Coding the Radiobutton Control

    • 15. Section 3 - Coding the Checkbox Control

    • 16. Section 4 - DevelopingProjects Intro

    • 17. Section 4 - CreateRectangle Project - Overview

    • 18. 02 CreatingRectangleUtilClass

    • 19. 03 CreatingForm

    • 20. 04 CodingTheRectangleForm

    • 21. 05 RunningRectangleForm

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.





About This Class

This course will show you how to develop an application/plugin using Windows Forms in AutoCAD.

Meet Your Teacher

Teacher Profile Image

Arnold H.

Sr. Software Developer, MCSD, MCAD


Hello, I'm Arnold.

See full profile

Class Ratings

Expectations Met?
  • Exceeded!
  • Yes
  • Somewhat
  • Not really
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Your creative journey starts here.

  • Unlimited access to every class
  • Supportive online creative community
  • Learn offline with Skillshare’s app

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.



1. Welcome: welcome to the score's alto called programming using C sharp. Within those forms, there are many ways to customize AutoCAD and extend its functionalities. You can use Italy's BB, a object, a Rx and many more but developing plug ins using C sharp and when those form is one of my favorite combination off developing applications, not only you can automate processes, but also you can design a user interface that your users we love with Windows forms. You have lots of different controls to choose from that you can easily drag and drop into your form. So join me in the scores and learned this invaluable technology to further your AutoCAD programming skills. I'll see you inside. 2. Section 1 - List of Topics: Hello there. Thank you for taking the scores and welcome. This will be the topics that we're going to cover in the scores in section One introduction where we will list out some benefits off developing up hot plug ins. You sing with those forms. We will also identify who is discourse for and determine the tools that we will be needing in this course in section two. We will identify what will you learn from this course? And in section three, we will develop a plugging that will demonstrate the usage off, many different with those controls. And in Section four, this is the section where we will be spending significant amount of time. We will develop six different rial world Duggan's that you can use for your projects. You are free to use the code however you like, and Trickett accordingly to suit your requirements. And finally we will conclude the course. So let's get going 3. Section 1 - Introduction: Hey, guys, welcome to the introduction section of the scores. So as a developer, there is one question to ask, and that is, why should we build an application or plug in using Windows forms in AutoCAD? I have listed some of the answers I can think up, but there could be more so here they are. It gives you better user experience and interactivity these where you can provide the user with step by step instruction with your user in their face. The next one is provide user with central user interface when performing automated processes in AutoCAD drawings. Basically, instead of looking into the command line progress status, you can keep the user interface active and let the user see what's happening with your automated process in the next one. Is address limitations off common land options? With those form, you can provide many different controls that the user can choose from or request required parameters before running the process in one go, and the next one is the ability to provide professional looking applications. So depending on how good you are designing form, you can provide professional or fancy looking forms that are both very pleasing to the eye , a swell US offer effective process flow, and the next one is better. Presentation off information by using many different controls between those forms. Offer she lots of control to choose from to add into your projects that will give the user the needed information for their requirements. And finally, I say, develop rates more fun and better developer experience. I mean better development experience. So it is always great to come up with great of design and functionality that you can present to the user that gives you more excitement and fun while developing. So these are just some of the reasons that I can think up, and you may have some more to add when you start developing using Windows forms. So in the next video we will list out what will you learn from the scores and that's see you there 4. Section 1 - Who is this course for: So who is this course for? This course is primarily for C Sharp developers. This is an intermediate course off programming in AutoCAD using C Sharp. This requires basic seizure programming knowledge as well as deeper knowledge off Todd objects. I have another course that is beginner course for C sharp programming in AutoCAD. Once you've finished that, you can take the scores if you want to extend your knowledge in C sharp AutoCAD programming . But that is the recommended path. However, this course can also before other AutoCAD developers who want to learn how to develop plug ins using C sharp and doing those forms. The reason being is that in all the projects or the plug it's that we're going to developed in this course are explained in much detail where you can understand how the code works. And, of course, this is also meant for all up a cod developers who develop using auto lease BB, a BB debt net and object, a R X who want to explore and try a different programming experience. It's ah, it's not difficult to move from one language to another once you have a good understanding off the AutoCAD objects and how to manipulate them. It's just a matter off learning the syntax on how to do it. And finally, this can also be for advance AutoCAD users who want to extend their knowledge and learn new technology. So, yeah, if you are one off these, then you are most welcome to take the scores. 5. Section 1 - Tools: let us identify the tools that we will be needing 40 scores. The 1st 1 is the full version of AutoCAD. But if you don't have the card installed, you can try it for free for 30 days and you can download it here. Ah, I mainly using AutoCAD version 2020. But you can use other versions slower than that from me between the 14 or 2016 to 2019. And the next one is the visual studio 2019 community addition these a free version fully functional, so you can download it from this u R l here. But if you have visual Studio 2017 you can also use that. And finally, the debt net framework version 4.7 point two So you can get it from this link and make sure that you have all those installed. And then you can start developing the God plugging with the windows form. Okay? And see you in the next video 6. Section 2 - What will you learn: welcome to Section two and let us examine what we you learn from this course. The 1st 1 is that you will learn about using when those form in AutoCAD plug in so you would learn how to change the form. Properties like the background colored, the foreground color the size of the form. He will also learn how to handle the form, events and so on. And also you will learn how to use different windows controls such asl able text box button , this box combo box group box, container check box and many others like ready about unleased and so on. And of course, you would learn how to design your own user interface. So once you go through all of these projects that we're going to develop, you will have a very good hands on experience or knowledge that you can apply to deciding your own user interface. And next, it's that you learn about event Jeevan programming. What This means that when the form load, that is an event and you can write a code on that event to do something for your program or for your plugging when the user clicks on the bottom, it's another event, and you will learn how to handle all those and, ah, next one. These you will learn how to develop your own Todd plugging. We're going through these projects here, and once you're done with this, he should be able to develop your own plug ins. Or you can even tweak or enhance some of these bug ings to suit your specific requirements . So you are free to use the code. It's all yours. Do whatever you want upgraded or enhance it or take it however you like it. So which, uh, these would be a very good experience for you, too, right? A. An automated process to applied to a multiple drawings like, for example, updating a layer of multiple drawings in the folder. Extract the block, attribute this specific block. Attribute off multiple drawings or update textile of multiple drawings. Or, if you have a Siri's up DW, d d w G or drawings, and that you want to convert to Pdf, then you can use this plug in instead off doing it manually and planting into pdf one. At the time it was taking so much time, but with the use with the use of this, uh, plug in will help you a lot too. Ah, finish converting all your drawings into pdf file. And of course, you would learn also how to extract different entities or different objects from multiple drawings as well. So most of these projects that we're going to develop bills about updating multiple drawings and only the 1st 1 here to create a rectangle is a single drawing. But we are going to, ah, provide lots of best practices. Well, when it comes to developing a project like validation and so on, so this will be the first project that we're going to develop. But after this, whatever we apply in coding this rectangle, you can also reflect on some of these projects here. So, yeah, In the next video, we're going to learn about all these Windows control. And also we will be building another plugging just to illustrate how all of these control works. Okay, I'll see you in the next video 7. Section 3 - Windows Form and Controls - Overview: Hey, guys, welcome to Section three of the scores, windows form and controls. In this section, we will be learning about the form we learned. What are the behaviours and properties of the form, and how can we put or drug and drop containers and controls on top of the form. Also, we will learn about the group container where we will be adding more controls from within a group container so that they will be drug as one control, which means that all the related controls will be grouped into a group container. Also, we will learn about the label control, these very common control and how to use them. That's a a se guide for the user or as information ah, provider for the user based on the status of the project or of the plugging. You will also learn about the textbooks where we will allow the user to entered ah text or the information that we need in our program. Next, we will learn about the bottom control, how to called the event when the button is clicked and also we will learn about the radio button control where we are providing the user with options to select from as well as the check box and also the list box where we need to display different information. And finally, who learned about the combo boss? So same thing with the least box where we will be providing the data that the user can can select or choose from. So, all of these we will be creating a simple project to showcase the behavior off all these controls or their usage on the form. So yep. In the next video, we'll be creating the project for all these controls. Okay, I'll see you there. 8. Section 3 - Identify Project Requirement: just before we create the project. Let us first examine the finished product and also the objective as well as the project requirements. So this will be the you I that you're going to create for these demo. We call that the controls demo. What we have on this form is two major containers. The 1st 1 is the options container, where the user can select whatever options he would like to use, like the combo box. If, let's say he select the user selected from here the layer, then you will display the layer. If the uses selected a line type, then you will display the land type and in the use of selected the textile than you displayed textile here. So basically the same behavior as the combo box. But for these option, we are going to allow the user to enter the value instead of selecting and another option for the user to to scrum, ease the radio button where we can provide the user with three options that they can select from, which means that using this option, they can only select one item. The same is true with the with the combo box and the last option that we will be providing the user is the check boxes. Where the user has the opportunity to select either 12 or all of these I things here and then depends on the selected items. All of these or some of these will be populated and finally would provide the user with the the button to basically start the process of gathering the data provider of the selected items and then displaying into the least boxes. And also we have here the clear all button where we let the user to clear all the items in this list box. So this is a very, very simple example, however, is quite important. At least we will witness. Or we will see how each of these controlled behave and how how they are being used in this project. So in the next video, we're going to create our project. I'll see you there 9. Section 3 - Creating the Project: Okay, Let us know. Build our controls them or project. So open up your reach with Studio 2019 and select the create new button option here and search for class. Library that need framework. It would be using this one here. I have it here in the recent project templates because I Mm. I developed some of the applications earlier. So in your case, if this one doesn't exist, just search for class. Library that net framework and click next and, uh, can start in any folder you want. Let's give this a name. School. This is controls Demo. Click on. Great. Okay, so let me just rename this class one here with the another name that let me call that as controls Demo Util. He will use this glass as that's the glass per hour functions. There are methods sleater on. All right, First things first. We need to add references to AutoCAD definite a p I. We have here the A, c m G d a, C D b and a C Corps MBD. You can find all these three in your auto hide the installation. In my case, it's in the program files off the desk How hard? 2020. And you can find those three there. We can Okay. And set the copy local property to false for each of these three. All right, so we're good there. And now we we need to add Those libraries now are using statements here. So using out the desk that autocad that application services, you single out a card that out of this AutoCAD database services and also using other debts that autocad that run time. Okay, so that will be our project. So in the next video, we will continue with, ah, designing the use earned their face. And then, you know, so start coding the instant she ation method to display the former. Okay, See you there. 10. Section 3 - Designing the User Interface: let us continue building our project, so let us add a form in our project. So right click on the Solutions Folder or Projects folder, click on add and select the windows form and let us named these as main form. Click on add. All right, so these our form. Now, if you look at the properties in the right, the lower right corner Here we appeared, the name of the form we have in the background, the back collar. You can change it if you want. There's so many other options to choose from, but we'll stick with the default. You can also create a background image, so it's up to you to design your own form. There's just so many properties here that you can play around with, and also the four color or the phone, and the location is 00 based and the maximize bucks. It's true, which means that this is active or enabled, So if you want to allow the user to maximize deformed and just keep, this is true. But if you don't want the user to maximize it, said it false and also the the start position. When you load the plugging it will be the default location, which means that wherever the AutoCAD engine starts deformed and it will be there, however, you can also choose to make it at the center of the screen. You know, so you can change the the text here, the main form, it's just provide a space there and the top most. You can set this to true or false. When you said true, this is ah, these advisable to set the true. If you are processing a multiple drawings, which means that every time a new droving it's loaded, the form will always be on top. It wants disappear on the screen. So in our case, since we're just dealing with one drawing for these projects, so it doesn't matter if we change to true or false, but let us set it to true anyways. And these are just the basic. These are just the basic properties that I would like to set for our form, and now we can just recites it accordingly. So hold on these white squares, and then you can just drug it accordingly. Okay, so now let us create too major containers. So this is the toolbox here. You can find this one from from the view. And here. Ah, you can also press controlled out X. So once you add the form in your project, the toolbox is automatically displayed. This in case it's hidden. She you close it and you can, ah, activated bath by clicking on the view and selected to bust you. Okay, so let us drag to group box containers. This will be for the options. The options container and other one is should be the display container. Okay, so let us just reading this s eruption. This container can this one for the display container. You don't need to change the name since we're not dealing with or we're not interacting with this group box anyway, so we'll just keep the name is the default. Next, we need to drug a label control, and this label will be just guiding the user to select. I tempt to this play, and next we will be needing the combo box control. So since we are interacting with this combo box, we need to provided a more intuitive name or more descriptive name. Okay, so let's just call this as CBOE options. And since this since This is a combo box we can actually add or hard coded value. Sometimes hard coating is OK, but you have ecstatic values that the user to choose from. But if you have dynamic values, for example, you're you're you're retrieving from the database or maybe from the cod tables. You might have to use the data source binding. But in our case scenes, we are just providing the yusor with options like to select from those options so we can select on the date. Uh or is that here the items. So the 1st 1 is all the 2nd 1 is layer 3rd 1 is lying type and textile. Okay, then click on OK, so next we're going to great a button that would be to show the items it's called that as BT end display and the text would be like show items and the next button is clear. All the values in the least box. So let's call that as clear. All and the name would be Bt and clear. Okay, let's call the Beauty and Pierre Oh, so our our project, our plugging, will try to build it one option at the time, Then we will run and you will see we will examine the code and the the behavior off our, uh, code. So in the display container section here, we need three list boxes. So let's drug first, the layer hopes ethnical. This is LST layer another one. It's called that as LST line time. I need to enlarge the form a little bit and one more this box. Let's call this as LST textile. Okay, we also need three more label controls. This time we will be using that label, too. Give the user information on how many layers or how many line types or textiles founding the drawing. So let's add another three labels that's called since we will be interacting with this label control later on. So we need to give me the name lbl layer count. And let's just initialize the text value to maybe just three dots. And also we need to have here for the land type. It's called. This is LBL line type count and one more labor and B l text style count. It's just initialized next to three dots. Okay, so this will be our form. We are not doing any coding on this form yet, however, we will be, uh, according a method in this utility to instant. She ate and display the form. So to do that, we need to create a method that's cool, that as public avoid, let's just call us demo. And then we have two instance She ate that form main form. That's let's say, MF IQ waas new main form. Okay, then I m f that show and it should display our form. But we also need to provide here that command method that will be used in in the command window. So let's just call. This is Demo as well, and that's it. Let's save our project. And when we run it, let's just click on the debug and you set the property. I mean, the start extended program to the AutoCAD, the X installation. Okay, so C program files out of the ESC. Took out 2020 and click on a Cuddy XY. Okay, so now we can try running our plugging, So let's do that. Click on. Start this. Open one up. These drawings here. Okay, Some extents. All right. That typing net load and then look for the project. So it's in the C drive controls. Demo. Go to the bin folder debug, then select on Control's David. Yep. Click on all the way slowed. And now we should have the demo command. So let's try that. There you go, Demo. Yep. There you go. We have our form. So if you click on the drop down here, we can select one of these options. But even though if we select one, there's no activity happening because we haven't handled the code yet. Okay. So yep. In the next video, we will start coating on these form here and start displaying some layers land types or text size. Okay, I'll see you there. 11. Section 3 - Creating the ControlDemoUtility Class: know that we have our form ready. We we should be good to start coding on this form. However, I would like first to complete those three methods that will retrieve the layers, the line types and the Texas style from the drawing that we're going to run this gold on. So to do that, let us go back to the controls, them or you till and in here. We're going to create those three methods to get the layers, land types and Texas styles. Let's start with the, uh, layers so public our A list. So basically, we are going to retrieve all the layers from the table, the table dictionary, and we're going to store that in a list in an R A list that we can bind into the list box controls. Okay, So I will release its not yet recognised, just hover over. And then you can see these Ah iro here and click on using system collections and it should be added in your using section here. And the method that we're going to create is get layers. So this will trip all the layers for us. So let us declare one variable. I released variable and call that a slayer's quells knew our A list. Next, we need to get the document object. So application the document manager that MD I active document and let's get hold of the data basis. Well, that's cool. That as D. B. And that would be duct that database. Next, let's start a transaction. So using the using syntax trance section, the school that trans equals BB that procession manager that starts to recession? No, Since we are retrieving the layer, we can find that from the layer table. So layer table and let me call a variable name as L y tab equals trance that get the object and ah, object idea would be coming from the DB that layer table i D. And the open mode would be for Reid, and that will be a slayer table. Okay, so now that we have the layer table, we can looked through this layer table and extract the layer extract all the layers to do that we need for each statement. So for each bar, let's say L y in layer table variable el y tab. Now we can get the layer table record, so layer table record Let's call that as L Y T r equals trance that get object. And that would be the object idea, which is the L. A Y. Here. Open mode for Reid US layer table record. Now that we have the layer table record, we can now I retrieved the layer name. So to do that, we need toe add layers. That ad Ah, L White Yard, that name. Okay, so we are adding every single layer into our are released variable here, okay? And that's it. All we have to do now is return the layers. So now this is fix. It's not complaining anymore. And that's all about for the layer next four, the line types. So we can basically copy this method. It's ah, it's the same process. But instead of players will be using the get land type method. Get land types and then the area leased. Let's call that US line types, so we're just replacing all the layer related variables. Here are layer related information and changed it to land type. So in this case, let's call this is lt tab, and instead of player table, I d. It should be line type table. I D and instead of player table here, it should be nine type table and this would be Atlanta table here. Okay, so now in the for each statement instead of l while it's just call that us lt and then it tested be the lt tab for the layer table record. It should be line type the table record. This really should be lt. And let's call this as LTTE are and this one will be lying type table record. All right, so now instead of players we have here line types, types that ad, then the land type name LTTE are that name okay, and now we return the land pipes so that will be our get line types method next for the Texas style. So same thing we have just to copy these method and Jason too. The I mean to textiles. So get Texas styles and instead applying types here. Let's call that as Texas up. Sorry, it's called that Texas styles and instead of plant type table, it should be Texas style table text the style table. Here you go and let's call these s Ste Todd and this one will be text style table. I D. This will be Texas style table yet. So in our for each statement, this will be ste in Ste. Tub instead of blind type. They will record this would be Texas style table record and this will be lt or STM in. Let's call this as STT are okay and Texas style table record. So now we have here the textiles variable. It's replaced this land type with textile. And let's replace this lt theory STT are this one here and return the Texas styles and that's it. We have all our three methods, so we don't need to put a common method decoration for each method here, because is only need for the entry point for executing in the front. So all of these three methods will be called from these main form. So if you right click and view code, we would be creating the the form events methods. And then we will be calling all this method here, the one that we discredit. Okay, so in the next video will be coding this form all the events that's triggers from this form . We will handle it from the court behind and I'll see you there 12. Section 3 - Coding the Combobox Control: all right. Now that we have our utility methods complete, we can start quoting the form now. So if you right click on the main form and view code or press F seven, you can see that this is the only existing code provided by the boiler plate. So if we go back to the designer now, we need to click on this button here so we can handle the click event. So you might notice that the programming and Windows form is based on the events off the forms that's happening on the form. Okay, so one of the event that you can handle is when the form loads, then do something. But in our case, there is no action to be done when the form those So all we have to do now is great. The method for the button click off these Bt and display button controlled here. So double click on this and we will have this beauty and display click event. Okay. All right. So when this button is clicked, the objective is to select whatever the user selected from these drop down list. It's either layer land type or text style and all and then, based on that selection, we are going to display ah into the respective list box. If the user selected layer, then we will just display the layer. The use of selected the land type will display the line type and we will hide the layer if the user selected the Texas style. So this will only be the one that is active and issuing information. So which means that these other two will be empty. So that is our logic or our project requirement. Okay, so now that we have, uh, this play click event, let us create a variable and called that as choice equals empty string. For now, this will be the viable to handle the selected value from the combo drop house. So that's just put here using combo box. So the choice now would be equal to CBOE options. That selected item that the string and now before we can call the methods from here from this class, we need to instant she ate this class. So to do that controls them or you till. And let's just call that a see you till equals new controls. The more you till now, we should be able to access those three methods, like get layers, get line types and get techstars. All right, so now that we have the choice value from the drop down from the combo box, let's do a validation. We can use either switch or a statement, but in this example, we are going to use the eighth condition. So if choice equals double equal layer, then well, this declare and our A list. Uh huh. I release. It's also that included here. So using system that collections, so are a least. Let's go that as layers equals, see you till that Get layers. Remember this Get layers is returning an array list this way, we need to have an are released data type. Also, when we retrieved those layers. Okay, so now that we have the layers, all we have to do is buying this into the list box. So Alice T layers layered. That data source equals layers, and that's it, however, has spurred the requirement. Only the layer should have value. I mean, only the layers list bucks has a value. So if that's the case, we have to make sure that the line type that date the source equals nothing or not so that they don't show anything. Also, the A list the textile that data source. Because now this weather, this logic only works. If, let's say I mean only yeah only works when the user selected from the drop down like land type or textile and then suddenly he decided to select the layers. So at least we really just clear whatever is in the list bus. And then, of course, we just showed the user Khomeni layers are there in the drawing. Text equals layer sculpt. It's put that there's equals plus layers that count. Oops, and that's it for the layers. Next, if the user selected the line type so else if choice equals line time, we will basically do the same thing. Except that we just changed the variable names and some of the the values here. So this will be line types and see you till that get line types and now the this line type will have value instead of not, that should be the land types that is buying into the data source, and the layers now become not in next lbl land type count online types count equals the land types count. Okay. And that's it for our line type. Next, let's scrap. It is for the Texas style. So if the choice is Texas style now let's just change this variable to text style styles, and we can call the method, get Texas styles. All right. Next, the Texas style now will be the one with the data source. So this will be Texas styles. Okay, In the line type now in layer becomes not. All right. And here the the count will be Texas style count, and Texas does. Texas does. All right. So one more thing if the user selected all So that's just copy this over. And if the user selected all, then all of this three, we have to call, which means that we need these. We need the line types groups. Forget the layers here, and we need the Texas styles. So we have here the line types. Oops. And we need the Texas that here. Okay. And now all of these the messages should be available. Should be called this well in the layers. Okay, You've got duplicate here, so that's it. So if the use of selected all we will be calling all of these three methods and by banding together and then display all the information's in their corresponding label control. Okay, so let's save our project. And let's give this a try. All right, let's open this drawing. Okay, Do a net load. Click on. Always slowed. And now we have the demo command. There you go. All right. So let's try the layer and select on show items. Nice. He had the layer. It's We have 16 layers. Next, let's try the line time. So we should be expecting to be displayed here. And then this this layer, this box will be cleared. There you go. But we forgot to do this one, but I leave it to you to clear it out. But now it pre select on the Texas style. This should be clear out to, and we only have this Texas style displayed. Now you re select online type and show items. The Texas that is clear. Okay, finally, we select all all of these three should be populated. Very nice. So that's it. When using the combo the combo box control, you can only select one item at a time. All right? In the next video, we will add another option. Another option here, too. Just use a text box by simply accepting whatever the user types or enters into the textbooks. And we will use that in, uh, controlling the display in this list box here. Okay, I'll see you there. 13. Section 3 - Coding the Textbox Control: Welcome back. Let us know. Continue building our plugging. Now we're going to add a text box. That will be the source off our input from the user. This may be the ideal usage of the textbooks, but for the sake of these ah example Demo. Let's just do that. So drought drug a label control and changed the text to enter item to display and drug a text box here. So let us call these txt item. So if you are interacting with the control from the code behind So you have to make sure that he renamed the control accordingly. That is descriptive enough for you to easily ah, retreat or identify. Okay, So next we have to modify the code behind these button control since we are now ah, getting the input from the text box instead of the combo. So that's the book make on these. And this time let us just comment this code here it's put another comment using textbooks. So now the choice will be coming from the txt item that text. But we also need to add the dream his dream method really get to read off all the extra spaces after the text, and that's it. So if the user enters a layer, it will display the layer land type textile. And so on p enters all they will display everything. Otherwise, if none of these choices here are entered and nothing will happen on the form so that save our project and this Q b That's right. Okay, that that's open one of the drawings again here and let us load our plugging net load controls, demo and demo. So now we will be using this text box. Say, I have bean layer and click on show. I attempts. There you go type in ah, line type. So same behavior as the combo box, right? Textile? Yep, because they're using the same code except the choices. Ah, coming from different source in the by type in all. Yep. If I type in anything, that's just clear this one first, So we haven't 100 the clear yet, anyway. So let's say that we just start with the layer and by typing here anything, nothing would happen because there is snow. It's not handle in any of the condition you can add, like please enter either layer line type. Something like that in the message box. So let me close this form and let us modify our code to handle. Yes, that. But before, before we handled that, let me just called the the clear All button here. That's all we have to do is clear the layer that date the source equals none. LST line time that they the source equals not also, and elastic textile that day the source going nuts. And that's it for the clear orders. So no, that has handled the option. If the user and there's anything that's not one of these ah types here, one of these items here. So all we have to do is put in else. Then you can say message box that show, please enter a valid value. Okay, then that type the love, our message boxes, invalid entry or something, and message box buttons that Okay, Mrs Bucks? Icahn the error and that's it. Let's give it another try. This opened one drawing and then load our plugging. So typing demo. Okay, So layer see, layer is different from layer with the capital. L all right. Ah, see, sharp use case sensitive. Remember that. So this layer is not the same as layer. We can do that too. We can handle those guys of case, uh, issues by using either to upper or to lower, And we will just capitalize all the the items that we have. But, uh, let's just continue with our testing here. So lying type? Yep. And then let's see all. Yep. Then clear everything. You're all it works now by typing lying type that one. That would give us anything because it's not the correct one. Typing anything here. Same thing. Okay, so that's how you handle those guys off. Validation the errors. And that's it for this Ah textbooks option. As I mentioned earlier, this is not a good, uh, wait to handle. When you are giving the user options, it's either you provide them. The combo box or radio button are check box. Depends on your project requirement or your logic, your business logic. So, anyways, that's it for the text. The option In the next video, we're going to provided you served another option using the radio button control. I'll see you there 14. Section 3 - Coding the Radiobutton Control: Okay, so now we are going to add another options for the user to select. This time, we will be using the radio button control. So let us create a another group box. This will be the container for all our radio button. So that's just changed the name here, too. Radio but us. And now we can drug a radio button controlled inside it. So let's call this a slayer and changed the name to R B Layer. It's tread too more so. This is for the line type R B line type, and that's changed the text to line time. And one more for the Texas. That next style yes, called this s RB Texas style. Okay, now we can go. You can update the show i them about them here and get the the value from this radio button control instead of combo our textbooks. So that's do that. Let me just comment out this way. No using radio button. Okay, So to do that, we need to have the if statement. So if our b layer that checked, then our choice would be R b layer that text. All right. And same thing for the r. B line type. If the RB ready bottomland type that checked, then choice will be RB land Type that a text. And finally, for the RV textile, the check and our choice will be RB textile text. So I didn't add the option for all, but you can just do it. The important emphasis here is that for the radio button it behaves just like the combo box . Which means that you can only select 11 item from the group or Siris of radio buttons. Okay, so you might want to update these program by yourself and add some of another options like the all. But for now, it should be good for our demo. So that's it for the code update here that save our project. And it's straight. It's up in the drawing. Okay, let us load. Are plugging custom controls. Demo? No, we have a demo. So here, if we select on the layer, click on show items. There you go. Select on the line type. See the behavior. It automatically unchecked the layer. If you so like one of the other options. Select on the textile. Go back to layer. Okay. So as on extra exercise for you. You should add maybe the old option here. Samos the combo box so you can display in one Go for all these three list boxes here. And that's how simple it is to use the radio button controls. Okay, in the next video, we're going to use the check box control. All right, see you there. 15. Section 3 - Coding the Checkbox Control: we're almost done with our plugging our last option ISS using the check boxes. So let's do that. We need one group container so that we can I store all the check boxes options into one container. And let's call these asses check boxes. Now we can drug three check boxes in here. Let's go this a slayer and name it as C H K. Layer struck two more. It's called this a C H K Len type. Can that text would be line type and one more. The text would be Texas style and the name it should be. Chk, Texas style. All right, so here's the the tricky part off the check box. Unlike the radio bottom, where the user is only allowed to select one check box allows multiple selection. Reach me is that if the user check this layer, he can also check the line type. Or you can also check the textile, which means that whatever is checked in here, we're display accordingly. In this list. Boxes here will be displayed accordingly. However, since most of these all of these three options that we have provided earlier only allows one selection or one option or one choice. It is different when it comes to list the check, boss. So to do that, we need to handle it in our code accordingly. So let us examine our code. So the current set up now only works for those three options earlier. Because we're only dealing with one the value so visits the case. Our code structure here is not applicable anymore for the check box. So to do that, we are going to re factor this code and then just provide one parameter or argument that they can pass on. And then we will execute accordingly based on the choice that's being passed. So let me do that. So from here, they're going to extract and create a new method. Let's call that US private boy just display item and it would be needing one parameter the choice and you write it here. Oops. Also the util we need these swell. All right, so now we have a separate method that only except one ah parameter the choice. So whatever the calling function passed onto this method, then we will do as ah we've done before. It's layer than just do the layer land type and textile. However, those scenes ah, the option for check box are open, which means that if the user selected more, we have to apply the logic accordingly. But I will leave it up to you to modify the code, but for now we will keep us the same. And a logic as before. Reach me is that the layers select the use of selected. The layer will clear all the land type in the Texas style. So if let's say, the use of selected two layers at two items layers in line type, you might have to adhere if the choice equals layer or, uh, maybe just provide some if statements in here before you clear up the values. So those are just simple logic. It's just need to be added in the code. But for now, we'll stick with our existing structure and handled the selection off check boxes. So let me just comment out this radio button here and now we are going to be using the check box you're seeing check boxes, so same thing with the radio button. If C h k layer the checked, then our choice would be equal to chk. Layer That text and now we will be adding a comma as a D limiter because we should anticipate that the user might also be selecting the line type in the Texas style. So we are going to concoct innate those selected text or values or choices into a single ah , string variable separated by a comma. And then later on, we're going to split the string based on the common, the limiter and the storied in an array. And then we can look through the IRA and process one item at a time. Okay, so now if the chk line type that check our choice now would be the concatenation off the layer and the line type. So that's why I did hear the plus That is the way you can cut in eight string or you join string together. So chk line type that text blast another comma just in case the user select or check the Texas style as well. So if chk textile that check so we have to also add into our choice. So chk textile that text. Okay, now, maybe we can add extra condition here if see chk layer that checked and hopes and also ch gay line type that check and also C h k textile that checked. Which means if those three are all checked, then our choice will be all all right. So we handled individual selection as well as the three items. So we have no problem with this logic here. But somehow we have an issue with If the user only selected to either of this tree, so to other history, off the different combinations, then that should be handled accordingly. And that's the one that I am living it up to you for your own exercise. So now that we have the choice here, I can now create a another string variable. But this time an area piece string. So Choi says, equals choice that split. And then the dilemma is a comma. So now we have an r a up string he stored in The choice is valuable. Now we can look into that area B string using the for loop for int I equals zero. Then ice less than two choices that lent. Then I plus plus. So now the choice will be equal to choice us and the index of the area, which is the I and now we can call the display. I ate them. Choice. Passing the choice parameter. All right, so that's how you handle the check box. Okay, So we can give this a try. Let us save our project and start It's up in one drawing and let us load our plugging. Okay, so now we should have the demo. Oh, man, that start with the layer checkbooks. Nice. Oh, we forgot to ah, comment the validation in the text, boss. But anyway, our Cody's working here. If I let's say select on the line type. Yep. If I select on the textile, you go. Now, if I select all three well, let let me just clear the 21st. So if I select all the three, it should display all the three because we handle in our condition. Also. Now, if I just select two let's try that. This one that keeps on pumping up. See, this is the issue here because we selected the layer in the line type. But since you are just passing in one choice at the time, it actually loads the layer. But since we passed the land, type us the second ah, option or choice then it clears the layer and displaced the line type. So that would be the same thing with when we choose the line type and textile. This one will be shown but immediately, uh, cleared because the textile would be displayed. And the logic is to clear each of these two whenever one is selected, right? Same thing here. If I select this too, Uh, layer will will be displayed, but eventually will be cleared out as well when we display the line time at the textile. Yeah, so that's it. Now you might ask what will happen to the earlier code that we have here? Let's say for the combo. So all we need to do actually is call these ah method here, call this method and passed the choice. So in this case, just like that. So let let us comment out this good for the check box and give that give this a try for the combo. Okay? Let us load are plugging and then demo. I see. No, it's active. And that the select the layer There you go. Nine type and textile are all yet here still works. And that would be the same thing for the textbooks so that savory and commentaries and just added here and that should work. So let's save it and give it a try as well. But the select one drawing and then load our plugging gay and open our form. So that's typing here, layer Nice nine type. Have something. The friend message box textile. There you go. Say still works. And same thing with the radio button. So yep. Let me copy this over and that, as a NCAA meant these radio button controls and put here the display, I them line of code and save and run open the drawing and our plug in called on Demo Radio button Control. Here you go. All right, so that's it for our demo. I hope you learn a lot here on how to use these different controls. We have identified some of the missing functionalities. Like, for example, you want to adhere another option for all and also for the check box. When the user selected to I attempts, for example, it should display to rather done just one. So I leave it up to you for your exercise, play around with the code and try it for yourself. Another thing is you might have to clear out these count here if it's not displayed. So it's just going out saying that lbl late layer count that Tex equals to an empty string , for example. So yet the code is all yours and play around with these projects. Maybe you change the background up some of these controls or changed the fund await, like, bold or something. It's all up to you. Play around with this and be familiar yourself with how to handle there code both on the class and in the form of events. All right, so in the next video, we will be starting developing rial world applications or plug ins. Okay, I'll see you there. 16. Section 4 - DevelopingProjects Intro: Finally, we are now into the most interesting part of the course developing real world projects. So let me just quickly give you an overview off the projects that we're going to develop. The 1st 1 is very simple. One. Just draw a rectangle. We will just provide the user with options to enter the coordinates on the form or on the you. I use it in their face that they were good, that we're going to build and also provide the user with the option to select on screen. So this is just very simple application just to give as a traction on building the rest of the applications here or the plug ins here. But whatever we learn from this first project, we will be applying into these other projects. Also, the next project is the updating Off Objects layer and from Project to Project six. This will be all dealing with multiple drawings, basically automating the process, like updating the objects layer and extracting the block attributes to a file for all the drawings in the folder, updating the and text text style for multiple drawings and also the converting or plotting the drawings to pdf file This is very, very useful if you have some kind off requirements to generate. PdF for all your drawings so you can use this plugging. You can use this code, and it's all up to you to modify it however you like. And finally, we're going to developed a plug in that can extract multiple objects in a single process, so there are lots of rooms to upgrade or to enhance this project. You can build upon this project by adding your any other functionalities or entities that you would like to extract. So that's basically the projects that we're going to cover. And in the next video, we're going to start our very first project, draw a rectangle, and that's see today. 17. Section 4 - CreateRectangle Project - Overview: All right, guys, it's about time to start developing projects. Our first project is simple one just to draw a rectangle on the left. Here we have our user interface design and on the right, we have the project requirements. So our u I is simple one with some controls to allow the user to enter the value of the within the height of directing Go. And also, we have here a radio bottom control to provide a yusor with options to either enter the coordinates or the lower left off the rectangle or pick on screen, which when the user choose to enter the coordinates, these groups box container here will be activated and then the user can enter the location for the X and Y coordinates. And if the use air decided to select the pick on the screen, we will hide the form and allow the user to click on the how toe had drawing window. And of course, we have a bottom here too. Allow the user to click and draw the rectangle, and you may not. This here one of the label controls is just and up information control too. Let the yusor see the status of the of deformed or pan off messages because we will be providing some kind of validations here just to make sure that the user will enter the correct value. And it's not empty. And we will use these label control to display those messages other than the message box too. So, yeah, it's a simple one. But we will learn quite a lot on how to code behind the form and also creating a separate class utility that will draw the actual, uh, rectangular. Okay, so I'll see you in the next video where we're going to create this project. 18. 02 CreatingRectangleUtilClass: Okay, guys, welcome to creating our first project. Let's call this a scrape rectangle project. So open up your visual studio 2019 and click on Create a new project in here. We're going to select C Sharp and also type in the class library template. And it would be using these dotnet framework. I am using these folder to store my project. So let's rain this US draw rectangle project we can create. Okay, So first thing that we should do is to reference those three definite a p I, which are the A c M G D A CD BMG and a Psi Corps mgt. These are all installed in the AutoCAD folder installation. So just locate your your authority installation, and he should find all those three there. Okay. Next, you have to make sure that the copy local is set to false for all those away. These three Ap eyes Next. Let's get rid of the class. Let one library. I'm in the class one file here. We're going to create our own. We just have to make sure that we make it public here. Right Click. And then I had ah, class. Let me call these as rectangle. You tell us. It's called this class real Store the code to draw the actual rectangle and make sure we have to make this is public. Okay, so we are ready to code. But before that, we have to, ah, add all those names, spaces using off the desk that other card application services. When you're scrapping, it's over And Basit here, the next one is the database services and the 3rd 1 East. Ah, run time. Another one is the geometry, since we are drawing object and the last one is the editor in front just to give messages to the users and we can get rid off all these. I did, uh, I did using statements. All right, so the first thing that we should do is to create the method public void. Let me call this method as draw rectangle, and we need to add three parameters which are the with and put it us double. And also the height. And also the point, uh, object, which is the insertion point. All of these three parameters will be coming from the form that we're going to create later on. So once we have the form will prompt the user to enter the with the height and the insertion point. And then we will call this method. Okay, so next is to get hold off the document. Object that because this is Dr Equals, that would be from the application object Document manager MD I Active document. If you are not very familiar off all these libraries, I recommend to go through the the other. Of course, that I have That's learning C sharp programming using in AutoCAD using that, not a p. I saw that you will be more familiar with all this. We abused a lot of this in the tutorial. It's the next one is the database object we call. This is Debbie. That would be coming from the dock database and also the editor. Let's just call that us E t t. Okay, now we can start with the transaction, So using trance section, you call that us trance equals db that trance session manager that start transaction, you know? So let's wrap our code in a try catch block, so type in, try and then press the top twice. And we just handed the air here. Let's say we encountered an error. Who will just provide the You serve it a message saying that error encountered you can customize thes as you prefer. In my case, I just wanted to display the message to the user, and then we have to abort the transaction. Okay. A suit like nothing happened. Okay, so in this gold block here in the trick, in the try block, we're going to write our code to draw direct hunger. But before that, since we are using the form since we will be using the form, what I'm trying to say is that we need to lock the document love document. All right. And now we can do our own processing from within the document. So next we need to get hold of the block table object, black table. Let's just call this beauty equals trance that get object. And the object i d will be coming from the database object Blood table I d and open mode. Just for reading for read. And of course, as a block table. Next, we need to get hold up the block table record, So block table record. That's called this SBT are equals trance that get the object our object. I D and I will be coming from the block table love table record and used the model space and spare just dealing with model space. And then the open mode would be now for writing, since we are writing some objects and this one is a block table record. Okay, Next, we have to convert the the point Treaty just converted into a 0.0.2 d. So that's just have a comment here. Convert and the insertion point 2.2 D. Since you're just drawing the lightweight Polly line. So point two D in speedy duty, new 0.2 d, and that will just basically the x and y up these insertion point here. We don't need that, is it so in speedy the ex scored in it, and in speedy that Why cord it. Oops. Missed around here. Okay, All right. Next we have to derive the upper left corner of the rectangle based on the insertion point . Okay. And of course, we have to include in the calculation within the height. So that's derived groups. The upper left corner based spawned insertion point. So 0.2 d, we just the upper left point. It's called that as upper left pity equals new 0.2 D. And that should be coming from the insertion point. Whatever the insertion point picked or entered by the user, we will use that X axis the X coordinate, I mean, And then the white coordinate in Speedy that Why, plus the height. Okay, so from the the insertion point, we just need the x Samos, the insertion point, and our why will be the insertion point. Why axe y co ordinate bust the height that these our upper left corner point next derived, uh, upper right corner. And this time that will be based on, uh, upper left corner. Okay, so now point two D upper right point or operate corner point, new 0.2 D. And that will no be equal to the upper left point. That X glass. No, we have. Okay, so we're moving to the right now and the white cord and it will be just the same. A stopper left corner point that Why? Okay, so now we have three points already. We have the insertion point. We have the upper left, and we have the upper right next there. I've, uh, lower right corner. Based on the insertion point, you can still get the lower right corner based on the insertion points. So 0.2 D let's call that as lower right point or lower right corner point new 0.2 D That will be the exc ordinate up the insertion point, plus the with at this Hour X and then the why co ordinate of the insertion point. And that's it we have now the four corner off the rectangular poor points. Next draw the LW Polly line, of course, using the newly derived Regis's. So let's declare one poorly line. Let's just call this SPL us new Paula line and now we can add the birth. Vergis is odd. Vertex at zero is the first vertex in 0.2 d and we have here the botched zero start with zero and with the zero all of those three parameters a zero And now let me just carpet is over. So the next Vertex would would be the upper left point or upper left corner. So you lpd okay and based again the next one would be the upper right point upper right corner point and the last one is lower right point, and then all we have to do is close. The police said the true property, I mean, the close property to true. It should be closed. All right. Now, of course, we have to add into the block table records. So BTR dust Ah, a pen entity that this the newly created Pauline. And then you have to commit the transaction. The only created Devi object pl true and trance that coming. And that's it. And it's just give a message to the user saying that this rectangle has been created successfully drawn success, buddy. Okay. And this will be our code to draw direct anger. So in the next video, we're going to create the form the user interface for our rectangle and see it it 19. 03 CreatingForm: Okay, guys, let's continue building our draw rectangle project in this video. We're going to create the user interface, the windows form. So But before we create our form, let me just do some correction here in our code from the previous video. So we need to make sure that the Indus s are in proper order. So is your 123 Okay, so we're good with this? Not all right. So let us great. The form first thing that we should do is just right. Click on the project and then select add and windows form that's called is as rectangle form. Okay, let us resize it to make sure it just, uh, enough to contain all the controls we need. And first thing I would like to make these Azaz a not maximize a ball. So basically, we disable this maximize bottom just to avoid the usurp from selecting it in covering the entire AutoCAD drawing window. Okay, so now let us start building our controls or creating it controls. I love too. Put all the controls in a group bucks container. So drug A group bucks here. And who says it's something like that? Let me just name these s G B rectangle form or something, and then the text it's provide here, this enter rectangle parameters. So next let us create the controls for the will and the height. So to do that, we need the label control. We need the textbooks groups, another label control for the height and another textbooks for the height. Now, let us change the text for the label 12 enter with and for the labels to to enter height. Okay, Since we are not interacting with the label in our code later on, we don't bother to. I don't bother to change the the name. Just leave. It assists us the default. But for the text boxes, Since we will be interacting with this values here later on, we lost to be doing some valuation. We need to provide a more into t name. So in this case, txt with its this year for us to identify that we are dealing with the particular control. This is the extra hype. Let me just at some more caller here to make it a little more lively rather than plain white. Okay, so now we have the control for the within the height of the rectangle. Next, we need to provide the user with an option to either the starting point on screen or enter the coordinates. So for that, we also need another label. So in this case, we are basically the advising the user to choose starting point or chooses starting point options. Something like that. And now we need the radio button control so that the user can choose either or so this is still in here that we need. That is for the entering the co ordinates. And the other one is sport peaking on screen. So let's call this and their co ordinates. The other one is pick on screen. And of course, since we are also interacting with this radio button, we have to name it properly. So pick on screen and this one will be our be co ordinates. All right? Okay. So based on these control, if the uses selected ah option to enter coordinates, we have to provide them with another set of controls to enter the X and y chord in it. So in that case, I would like to another group. Bucks control. This is four hour Gordon. It's Now we need a label for the X coordinate. And of course, the textbooks. Another label for the Y coordinate and another textbooks. So that's just James Dis text into X. According it This one to why, according in this text box, we should rename It s txt chord, Ex Corde, I mean, and this textbooks to should be the x t y chord and the color will be Let's put lighter yellow. Okay, in this group bucks, let's just let's don't bother to change the name. But of course, the message here, the texts We have to provide more meaningful message. So enter coordinates. Okay, Next, we need, of course, the button to be clicked by the user one soon he entered all the information here. Now he should be ready to click the button to create the rectangle. Let's give this Texas draw rectum good. And then Bt in Ah, correct. Make it drawer. Okay. And let's change the background color too green and make the fun to be bold. So chase the front to both True, There you go much better. And next The last control that we will add is another label control. These just for the information, which means that we are keeping the Yusor inform off any activities that's happening on the form. Let's say for validation purposes, if the user entered a A and an invalid value will prompt the user with using this label control here. So let me call this us lbl info and temporarily Let's just provide initial message or text us three dots so our control is ready. Our form, it's ready. In the next video, we're going to ah, write the code behind this form. And also we we will be updating the rectangle you till that we've created earlier so that we can instant shape this form from this code. Okay, I'll see you there. 20. 04 CodingTheRectangleForm: Okay, let's continue building the project. So in this video are trying to complete the code behind this form. But before we create the code, let me just update this. Ah, control here. The group co ordinates Because we will be interacting with these control when the user select either one of these options here. So we might as well provide a a better or meaningful control name. Let me just call that as G B coordinates. Okay, so it should be good. All right. So what should be the first thing that we should do to read the code here? Remember that when developing a Windows form application, all of the code are triggered by the event that's happening on the form. So in this case, we're going to execute whatever. We're going to execute the code in relation to whatever the user inputs in here. So there are three types of events that will be happening in this form. When the user clicks on this option here to inter corden. It's we're going to activate these group bucks control here so that the user can enter the value of the X and Y coordinates. If the use air decided to pick on the screen. We are going to deactivate this control. He will disable this control, which means that the user is Snowden were able to enter any value here. Okay, so those are just some events that will help out to minimize that you, sir, interaction unnecessarily because we don't want these controls to be enabled when we actually picking point on the screen. Otherwise, they pick on screen at the same time taken on. So we can also enter some values here. So we're trying to minimize the user interaction and only limit that the the behavior of the form based on the user's selection and of course, was everything is valid here. And then we can click on the draw a rectangle. Also, we will be introducing some validation, which means that we cannot allow a an empty value that the user will enter in any of these texts boxes. So the user and there's nothing that would this place, um, information or error message. Okay, so let's Ah, start with the Botton. Click here. If let's say the user ah, decided to click the draw a rectangle button we, the visual studio, will generate for us. The draw A rectangle click event. Okay, so going back to the form, you can just either click on this one here and going back to the code. Let's say from the solution Explorer, you can just right click and view code. And also you can right click and view designer, or you can either Just anyone. Anyone of this stuff here. Okay, so next, what should we do? Since we have different textbooks control instead off writing a validation logic for each one of these controls, we can just great a method that will validate. That's a common method to validate the textbooks by just passing the textbooks as the parameter. Okay, so let's do that. I'm going to create a method. So let's say here, let's call this a private bull validate entry, and then we'll be accepting a text box parameter school. This is textbooks TV make keyboard is somehow be. There you go. Okay. Excuse me. So now so each of those off textbooks control that we have on the form will validate each one of them by calling this validate entry and then passing on textbooks. So in this method, we're going to create a Boolean variable called Is Valid equals initialized, toe false and also that's great A the bullet variable called value. And now let's ah, have a try catch block just to make sure that we are capturing any error that might happen . Let's say the user just entered any special character or or texts or whatever. Then at least we can catch those errors. So in here we are going out to right into the LBL Info label. Remember that the text equals invalid input and then we'll come. Captain ate the message, the error message and then lbl info that four color cooler that read. Okay, this is, uh, Capital T. Okay, Now let us write a code in our try catch block. I mean, in the tribe up. So we are now basically validating the textbooks value. Next. If let's say that the textbooks property, I mean the textbooks control that's being passed the text. And let's also introduce the dream common here just to make sure that there is no extra ah spaces, it textbooks the text. The dream equals an empty string. Then say lbl info, that text. Let's just say this entry value and Let's also make that four color that red because those are error message else we know get the value double that. He used the double that parse method, which means that whatever values in there, we are parsing it to make sure that they are valued at double value. That dream then, is valued. It was true, which means that when we parsed the value that's being entered and we get the value here without any error, that that is a valid value. Otherwise it's parsed. Then it's something else, like a special Carter's. It might cost on error than it will be catching our cut your block here. And of course, we have to return The is valid, which is either true or false. So the default body disposed, which means that it will remain false if if it didn't go through into this statement here, which means it's either going here or here, which the value will still remain false. Otherwise it will change to true. Then we return, whatever the value here. Okay, so these now our validation method. We can use this method into every individual textbooks that were going to validate the data later on So the first thing that we need to do now is basically validate with. So let me declare one variable here. Same variable name is valid. Now we call the validate entry and we pass on the txt with control. OK, now we have to check the value off. This is valued. If it is, value equals false. Then it was say, message box that show invalid with Just say here, please enter a valid value. Okay? And then let's put ah more I cant in our message box that okay as it's about us Icahn that let's call that as error, okay? And then, of course, since it has since the textbooks has a invalid value, we will remain the focus into that particular control and we return reach, miss Nothing. Nothing further will be executed, which means that it already failed in the first Ah validation. Ah section here. So however, if let's say past week, which means that it did not go into this cold blob we are not going to validate the height . Same thing we used the is valued variable to validate the now that txt height textbooks control so same thing we just have to copy the scope. Look for faster coding. Now, we only need to change the message here. Invalid height. The center a valued value. It's should be capital. OK, there you go. Okay. I think there is a missing, uh, parameter here. It should be dead. The caption before the buttons and icons. So this book here error, okay? And of course, you have to change this to TXT height because that is the control that we're validating. Okay, Next. So assuming that these valued the height is also valid, the user can continue. I mean, the code can continue no going back to the code, which means that we passed this to validations here. Now, if the yusor selected the pick on screen, for example, so what we need to do it's prompt the user in the outward command prompt to select on screen. So that's what we're going to do next. So if r b big on screen, that check that is the the event that gets triggered for the radio button. If it's checked or not, So we will now ask for, uh, insertion point. There it goes. So when we are prompting the user to use the AutoCAD window. We need to hide the form. So in this case, we need to execute the hide common this that hide this misses the form the kind object that we are dealing with. And then we will use the editor. Input this. Ah, editor E T t. Let me just add the name spaces for that using the desk that autocad that editor in Portland. Okay, so editor 80 D crossed off the vest that autocad the application services, That application document manager that MD I active document that editor. I'm using this long name space because I did not declare it here. That's just the same. You might notice here that this portion of the code is gray, but that is actually needed because the the Windows form has its own application object also. That's why we need these portion here. If we remove that, For example, this 10 my good. Have some error. Because it is assuming that this is getting from the Windows form application, which is not the case. We're getting it from the other desk library. Okay, so next that we have the editor now, we need to have a prompt point options from point options. Since we are asking for the point, it was, ah, from point options P P o new prompt point options Pick there, lower left corner off the rectangle. Okay. And then, to get the point that the user picks, we have to have a pull prompt point result Variable. That's called this SPP are because from editor that get point and then pass on the prompt point options. And now we can have the body restored in our ah, insertion point. Let's call these asses point three D. In speedy groups, we also need the name space for that, which is the Gattaca. That geometry. Okay, But since this particular variable will be used all over these code, let me just put this and, uh, at the top so that it will be accessible by all the methods. And let me also create here a variable for the ex Corde and for the white cord for the X and y coordinate later on. Okay, so now that we have those variables, we can restore that the point that the user pic on screen into in speedy, then it's just PPR that value, and then we can show the form back again to the user. All right to these. Good. We're done with the event when the yusor a picked on this screen option. I mean, when the pick on screen is checked next, we know have to verify if the coordinates the radio button coordinates is checked. So we now have to validate exc ordinate something when we are when what we've done in here for the within the height will have to do the same thing here for the x and Y coordinates. So let me just copies over. We just changed the control name we'll be using. The same is valued variable, and then we'll pass on here. The x coordinate. So now the message here is that invalid. Okay, according it Okay. And then this will be that txt x co ordinate and then return. Next. I will copy this code and then the validate the y co ordinate. So we passed on the why Gored control. And then we just have to change this message here. And of course, this control has to be the extra white cord in it, and that's it. So if both of these values are valued now, we can store the X and Y coordinates into the variables that we have created earlier At the top, he will also be doing the parsing double that parse txt ex corde, the text that dream and then the white cord would be double that parse p x t y chord that text that dream. And then now the insertion point will be new point three d ex corde Then why cord than zero That's does that Okay, so next, Which means that all of this past we can now capture the direct the with in the height of the rectangle So double with was double that parse txt with that text that dream and also the height noble that parse txt height that text, that treatment and then we Now we can call this method here I'm in this class Winston shade the rectangle you till class and then we can pass on all of this value that we have ah, recede from the user. Okay, so rectangle you feel media school that us wrecked equals new rectangle Until so correct Now that draw a rectangle we will pass on the web, the height and the insertion point and Now we will provide message to the user that lbl in full the text equals rectangle waas created successfully. And then let's make these four cooler equals color that green, which means that all this good and that's it. However, there are two more actions that we have to handle. That is when they use sir clicks on either off these to radio buttons. So let's do it now if I click on here, I mean, if I click on the screen, it will generate the check chains, method or event, which means that we are going to deactivate or disable the G B coordinates G B coordinates that enabled equalised falls so that the user can no longer enter any value in there. Okay, so now let's also handle these. Ah, the radio button to inter coordinates, which means that we have to activate this group. Bucks control Here. There you go. So G B coordinates that enabled I think waas true, and that's it for the code in here. So just to summarize quickly, we have added to these control name spaces. We have added these variables and then we have a button drawer rectangle click event that we handled all the validations and he created another method to validate all the text box controls. And also we have created this event for the radio button pick on screen and co ordinates. And that's it. We should be ready now to Instant. She ate this form into in our rectangle util class. We will do that in the next video. I'll see you there. 21. 05 RunningRectangleForm: Okay, guys. So now we are ready to instant. She ate this form into our rectangle. You peel class So let's do that in here. We just have one method. The draw rectangle with what we're going to create now is the the the breeds or basically the entry point where the U sir can display the form. So let us great a method called public void. Sure rectangle former. What we need to do here is instant shade the rectangle form so rectangle form it's just school visas are graphic waas new rectangle form and then our f that show okay, which means that the form will display in AutoCAD. But I hope you still remember how to execute a plug in in in Ottawa would prompt we need to have a common method. This will be the command that they have type in in the prompt. Let's just use the same, uh, name show rectangle form and the the deformed should show up Okay, so we can give this a try now, but let me just verify the project, draw a rectangle properties and go to debug, which means that when we start the debugging, we need to start the AutoCAD application. So in my case, the installation is in the program files at the desk. What about 2019? And we have here the a cut that dxy. All right, So that is after God will open up when we run this project. So let's do it now. Let's click on start. Okay, so now let us type in the Net. Load comment. Net load and we be load the plugging. It should be a in the projects plugging projects, Joe Rectangle being folder and the bug. And this is the plug in that we need. Okay, now let's try our show rectangle Common show rectangle form. There you go. See, the maximize button is disabled. Let's give it a try, for example, that's just click on these button without entering anything. Let's see the message invalid with Please enter a valid value, which means that our validation works. And also we have here from the LBL info These the okay and it's their icon in this the error Rick option. So let's Enderlin say, 100 for the wheel and then 64 the height, and if I click on the picture on screen, it should be activated. These group bus control here, let's see. Yep. Which means that I can no longer enter anything we activate. I mean, if we choose to enter the co ordinates, it's activated. Which means that our code so far he's working. Let's try to pick on the screen and draw rectangle. So now we can pick anywhere here. Oops. Tangle is drone successfully. There you go. That is our rectangle zooming to identify that. I mean, that's checked the distance from here to here in this 100 they should be 60. And we still have our form here. No, that's tried to enter corniness. It's a problem. Make it a 302 100 drawer. Dungan rectangle was grated successfully where instead, zoom extents. Here you go. So that strike what this discord in its here. This is the 300 and 200 put away yet. So this is the 2nd 1 Okay, so let's say I don't ender anything in the white cord in it. Invalid y co ordinate. Please enter value. Nice. It's safe for the X invited x cordant. This injury valued value. All right, so that's how it works. We've just successfully graded our very first the project. So I leave it to you, give it a try, try to do some experimentation on some of these controls and see how it goes. So I'll see you in the next project.