Author Topic: Getting off the Ground with .NET  (Read 22652 times)

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Getting off the Ground with .NET
« on: April 01, 2011, 10:56:23 AM »
Over the past few days I've been looking to take the plunge into the world of C# .NET and have been investigating the tools I need to get me started.

I've looked over the links in the 'Getting Started' thread, and am mainly following the advice offered by the AutoCAD .NET Developer's Guide.

I am running MS Visual Studio 2010 and AutoCAD 2010.

I have downloaded the ObjectARX SDK from here, and, following the instructions detailed in the Dev Guide here, I have attempted to run the 'ArxWizads.msi' file  --> This informs me that I need an instance of MS Visual Studio 2008 on the target machine.

Questions:

Can I develop in .NET with MSVS2010?

Are there version restrictions in C# .NET (i.e. Does an application need to be compiled to suit each version of AutoCAD?).



Your time and advice are appreciated.

Lee

LE3

  • Guest
Re: Getting off the Ground with .NET
« Reply #1 on: April 01, 2011, 11:05:10 AM »
Those are great news, good for you Lee!

- I'm still with VS2005 and VS2008, can't say anything about VS2010.

- You don't need the wizard, it is very simple to setup one without that, I have installed the one that comes with ARX/SDK 2010 and it is very helpful but for ARX apps, because of the project solution skeleton that it does.

- The .NET apps I do, I normally(have) to target for specific acad versions/32/64

Over the past few days I've been looking to take the plunge into the world of C# .NET and have been investigating the tools I need to get me started.

I've looked over the links in the 'Getting Started' thread, and am mainly following the advice offered by the AutoCAD .NET Developer's Guide.

I am running MS Visual Studio 2010 and AutoCAD 2010.

I have downloaded the ObjectARX SDK from here, and, following the instructions detailed in the Dev Guide here, I have attempted to run the 'ArxWizads.msi' file  --> This informs me that I need an instance of MS Visual Studio 2008 on the target machine.

Questions:

Can I develop in .NET with MSVS2010?

Are there version restrictions in C# .NET (i.e. Does an application need to be compiled to suit each version of AutoCAD?).



Your time and advice are appreciated.

Lee

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Getting off the Ground with .NET
« Reply #2 on: April 01, 2011, 11:24:30 AM »
Those are great news, good for you Lee!

Thanks Luis! Its about time I moved on from LISP, I feel that I'm stagnating in that area...

- You don't need the wizard, it is very simple to setup one without that, I have installed the one that comes with ARX/SDK 2010 and it is very helpful but for ARX apps, because of the project solution skeleton that it does.

Thats handy since its not letting me install it at the moment...  :wink: I have installed the Help Documentation and can access the ObjectARX section through the VLIDE Help.

- The .NET apps I do, I normally(have) to target for specific acad versions/32/64

That's a shame, but I suppose I'll just have to accept it and move on with the learning :-)

LE3

  • Guest
Re: Getting off the Ground with .NET
« Reply #3 on: April 01, 2011, 11:33:21 AM »
You can simple set it up to: Any CPU (under properties - that it is by default) I have used .net apps compiled with latest assemblies and they run under previous versions, all depends (maybe) if you are not using anything new, and that will work for you.

If you need something more in specific, let me know.

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Getting off the Ground with .NET
« Reply #4 on: April 01, 2011, 02:12:23 PM »
The wizard requires you to have the "Standard" or "Professional" version of Visual Studio, I believe.  You are using the "Express", I take it?  As mentioned, all is not lost and you might actually do a bit better without the wizard doing the hand-holding.  Pssst: look into templates.   :wink:

Depending on your AutoCAD version (2011 and earlier), Visual Studio 2008 *might* be the better choice.  VS2010 is a very good argument against early adoption.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Getting off the Ground with .NET
« Reply #5 on: April 01, 2011, 04:33:02 PM »
You are using the "Express", I take it?

Professional Version (I'm a student = free stuff  :lol:)

Depending on your AutoCAD version (2011 and earlier), Visual Studio 2008 *might* be the better choice.  VS2010 is a very good argument against early adoption.

I'm using ACAD2010 (student version, but I doubt that matters too much in this respect). So are you saying that VS2010 restricts what I can do in .NET, or that I simply cannot use it? I'm confused in how the version of the editor would play a part in the programming itself - but perhaps this is a feature of compiled code.

On another note, I've had another play with VS2010 using the C# sample code from here. I realise that I don't have the background knowledge of C# as yet, but I wanted to see if I could run some code to ensure that I have everything set up correctly (I wouldn't want to hinder myself before I've even started).

Now, I have opened VS2010 and started a New Project with type: C# Class Library (is this correct, or should I be choosing a console application?) - I have then pasted the C# code from that link to the editor window.

In the Solution Explorer, I went to 'References', 'Add References' and added AcDbMgd.dll and AcMgd.dll as described in the Dev Help (would I have to add these to every project I create?). These removed the majority of the 'warnings' I was receiving in the editor window regarding statements declaring the namespace, such as:

Code: [Select]
using Autodesk.AutoCAD.Runtime;
However I still receive errors on the following lines:

Code: [Select]
public static [color=red]void[/color] AddLine()
Code: [Select]
acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.[color=red]ModelSpace[/color]], OpenMode.ForWrite) as BlockTableRecord;
Code: [Select]
Line acLine = new [color=red]Line[/color](new [color=red]Point3d[/color](5, 5, 0), new [color=red]Point3d[/color](12, 3, 0));
Are these errors in the code or something I have not set up correctly? As I say, I don't have knowledge of C# or how to manipulate AutoCAD with it, but I wanted to ensure I have my environment set up correctly to save trouble further down the line.

Thanks for your help guys, appreciated.

Lee

LE3

  • Guest
Re: Getting off the Ground with .NET
« Reply #6 on: April 01, 2011, 04:57:09 PM »
Lee,

Normally after doing your references (make sure you set Copy Local to false - click on your assembly name and go to properties and you will find that)

Then, for errors or warnings, simple go to those warnings on screen right-click and see if there is available the option of Resolve, click on that and most of the warnings will gone.

Give it a try... and see if helps

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Getting off the Ground with .NET
« Reply #7 on: April 01, 2011, 04:58:14 PM »
Lee,
about time :)

The methods should be wrapped in a class

a piccy :
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.

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Getting off the Ground with .NET
« Reply #8 on: April 01, 2011, 05:04:58 PM »
Normally after doing your references (make sure you set Copy Local to false - click on your assembly name and go to properties and you will find that)

Yup - saw that in the DevHelp - done :-)

Lee,
about time :)

Tell me about it...  :roll:


The methods should be wrapped in a class

a piccy :

A picture is worth a 1000 words - thanks Kerry!

Then, for errors or warnings, simple go to those warnings on screen right-click and see if there is available the option of Resolve, click on that and most of the warnings will gone.

Give it a try... and see if helps

Thanks Luis, I'll look into this after I've tried Kerry's suggestion and report back to you guys :-)

Thanks for the advice!

Lee

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Getting off the Ground with .NET
« Reply #9 on: April 01, 2011, 05:14:16 PM »

Also :
From the menu ;  Project->Properties
Application : set Target Framework to .Net Framework 3.5
Build : Platform Target ; set for Any CPU
Debug : Set Start Action ; Start external Program -> select path to Acad.exe.


In your acad.exe folder do you have a file named acad.exe.config.

Mine reads like this
Code: [Select]
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0"/>
  </startup>

<!--All assemblies in AutoCAD are fully trusted so there's no point generating publisher evidence-->
   <runtime>       
<generatePublisherEvidence enabled="false"/>   
   </runtime>
</configuration>
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.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Getting off the Ground with .NET
« Reply #10 on: April 01, 2011, 05:19:40 PM »
Hi Lee,

Welcome to the .NET adventure...

I can understand you want to try a routine into AutoCAD, but...

I think it's a good way to first learn some .NET and C# for Windows (not related to AutoCAD), there are certainly some good tutorials and books in English...
Speaking English as a French Frog

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Getting off the Ground with .NET
« Reply #11 on: April 01, 2011, 05:35:43 PM »

Also :
From the menu ;  Project->Properties
Application : set Target Framework to .Net Framework 3.5
Build : Platform Target ; set for Any CPU
Debug : Set Start Action ; Start external Program -> select path to Acad.exe.

Thanks - I wouldn't have figured that out - first time I tried to load the .dll it reported that it was built in a later framework or something along those lines (Target Framework was set to 4.0).

BTW, should I be netloading the dll in the 'bin' > 'Debug' folder?

In your acad.exe folder do you have a file named acad.exe.config.

Mine reads like this
Code: [Select]
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0"/>
  </startup>

<!--All assemblies in AutoCAD are fully trusted so there's no point generating publisher evidence-->
   <runtime>       
<generatePublisherEvidence enabled="false"/>   
   </runtime>
</configuration>

Yes, I have that file:

Code: [Select]
<configuration>
   <startup>
<!--We always use the latest version of the framework installed on the computer. If you
are having problems then explicitly specify .NET 2.0 by uncommenting the following line.
<supportedRuntime version="v2.0.50727"/>
-->
   </startup>
<!--All assemblies in AutoCAD are fully trusted so there's no point generating publisher evidence-->
   <runtime>       
<generatePublisherEvidence enabled="false"/>   
   </runtime>
</configuration>

Hi Lee,

Welcome to the .NET adventure...

I can understand you want to try a routine into AutoCAD, but...

I think it's a good way to first learn some .NET and C# for Windows (not related to AutoCAD), there are certainly some good tutorials and books in English...

Thanks Gile :-)

That is my intention - starting from the ground up. But I just wanted to ensure I had my environment set up correctly before I delved too deeply to save some headaches in the future.

Thanks for your support :-)

Lee

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Getting off the Ground with .NET
« Reply #12 on: April 01, 2011, 05:37:46 PM »
Just tried loading the example code and, after loading, typed 'AddLine' and all worked correctly! I'm off the ground  8-)

I noticed it was slightly slow to create the line though (when I say slow, I mean 0.2 secs) would this be because it has to load some dll's when called for the first time?

sinc

  • Guest
Re: Getting off the Ground with .NET
« Reply #13 on: April 01, 2011, 05:38:33 PM »
I can understand you want to try a routine into AutoCAD, but...

I think it's a good way to first learn some .NET and C# for Windows (not related to AutoCAD), there are certainly some good tutorials and books in English...

I'd say the exact opposite...

Since Lee's already quite familiar with Autocad and Autocad customization using other languages, I think it would be a lot faster/easier to just start doing things in Autocad, as opposed to starting with exercises that create unwanted stand-alone apps.

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Getting off the Ground with .NET
« Reply #14 on: April 01, 2011, 05:45:29 PM »
as opposed to starting with exercises that create unwanted stand-alone apps.

That's the route I took with C++ (also taking a module as part of my Maths degree), but this resulted in many console applications and hit a road-block as to how to progress.

I think I'll follow a mixture of the two, learn the C# syntax, and see how to use it for applications in AutoCAD - that way I have a 'purpose' for my code.