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

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
Good place to start learning
« on: July 19, 2006, 05:22:13 PM »
Here is an artical which looks like a good place to start learning C# coding for Autocad.  Goes over some basic drawing objects.

Quote
Hi all C# lovers,
Recently, I did a project for Govt. PSU which involved using AutoCAD with C# and I found it very interesting. I am very eager to share it with you.

This article shows how to use AutoCAD objects in a .NET application using C#.
Tim

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

Please think about donating if this post helped you.

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: Good place to start learning
« Reply #1 on: July 19, 2006, 06:48:26 PM »
Does this mean you've decided to skip VBA and jump right into C#? :-)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Good place to start learning
« Reply #2 on: July 19, 2006, 06:53:48 PM »
Does this mean you've decided to skip VBA and jump right into C#? :-)
Will see.  At work I don't have the required .net framework, and I don't think if the IT people will freak (they are cool here).  I will ask them and see if they care.  If so, then maybe. :wink:

Was figuring if I have to learn a new language, let it be powerful.

But this one makes it look kind of easy to start.  I will digest it all tonight.
Tim

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

Please think about donating if this post helped you.

LE

  • Guest
Re: Good place to start learning
« Reply #3 on: July 19, 2006, 07:10:55 PM »
Tim;

Very good, that you will be moving to the dark side.... !!!!!!

(I know about those samples..... and I can tell, we have Masters on that HERE @theSwamp...  :-))

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: Good place to start learning
« Reply #4 on: July 19, 2006, 07:16:26 PM »
That is a good place to start in C# with AutoCAD especially if you're familiar with vba as all the examples are using COM. You will be familiar with the AutoCAD Object model and will only notice the different syntax required for C# which will help ease you into the language and be productive at the same time.
Using the managed arx wrappers is the way to go though but has a 'little' steeper learning curve.
Cheers,
Mick.
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Good place to start learning
« Reply #5 on: July 19, 2006, 07:34:09 PM »
Tim;

Very good, that you will be moving to the dark side.... !!!!!!

(I know about those samples..... and I can tell, we have Masters on that HERE @theSwamp...  :-))
I have been broken down, and I can't resist any longer.  Thanks Luis.  You know I will be asking for help, if I can install the needed stuff on my computer, which I think won't be a problem.

That is a good place to start in C# with AutoCAD especially if you're familiar with vba as all the examples are using COM. You will be familiar with the AutoCAD Object model and will only notice the different syntax required for C# which will help ease you into the language and be productive at the same time.
Using the managed arx wrappers is the way to go though but has a 'little' steeper learning curve.
Cheers,
Mick.
I use the ActiveX controls through AutoLisp, so I have a little understand of the object model.  Do you/anyone have some basic examples of the arx wrappers?  If that is the way to go, how much harder will it be to learn?  I will search for that tonight also then.  Thanks.
Tim

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

Please think about donating if this post helped you.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Good place to start learning
« Reply #6 on: July 19, 2006, 08:45:47 PM »
Quote
Do you/anyone have some basic examples of the arx wrappers?

http://www.theswamp.org/index.php?topic=8245.msg141017#msg141017


Some Samples provided by Jim Awe at AutoDesk <public issue> .  ... for 2006 ; he is working on 2007
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Good place to start learning
« Reply #7 on: July 19, 2006, 09:27:21 PM »
Quote
Do you/anyone have some basic examples of the arx wrappers?

http://www.theswamp.org/index.php?topic=8245.msg141017#msg141017


Some Samples provided by Jim Awe at AutoDesk <public issue> .  ... for 2006 ; he is working on 2007

Thanks Kerry.  I don't know what I can do with these at home, but I will see.
Tim

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

Please think about donating if this post helped you.

Bobby C. Jones

  • Swamp Rat
  • Posts: 516
  • Cry havoc and let loose the dogs of war.
Re: Good place to start learning
« Reply #8 on: July 20, 2006, 08:06:25 AM »
At work I don't have the required .net framework,
acad 2005 and 2006 install the 1.1 version of the framework, 2007 installs version 2.0.  You'll just need the .NET SDK and an IDE.  And technically the IDE is optional, but only if you're a masochist...
Bobby C. Jones

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Good place to start learning
« Reply #9 on: July 20, 2006, 11:12:17 AM »
At work I don't have the required .net framework,
acad 2005 and 2006 install the 1.1 version of the framework, 2007 installs version 2.0.  You'll just need the .NET SDK and an IDE.  And technically the IDE is optional, but only if you're a masochist...
I thought I read somewhere that 2006 needed .net 2.0.  If you say I don't need 2.0, then all I need is a good FREE ide I guess.  I will see what I can find.  The article I read mentioned ShartDevelop as and ide to use, and I think Tim R. uses it also.

Where do you get the .Net SDK from?  I don't think I have run across that yet.

Thanks for the info Bobby.
« Last Edit: July 20, 2006, 11:13:23 AM by T.Willey »
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 #10 on: July 20, 2006, 11:16:31 AM »
The article I read mentioned ShartDevelop as and ide to use, and I think Tim R. uses it also.

Anyone else think of "Along Came Polly" when they read that?

TR

  • Guest
Re: Good place to start learning
« Reply #11 on: July 20, 2006, 11:31:33 AM »
I use SharpDevelop2 to run .NET 2.0 apps on AutoCAD 2005 and all is well. For SharpDevelop2 all you need is the .NET 2.0 runtime and you will be able to build and run 2.0 apps. If you want the .NET 2.0 documentation you will need the SDK available @ http://msdn.microsoft.com/netframework/downloads/updates/default.aspx

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Good place to start learning
« Reply #12 on: July 20, 2006, 11:36:55 AM »
I use SharpDevelop2 to run .NET 2.0 apps on AutoCAD 2005 and all is well. For SharpDevelop2 all you need is the .NET 2.0 runtime and you will be able to build and run 2.0 apps. If you want the .NET 2.0 documentation you will need the SDK available @ http://msdn.microsoft.com/netframework/downloads/updates/default.aspx
But if I don't want to install .NET 2.0, can I run SharpDevelop1.1 with the .NET framwork already installed on my computer, and use the SDK from here? (version 1.1)

Sorry for the nubish questions.  I'm running 2006 right now.
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 #13 on: July 20, 2006, 11:39:24 AM »
Yes, you can do that. I recommend SD2 and .NET 2.0 though.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Good place to start learning
« Reply #14 on: July 20, 2006, 11:49:07 AM »
Yes, you can do that. I recommend SD2 and .NET 2.0 though.
Thanks for the info Tim.  I will have to talk with my IT people then.  If they say it is ok, I will grab all the 2.0 stuff.
Tim

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

Please think about donating if this post helped you.

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.