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

0 Members and 1 Guest are viewing this topic.

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.