Author Topic: AU 2005 - Example Code Project  (Read 12954 times)

0 Members and 1 Guest are viewing this topic.

Bobby C. Jones

  • Swamp Rat
  • Posts: 516
  • Cry havoc and let loose the dogs of war.
AU 2005 - Example Code Project
« on: January 03, 2006, 02:15:47 PM »
Per request, attached are the VS2005 project files for my AU2005 code samples.  I *may* have an older VS2003 version of this project lying around if anyone is interested.  Just let me know.
Bobby C. Jones

LE

  • Guest
Re: AU 2005 - Example Code Project
« Reply #1 on: January 03, 2006, 03:48:44 PM »
Per request, attached are the VS2005 project files for my AU2005 code samples.  I *may* have an older VS2003 version of this project lying around if anyone is interested.  Just let me know.

Is possible to run this samples on SharpDevelop ? ... [I have AutoCAD 2005]

Thanks.

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: AU 2005 - Example Code Project
« Reply #2 on: January 03, 2006, 04:25:08 PM »
Yes you can Luis, you may have to change the 'using' statements slightly as it seems SharpDev reads the ref'd assemblies a little differently, this may have changed in later releases though.
Also, if the sample was built for 2006 it probably won't compile for 2005 as they changed quite a few of the wrappers (mainly for the editor and UI) and made them more complete for 2006.

If you have VS2002 you should have no trouble, this is what I use at the moment with no prob's so far.
hth
"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

LE

  • Guest
Re: AU 2005 - Example Code Project
« Reply #3 on: January 03, 2006, 04:30:48 PM »
Yes you can Luis, you may have to change the 'using' statements slightly as it seems SharpDev reads the ref'd assemblies a little differently, this may have changed in later releases though.
Also, if the sample was built for 2006 it probably won't compile for 2005 as they changed quite a few of the wrappers (mainly for the editor and UI) and made them more complete for 2006.

If you have VS2002 you should have no trouble, this is what I use at the moment with no prob's so far.
hth

 :-(

I see, I just want to play for now.... nope it will allow only 2003 solutions... I have VS2002 but it is the "standard" version.....  does not include C#... OK.. I will download the 2005 express.... for now [will that work?]

Thanks.

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: AU 2005 - Example Code Project
« Reply #4 on: January 03, 2006, 04:47:40 PM »
Before you do, create a new project, add your references and add just the .cs files into your project (or copy and paste the code from a std text editor into new files). It's only the version of vs that's givving you the trouble ;)
"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

LE

  • Guest
Re: AU 2005 - Example Code Project
« Reply #5 on: January 03, 2006, 05:10:16 PM »
Before you do, create a new project, add your references and add just the .cs files into your project (or copy

Let me explain, what I did before:

1. I started a Class Library
2. Added the references: From the .NET assembly browser and use: "ACDBMGD.DLL" and "ACMGD.DLL"
3. In the HelloWorld.cs - I added:

Code: [Select]
using System;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using acadApp = Autodesk.AutoCAD.ApplicationServices.Application;

namespace HelloWorld
{
/// <summary>
/// Description of HelloWorld.
/// </summary>
public class HelloWorld
{
[Autodesk.AutoCAD.Runtime.CommandMethod("HELLO")]
public void HelloCommand()
{
acadApp.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Hello World FROM C#!");
acadApp.UpdateScreen();
 
}

}
}

I hit the Build option and get:
'Autodesk.AutoCAD.ApplicationServices.Document' does not contain a definition for 'Editor'


MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: AU 2005 - Example Code Project
« Reply #6 on: January 03, 2006, 05:34:12 PM »
Luis, try replacing

acadApp.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Hello World FROM C#!");

with -

CommandLinePrompts.Message("Hello World FROM C#!");//using the Autodesk.AutoCAD.Application namespace
"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

LE

  • Guest
Re: AU 2005 - Example Code Project
« Reply #7 on: January 03, 2006, 05:42:06 PM »
Luis, try replacing

acadApp.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Hello World FROM C#!");

with -

CommandLinePrompts.Message("Hello World FROM C#!");//using the Autodesk.AutoCAD.Application namespace

 :-o
Aaaaaaaaaaa..... that was it.... that's good!!!, where can I read about those functions or calls? - I see that I do not have to close nothing?... all is managed code like in LISP ?.....

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: AU 2005 - Example Code Project
« Reply #8 on: January 03, 2006, 05:49:03 PM »
You'll probably have to look at the doc's that came with your arx sdk and find suitable replacements for things that won't work. Just holler if you have trouble finding suitable classes.
Quite a few things changed from 2005 to 2006 including some of the geometry classes (matrices for eg) so this will happen quite a bit!

Once you start opening objects and bt's etc. you will need to close them unless you are using transactions which will take care of this for you, I'm not sure if this is the case with arx and tranactions though(?).
"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

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: AU 2005 - Example Code Project
« Reply #9 on: January 03, 2006, 05:52:20 PM »
Luis, try replacing

acadApp.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Hello World FROM C#!");

with -

CommandLinePrompts.Message("Hello World FROM C#!");//using the Autodesk.AutoCAD.Application namespace

I was trying to find some old code .. I couldn't remember that .. DUH !
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.

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: AU 2005 - Example Code Project
« Reply #10 on: January 03, 2006, 05:54:16 PM »
Here's some old code I used for a template you may find useful.
"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

LE

  • Guest
Re: AU 2005 - Example Code Project
« Reply #11 on: January 03, 2006, 06:02:38 PM »
Once you start opening objects and bt's etc. you will need to close them unless you are using transactions which will take care of this for you, I'm not sure if this is the case with arx and tranactions though(?).

OK, I think not sure.... it is the same as in ObjectARX

Code: [Select]
long i, length;
ads_name ename;
AcDbObjectId entId;
acedSSLength(m_sset, &length);

// Traverse selected entities
acdbTransactionManager->startTransaction();

for (i = 0; i < length; i++) {
// obtener el objectId de cada entidad
acedSSName(m_sset, i, ename);
acdbGetObjectId(entId, ename);
// abrir la entidad y borrarla
// es recomendable inicializar el pointer
// y darle el valor de 0 o NULL que es lo mismo
AcDbEntity* pEnt = NULL;
if (acdbTransactionManager->getObject((AcDbObject*&)pEnt,entId,AcDb::kForWrite) == Acad::eOk) {
pEnt->erase();
}
}

acdbTransactionManager->endTransaction();

Are Smart Pointers available on C# ?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: AU 2005 - Example Code Project
« Reply #12 on: January 03, 2006, 06:07:30 PM »
Luis, Have alook at this by Glenn
http://www.theswamp.org/forum/index.php?topic=8197.msg105289#msg105289

Does almost the same thing


Well, NOT the same, but you'll get the idea :-)
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.

LE

  • Guest
Re: AU 2005 - Example Code Project
« Reply #13 on: January 03, 2006, 06:18:22 PM »
Luis, Have alook at this by Glenn
http://www.theswamp.org/forum/index.php?topic=8197.msg105289#msg105289

Does almost the same thing


Well, NOT the same, but you'll get the idea :-)

Start to get confused............  :lol:

I don't see in there any place to call the endTransaction() ... It is because if Managed Code no?

Well.... at least I have an idea now [I think]

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: AU 2005 - Example Code Project
« Reply #14 on: January 03, 2006, 06:23:53 PM »
The EndTransaction is automagic BECAUSE the code operates inside this :

using (Transaction tr = ...
{


   
}

     
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.

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: AU 2005 - Example Code Project
« Reply #15 on: January 03, 2006, 06:27:27 PM »
This is another way to do it without using 'using'
Code: [Select]
public void SomeFoo()
{
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
Transaction tr = db.TransactionManager.StartTransaction();
try
{
//do stuff here!
tr.Commit();
}
catch
{
ed.WriteMessage("KaBoom!..");
}
finally
{
tr.Dispose();
}
}

as with most things there are a few ways to do them :-)
« Last Edit: January 05, 2006, 04:08:01 PM by MickD »
"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

Glenn R

  • Guest
Re: AU 2005 - Example Code Project
« Reply #16 on: January 03, 2006, 07:23:34 PM »
A 'using' statement is really shorthand for a 'try/finally' construct.

I tend to use the using if it's one thing - if I have more I tend to use try/catch/finally to avoid all the nesting of multiple 'using' statement.

Cheers,
Glenn.

Bobby C. Jones

  • Swamp Rat
  • Posts: 516
  • Cry havoc and let loose the dogs of war.
Re: AU 2005 - Example Code Project
« Reply #17 on: January 05, 2006, 12:16:08 PM »
I tend to use the using if it's one thing - if I have more I tend to use try/catch/finally to avoid all the nesting of multiple 'using' statement.
Hey Glenn,
You can put more than one object declaration in the using statement to avoid nesting.

Code: [Select]
using (DisposableObject1 do1 = new DisposableObject1(),
       DisposableOjbect2 do2 = new DisposableOjbect2())
{
    .....do your thing.....
}

I have also seen this syntax:
Code: [Select]
using (DisposableObject1 do1 = new DisposableObject1())
using (DisposableObject2 do2 = new DisposableObject2())
{
    .....do your thing.....
}
but it doesn't look valid according to the 2.0 docs.  Maybe its OK in an earlier version?  Or more likely, I'm just off my rocker :-)
Bobby C. Jones

Glenn R

  • Guest
Re: AU 2005 - Example Code Project
« Reply #18 on: January 05, 2006, 06:20:50 PM »
Heh...I had forgotten about that. Thanks for the reminder.

I still prefer the try/finally construct with multiples, as I tend to declare things as close to possible to when i need them in code...
another habit from C++.

Cheers,
Glenn.

Bobby C. Jones

  • Swamp Rat
  • Posts: 516
  • Cry havoc and let loose the dogs of war.
Re: AU 2005 - Example Code Project
« Reply #19 on: January 06, 2006, 09:27:28 AM »
I still prefer the try/finally construct with multiples, as I tend to declare things as close to possible to when i need them in code...
Excellent point Glenn!
Bobby C. Jones

BazzaCAD

  • Guest
Re: AU 2005 - Example Code Project
« Reply #20 on: July 17, 2006, 06:17:52 PM »
Per request, attached are the VS2005 project files for my AU2005 code samples.  I *may* have an older VS2003 version of this project lying around if anyone is interested.  Just let me know.


Sorry, total noob here.
When trying to compile your code in VS2005 Express I get this error over & over again
"The type or namespace name 'Autodesk' could not be found (are you missing a using directive or an assembly reference?)"
Is this an issue with Express, or is there something in the code I need to change?

thx for the help.

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: AU 2005 - Example Code Project
« Reply #21 on: July 17, 2006, 06:30:29 PM »
Hi BazzaCAD, make sure you have your using statements at the top of your code file, eg. -

using System;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using acadApp = Autodesk.AutoCAD.ApplicationServices.Application;

- add others as required. This lets the compiler know which libraries and namespaces you are using.

Also make sure you have any libraries 'referenced' in, right click on 'References' in your solution explorer and choose 'Add reference' and browse for the 2 autocad dll's in the acad directory required to build your project.
A screen shot -
"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

BazzaCAD

  • Guest
Re: AU 2005 - Example Code Project
« Reply #22 on: July 17, 2006, 08:35:44 PM »
OK I got it to compile now but I get a .DLL, I thought I'd get a .ARX. How do I load this into Acad?
Sorry for my ignorance, this is all greek to me  :-)

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: AU 2005 - Example Code Project
« Reply #23 on: July 17, 2006, 08:46:15 PM »
No prob's, an ARX file is basically only a normal dll with a different extension that AutoCAD recognises.

To load a .net dll, type NETLOAD and select your dll and away you go!
"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

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
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.