Author Topic: "Hello World" a standalone CAD application?  (Read 5307 times)

0 Members and 1 Guest are viewing this topic.

pop

  • Guest
"Hello World" a standalone CAD application?
« on: February 25, 2009, 06:40:13 PM »
Hi,

1. How do you create a standalone application that manipulates multiple CAD drawings? Can it be done using COM only?

What I want to do is access cable schedules in Excel and automatically create motor schematics based on different motor CAD templates. I’ve done this in VBA, but I wanted to rewrite this in NET using OOP and I’m completely stumped.

I do not want to use “netload” for the time being, I’d like this to be a COM application only.
I’ve searched the through Autodesk NET discussion and this forum, and through ObjectARX samples, and didn’t find any examples using COM to write to the drawing database.

Using COM interops, I can open and close my CAD application, but I don’t know how to access the transaction manager and modify the drawing. Unsuccessfully, I’ve tried using acmgd.dll and acdbmgd.dll with COM. After reading about this, I know why it is not the way to do things.

Can you point me to, or write a small example for “Hello World” AutoCAD application using COM?

I am using AutoCAD 2006, Sharpdevelop 2.2. I am programming in VB.NET just so I can avoid typing out all optional parameters that I find annoying in Excel:)

Any help is appreciated.

Glenn R

  • Guest
Re: "Hello World" a standalone CAD application?
« Reply #1 on: February 25, 2009, 06:58:25 PM »
Why do you want it to be a 'stand-alone' application?

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: "Hello World" a standalone CAD application?
« Reply #2 on: February 25, 2009, 07:49:58 PM »
I'm pretty sure you can't use COM for excell without it being installed either, if both are installed you could use COM to get both app's going and not visible and then do your mojo...I think :)
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

pop

  • Guest
Re: "Hello World" a standalone CAD application?
« Reply #3 on: February 26, 2009, 10:35:22 AM »
Thank you for quick responses.

MickD,
You're right. With both installed, I can easily connect to Excel and read and write cells but I can only open/close Autocad. I think I will try ObjectDBX next (http://blog.jtbworld.com/2007/09/objectdbxrealdwg-using-vbnet.html) to actually write to the drawing.

GlennR,
I am learning how and what NET can do with CAD. I am very impressed with all things it can do in-process, but was wondering how can you do same things out of process as well (even though I understand the disadvantages of doing so). I've found a great example by Kean Walmsley (http://through-the-interface.typepad.com/through_the_interface/2007/12/launching-autoc.html), but I am still wondering if it can be done completely out of process.

So back to my original question:

How do you do a "Hello World" as a stand alone CAD app?

Thanks again.

TonyT

  • Guest
Re: "Hello World" a standalone CAD application?
« Reply #4 on: February 26, 2009, 11:23:34 AM »
I'm a little puzzled by your question, because there's not much
difference between programming AutoCAD from another process
using COM, and programming it using AutoCAD VBA. The main
differences are in how access the active document, and how you
start and close AutoCAD.

So, sorry for having to ask this, but have you done much AutoCAD
programming of any sort?

Thank you for quick responses.

MickD,
You're right. With both installed, I can easily connect to Excel and read and write cells but I can only open/close Autocad. I think I will try ObjectDBX next (http://blog.jtbworld.com/2007/09/objectdbxrealdwg-using-vbnet.html) to actually write to the drawing.

GlennR,
I am learning how and what NET can do with CAD. I am very impressed with all things it can do in-process, but was wondering how can you do same things out of process as well (even though I understand the disadvantages of doing so). I've found a great example by Kean Walmsley (http://through-the-interface.typepad.com/through_the_interface/2007/12/launching-autoc.html), but I am still wondering if it can be done completely out of process.

So back to my original question:

How do you do a "Hello World" as a stand alone CAD app?

Thanks again.

pop

  • Guest
Re: "Hello World" a standalone CAD application?
« Reply #5 on: February 26, 2009, 01:37:18 PM »
Hi Tony,

Yes, I am new to AutoCAD programming and fairly new to NET. I've done a number of rudimentary AutoCAD VBA macros connecting Excel and using spreadsheet data to draw schematics but VBA hides many of these complexities. I didn't even know that the cad drawing was a database before I looked at programming in NET:D

So far this is the only thing that I can do:

Code: [Select]
Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common

Module Program

Sub Main()
Dim acadApp As AcadApplication
Dim acadDoc As AcadDocument

acadApp = CreateObject("AutoCAD.Application.16.2")
acadDoc=acadApp.ActiveDocument
acadApp.Application.Visible=True

msgbox (acadApp.Version)

acadDoc.close
acadApp.Application.Quit
End Sub
End Module

How do I open the drawing database? A while back, I read on some cad forum several posts by Tony Tanzillo (maybe you're the same person), that managed and unmaged code cannot be mixed. I've tried anyways, using startTransaction() method and he was right. 

Can you write a snippet of how you would draw a line or insert mtext, using above code, anything to show me how you can manipulate the drawing?

Thank you


Draftek

  • Guest
Re: "Hello World" a standalone CAD application?
« Reply #6 on: February 26, 2009, 05:10:23 PM »
We could easily 'show' you but that's probably not the best thing for you.

Take a look at the object browser and you should see some properties and methods that will help.

Hint - You already have the instance of the document.
« Last Edit: February 26, 2009, 05:36:50 PM by Draftek »

pop

  • Guest
Re: "Hello World" a standalone CAD application?
« Reply #7 on: February 27, 2009, 11:16:35 AM »
Thank you for the hint Draftek!! This is exactly like VBA. Curiosity satisfied.

Code: [Select]
Dim textObj As AcadText
Dim insertionPt(2) as Double
insertionPt(0) = 0.0
insertionPt(1) = 0.0
insertionPt(2) = 0.0
textObj=acadDoc.ModelSpace.AddText("Hello World", insertionPt, 10.0)


Draftek

  • Guest
Re: "Hello World" a standalone CAD application?
« Reply #8 on: February 27, 2009, 11:48:57 AM »
Excellent! glad you found it -

But, I would also question using com Interop.
There is a reason why there's no documentation.

I'd suggest re-thinking your program architecture.

pop

  • Guest
Re: "Hello World" a standalone CAD application?
« Reply #9 on: February 27, 2009, 02:38:13 PM »
Yes, lack of CAD-COM documentation is enough to keep me away from it.

Thanks again.

TonyT

  • Guest
Re: "Hello World" a standalone CAD application?
« Reply #10 on: February 27, 2009, 05:31:00 PM »
Yes, lack of CAD-COM documentation is enough to keep me away from it.

Thanks again.

There's nothing wrong with using COM if you are not going to
distribute your applications widely. The managed API for AutoCAD
requires some background with AutoCAD and preferably some
prior experience with one of its easier-to-use APIs, otherwise
you will quickly find yourself lost, without much to guide you.

With COM, programming is much simpler and can be learned
in much less time. Usually, one advances to the managed API
when they've 'outgrown' the COM API, but until then, I would
try to use the easier of the two.