Author Topic: Good place to start learning  (Read 12975 times)

0 Members and 1 Guest are viewing this topic.

LE

  • Guest
Re: Good place to start learning
« Reply #15 on: July 20, 2006, 11:57:52 AM »
Hey Tim;

Here is a blog site about C#.... I got the impression that the samples in there are from Master Bobby Jones (I guess)

http://as.vis.ne.jp/home/blog/archives/arx/

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Good place to start learning
« Reply #16 on: July 20, 2006, 12:00:31 PM »
Hey Tim;

Here is a blog site about C#.... I got the impression that the samples in there are from Master Bobby Jones (I guess)

http://as.vis.ne.jp/home/blog/archives/arx/
Thanks Luis.  Bookmarked.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Good place to start learning
« Reply #17 on: July 20, 2006, 12:57:46 PM »
Looks like 1.1 for now.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Good place to start learning
« Reply #18 on: July 20, 2006, 02:11:38 PM »
Since I'm still starting I think I will contiue to post questions here, so that others will have a really good place to start.

Here is my question.  I have followed some examples (Hello world, kind).  I'm using SharpDelevop 1.1.  I opened a new project, select C# categorie, the selected Class Library, then added the References to Autocad (Autodesk.AutoCAD.Interop and Autodesk.AutoCAD.Interop.Common).  Typed in the code below per the example on Cadalyst.  But it errors with the quote below the code.

Any help/insight is greatly appreciated.  Thanks again.

Code: [Select]
/*
 * Created by SharpDevelop.
 * User: a0kcdzz
 * Date: 7/20/2006
 * Time: 10:29 AM
 *
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using acadApp = Autodesk.AutoCAD.ApplicationServices.Application;

public class HelloWorld
{
[Autodesk.AutoCAD.Runtime.CommandMethod("TestHello")]
public void HelloCommand()
{
acadApp.DocumentManager.MdiActiveDocument.Editor.WriteMessage(_"Hello world from C#!!");
acadApp.UpdateScreen();
}

}
Quote
------ Build started: Project: Test Configuration: Debug ------
Performing main compilation...


MyClass.cs(11,24): error CS0234: The type or namespace name 'Runtime' does not exist in the class or namespace 'Autodesk.AutoCAD' (are you missing an assembly reference?)
MyClass.cs(12,24): error CS0234: The type or namespace name 'ApplicationServices' does not exist in the class or namespace 'Autodesk.AutoCAD' (are you missing an assembly reference?)
MyClass.cs(13,34): error CS0234: The type or namespace name 'ApplicationServices' does not exist in the class or namespace 'Autodesk.AutoCAD' (are you missing an assembly reference?)
MyClass.cs(17,21): error CS0234: The type or namespace name 'Runtime' does not exist in the class or namespace 'Autodesk.AutoCAD' (are you missing an assembly reference?)

Build complete -- 4 errors, 0 warnings
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

TR

  • Guest
Re: Good place to start learning
« Reply #19 on: July 20, 2006, 02:31:32 PM »
Tim:
You are trying to run managed code without adding the managed assemblies. If you are running 2006 add a reference to acmgd.dll and acdbmgd.dll (found in your AutoCAD directory) and all should be well.

LE

  • Guest
Re: Good place to start learning
« Reply #20 on: July 20, 2006, 02:32:39 PM »
Quote
Step 1 – Hello World: Accessing ObjectARX .NET Wrappers

In this lab, we will use Visual Studio .NET and create a new Class Library project. This project will create a .NET dll that can be loaded into AutoCAD. It will add a new command to AutoCAD named “HelloWorld”. When the user runs the command, the text “Hello World” will be printed on the command line.

Launch Visual Studio and then select File> New> Project. In the New Project dialog select Visual C#
Projects for the Project Type. Select “Class Library” template. Make the name “Lab1” and set the location where you want the project to be created. Select ok to create the project

In Class1.cs notice that a public class was automatically created. We will add our command to this class. To do this we need to use classes in the AutoCAD .NET managed wrappers. These wrappers are contained in two managed modules. To add references to these modules, right click on “References” and select “Add Reference”. In the “Add Reference” dialog select “Browse”. In the “Select Component” dialog navigate to the AutoCAD 2006 directory. (C:\Program Files\AutoCAD 2006\) Find “acdbmgd.dll” and select open. Click “Browse” again then find and open “acmgd.dll”. Click ok in the “Add Reference” dialog once these components are selected.

Use the Object Browser to explore the classes available in these managed modules. (View > Other Windows >Object Browser. Expand the “AutoCAD .NET Managed Wrapper” object. Throughout the labs we will be using these classes. In this lab an instance of “Autodesk.AutoCAD.EditorInput.Editor” will be used to display text on the AutoCAD command line. Expand the “ObjectDBX .NET Managed Wrapper” object. The classes in this object will be used to access and edit entities in the AutoCAD drawing. (following labs)

Now that we have the classes referenced we can import them. At the top of Class1.cs above the declaration of Class1 import the ApplicationServices, EditorInput and Runtime namespaces.

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;

We will now add our command to Class1. To add a command that can be called in AutoCAD use the “CommandMethod” attribute. This attribute is provided by the Runtime namespace. Add the following attribute and function to Class1.

[CommandMethod("HelloWorld")]
   public void HelloWorld()
{

}

 When the “HelloWorld”  command is run in AutoCAD, the HelloWorld function will be called. In this function we will instantiate an instance of the editor class which has methods for accessing the AutoCAD command line. (as well as selecting objects and other important features) . The editor for the active document in AutoCAD can be returned using the Application class. After the editor is created use the WriteMessage method to display “Hello World” on the command line. Add the following to the function HelloWorld:

Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
ed.WriteMessage("Hello World");

To test this in AutoCAD we can have Visual Studio start a session of AutoCAD. Right click on “Lab1” in Solution Explorer and select “Properties”. In the Lab1 Property Pages dialog select “Configuration Properties > Debugging. In the Start Action area, choose ‘Program’ under “Debug” and in “Start applications” use the ellipses button and browse to acad.exe. After changing this setting hit F5 to launch a session of AutoCAD.


The “NETLOAD” command is used to load the managed application. Type NETLOAD on the AutoCAD command line to open the “Choose .NET Assembly” dialog. Browse to the location of “lab1.dll” (..\lab1\bin) select it and then hit open.

 
Enter “HellowWorld” on the command line. If all went well, the text “Hello World” should appear. Switch to Visual Studio and add a break point at the line: ed.WriteMessage(“Hello World”). Run the HelloWorld command in AutoCAD again and notice that you can step through code.


If you have time you can explore the CommandMethod attribute. Notice that it has seven different flavors. We used the simplest one that only takes one parameter. (the name of the command). You can use the other parameters to control how the command will work.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Good place to start learning
« Reply #21 on: July 20, 2006, 02:45:33 PM »
Thank you Tim and Luis.  I needed to load the dll files.  I thought if I loaded the two references I didn't need to load the dll's.

Since I made a project with all the correct references, should I just use that project to code all my Acad code in? or do I want to make a new project per code piece?
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.