Autodesk Official latest. NET Tutorial (ii) (VB. NET edition)

Source: Internet
Author: User
Tags command line tostring visual studio
Tutorials   2nd Chapter  . NET AutoCAD wizards and simple user input         in the first chapter, we use the class library template, So you have to join ACDBMDG by hand. DLL and Acmgd.dll are two references. In this chapter, we will use the AutoCAD Managed C # application Wizard to create. NET project, it will automatically add the above two references. Before you begin this chapter, you first have to install the Objectarx Wizard (the \utils\objarxwiz\arxwizards.msi of the ObjectARX2006 development package). &NBSP;&NBSP;&NBSP;1)     Start Visual Studio. NET, select File > New > Project (file> new> project). In the New Project dialog box, select the project type as Visual basic Engineering, and then select the AutoCAD Managed VB Project Application template. Enter "LAB2" in the Project Name box and select the location where the project is stored. Click OK button, "AutoCAD Managed VB Application Wizard" dialog box will appear. Because we do not need to use unmanaged code, do not select the "Enable unmanaged Debugging" item. "Registered Developer Symbol" will use the value you entered when you installed the Objectarx Wizard. Click the Finish button to create the project. 2     below to see the project generated by the wizard. In the Solution Explorer, you will see that ACDBMGD and ACMGD have been referenced. In the Class.vb file, the "Autodesk.AutoCAD.Runtime" namespace has been imported, and the project uses the name "registered Developer Symbol" for naming the default public class. The wizard also adds a Commandmethod property and a function to the class for the AutoCAD command. 3        in the previous chapter, we use an instance object of the "Autodesk.AutoCAD.EditorInput.Editor" class to output text on the AutoCAD command line. In this chapter, we will use this class to prompt the userIn the AutoCAD graphic, select a point and then display the X,y,z value of the user's selected point. As in the previous chapter, import the Autodesk.AutoCAD.ApplicationServices and Autodesk.AutoCAD.EditorInput namespaces.  imports Autodesk.AutoCAD.ApplicationServicesImports autodesk.autocad.editorinput 4)         change the value of the wizard-generated Commandmethod property to meaningful names such as "Selectpoint" (the name of the function may not be modified). The Promptpointoptions class is used to set the hint string and other options for some control hints. An instance of this class is passed into the Editor.getpoint method as a parameter. At the beginning of the function, instantiate the class and set the string argument to "Select a point". Because the Editor.getpoint method returns an instance object of the Promptpointresult class, we also instantiate it.       Dim prpointoptions As Promptpointoptions =new promptpointoptions ("Select a Point") Dim Prpointres as Promptpointresult 5)        Next, instantiate an object of the editor class and use the GetPoint method with the parameter as the Promptpointoptions object. Assigns a value to the Promptpointresult object declared above, using the return value of the GetPoint method. After the assignment is good, we can test the state of the Promptpointresult object and return if it is not OK.  dim ed as Editor = application.documentmanager.mdiactivedocument.editor            prpointres = ed. GetPoint (prpointoptions)             If prpointres.status <> Promptstatus.ok Then                  return nothing            end if 6)        If the Promptpointresult object returns a valid point, we can use the Writemessage method to output the result to the command line. The Promptpointresult.value tostring method makes the output very easy:  ed. Writemessage ("You selected Point" & PrPointRes.Value.ToString ())  7)        Press F5 to run a debugging AutoCAD process. (Note: The wizard has been set to use Acad.exe to debug) in the AutoCAD command line, enter Netload, select Lab2.dll and open. Enter your command name (selectpoint) on the command line. At the tip of the selection point, click any point in the graphic. If everything works, you can see the coordinates of the point you selected at the command line. In the Class.vb file, add a breakpoint to the "return Nothing" line, and then run the Selectpoint command again. This time, press the ESC key at the tip of the selection point instead of selecting a point. The state of the Promptpointresult object is not OK, so the IF statement in the above code is executed and the "return to Nothing" statement is invoked. 8        Next we'll add another command that will get the distance between the two points. The wizard does not have the ability to add commands, so we must add them manually. Add a new life named Getdistance below the function (GetPoint) of the Class.vb file's selection pointMake. To add a command, refer to the contents of the previous chapter or the source code of this chapter, which is not listed here. Use the Commandmethod property and make the string argument "Getdistance" or another similar name. Use promptdistanceoptions in the command's function instead of promptpointoptions. Of course the return value of the Getdistance method is an instance object of a Promptdoubleresult class, so use Promptdoubleresult instead of Promptpointresult: dim Prdistoptions as Promptdistanceoptions = New promptdistanceoptions ("Find distance, select a:")   & nbsp;       Dim Prdistres as promptdoubleresult      Prdistres = ed. Getdistance (prdistoptions)   9)        as in the previous command, You can also test the state of the Promptdoubleresult, and then use the Writemessage method to display the value on the command line.  if prdistres.status <> Promptstatus.ok then               return nothing           end if             ed. Writemessage ("The Distance is:" & prDistRes.Value.ToString)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.