Author Topic: Create new AutoCAD drawing (C#)  (Read 11036 times)

0 Members and 1 Guest are viewing this topic.

wannabe

  • Guest
Create new AutoCAD drawing (C#)
« on: December 03, 2008, 04:10:55 PM »
Hello,

Anyone able to briefly explain the method for using C# code to create a new AutoCAD drawing?

All I want to do is to have a form with a textbox and a buton; the label.text is passed to the method that creats the drawing as the save location; the method itself will be activated by the button.

Unfortunately I cannot find the method for adding a drawing.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Create new AutoCAD drawing (C#)
« Reply #1 on: December 03, 2008, 04:34:59 PM »
Couldn't you just create a new Database, and then save it?
Tim

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

Please think about donating if this post helped you.

TonyT

  • Guest
Re: Create new AutoCAD drawing (C#)
« Reply #2 on: December 03, 2008, 06:23:05 PM »
Hello,

Anyone able to briefly explain the method for using C# code to create a new AutoCAD drawing?

All I want to do is to have a form with a textbox and a buton; the label.text is passed to the method that creats the drawing as the save location; the method itself will be activated by the button.

Unfortunately I cannot find the method for adding a drawing.

Assuming you mean "new DWG file" as opposed to a new drawing that is
open in the AutoCAD editor, then you can just create a new Database
using the parameters to build a new default drawing, and then call its
SaveAs() method, to save it to a DWG file.

But often 'new' drawing files are based on a template drawing file, and
in that case, you merely need to copy an existing DWT file, and rename
it to filename.dwg.


wannabe

  • Guest
Re: Create new AutoCAD drawing (C#)
« Reply #3 on: December 04, 2008, 01:57:36 PM »
Any chance of a code sample including references to the library?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Create new AutoCAD drawing (C#)
« Reply #4 on: December 04, 2008, 02:33:24 PM »

How about you post what you have so far and indicate where you are having trouble.
...  I'll have a look tonight .. or someone else will :)
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.

wannabe

  • Guest
Re: Create new AutoCAD drawing (C#)
« Reply #5 on: December 04, 2008, 03:51:57 PM »

How about you post what you have so far and indicate where you are having trouble.
...  I'll have a look tonight .. or someone else will :)


Thanks, Kerry.

Unfortunately all I have is a windows form application, with one form consisting of a button and a text box.

I've just read C# 2008 for dummies and have another practical exercise manual that I am working through as well.

However, I wanted to spend half an hour a day working on a CAD project, too. So I decided I would create a form that can create a drawing at the press of a button using text specified in a textbox. I then plan to add bits of code to this solution to give myself experience pertinent to AutoCAD development; my main reason for learning C#.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2132
  • class keyThumper<T>:ILazy<T>
Re: Create new AutoCAD drawing (C#)
« Reply #6 on: December 04, 2008, 04:20:38 PM »

Perhaps start here ...

AutoCAD .NET Labs
  AutoCAD 2007.Net Training.zip (zip - 788Kb)
     This file is compatible with AutoCAD 2008.
http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=1911627

and the ObjectARX for AutoCAD SDK has .NET info (including help files  managed API)
http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=785550

Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

TonyT

  • Guest
Re: Create new AutoCAD drawing (C#)
« Reply #7 on: December 05, 2008, 05:45:19 AM »

How about you post what you have so far and indicate where you are having trouble.
...  I'll have a look tonight .. or someone else will :)


Thanks, Kerry.

Unfortunately all I have is a windows form application, with one form consisting of a button and a text box.

I've just read C# 2008 for dummies and have another practical exercise manual that I am working through as well.

However, I wanted to spend half an hour a day working on a CAD project, too. So I decided I would create a form that can create a drawing at the press of a button using text specified in a textbox. I then plan to add bits of code to this solution to give myself experience pertinent to AutoCAD development; my main reason for learning C#.

If you're just starting out with C# and .NET, I would recommend focusing
on becoming reasonably proficient with those technologies first, and after
you have a few months (at minimum, but preferably at least a year) of
experience with them, then start with ObjectARX. Sorry if that sounds
discouraging, but doing managed ObjectARX programming without having
those basic prerequisites, is like trying to run before having learned to walk.

What many who've never used it before quickly discover, is that AutoCAD's
managed .NET API is not easy for an entry-level programmer to use, in the
ways that VBA and LISP are. The managed .NET API for AutoCAD requires
a reasonable degree of experience and a good understanding of the basic
tools that are used (mainly C#  or VB.NET, and the .NET Framework), and
the concepts that underly them (like for example, a good understanding of
object-oriented programming concepts).

Some seem to think that because there's a visual designer that allows
them to easily create user interfaces using drag-and-drop, that they
don't need to know too much about programming to build a program,
which is not the case.

The user interface is only one part of the puzzle and it's easiest part
thanks to the visual tools, but making the application do something is
another matter, and learning the programming language and APIs that
must be used to do that is a prerequisite to building real software.

The thing that many need to understand about programming, is that
their experience is what allows them to see what's wrong with their
code. If they can't see what's wrong with it, it's common for wishful
thinking to take over, and lead one to incorrectly assume there is
nothing wrong with their app... that is, until it crashes on the user or
corrupts their data. In one case I'm familar with, one inexperenced LISP
programmer was all that was needed to corrupt the infrustructure data
for a medium-sized US city, to the point where it had to be completely
thrown out and recreated from scratch (at a cost of 7 figures), and
ultimately resulted in half their engineering department getting pink slips.


wannabe

  • Guest
Re: Create new AutoCAD drawing (C#)
« Reply #8 on: December 05, 2008, 03:07:37 PM »
Ok. So you think I should ditch the CAD and just focus on completing my C# training manual and memorising all of the information in my C# for dummies reference book? Then come back to CAD a year later?

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: Create new AutoCAD drawing (C#)
« Reply #9 on: December 05, 2008, 05:14:57 PM »
Ok. So you think I should ditch the CAD and just focus on completing my C# ....

I don’t, you can learn both at the same time  8-)

jmaeding

  • Bull Frog
  • Posts: 304
  • I'm just here for the Shelties.
Re: Create new AutoCAD drawing (C#)
« Reply #10 on: December 05, 2008, 05:17:31 PM »
Wannabe,
You have to appreciate what Tony is saying, its constructive info.
Its is true that you cannot "date" .net.  While c++ requires entering into marriage, at least .net required going steady :)
Heck, from that analogy, all of us here are two (or three or five) timers.

Don't be discouraged, but do take some time to look into this forum and the adesk .net labs to get the hang of things.
Do not think .net can do all things better because its more powerful.  You can mix it with lisp if needed because lisp does certain things easier.

I'm not an expert at the objectarx model, but can get through it when needed with a little (sometimes a lot) of help.  You should not expect to get out a useful "original" program within the first few weeks.

Its ok to post beginner questions though, keep plugging here and you will be able to build the code little by little.
James Maeding

TonyT

  • Guest
Re: Create new AutoCAD drawing (C#)
« Reply #11 on: December 05, 2008, 10:39:56 PM »
Ok. So you think I should ditch the CAD and just focus on completing my C# training manual and memorising all of the information in my C# for dummies reference book? Then come back to CAD a year later?

Not necessarily a year. It depends on how much/fast you can learn those
prerequisites, and whether you're learning on a full- or part-time basis.

More realistically, I would start with ObjectARX, after having learned
enough of the prereq's needed to be able to look at the samples that
ship with the API and easily understand them, and how they work.

I disagree with Dan, and I think his point of view is likely due to the
fact that like most of us, he takes his own experience for granted, and
most skilled programmers find it difficult to imagine what it's like to be a
complete newbie/beginner again.

You may be able to learn ObjectARX in parallel with learning the tools,
but for most, doing that is kinda like learning to fly with a 747.

« Last Edit: December 06, 2008, 09:57:37 PM by TonyT »

Draftek

  • Guest
Re: Create new AutoCAD drawing (C#)
« Reply #12 on: December 08, 2008, 08:05:10 AM »
^ Amen to that.

I went the other route and suffered much pain along the way.