Author Topic: Newbie looking for simple C# examples  (Read 8271 times)

0 Members and 1 Guest are viewing this topic.

SteveK

  • Guest
Newbie looking for simple C# examples
« on: January 19, 2010, 11:51:14 PM »
Hi,

I've just been through the C# Hello World example here http://www.cadalyst.com/cad/autocad/autocad-commands-c-cad-clinic-civil-3d-tutorial-3069.

Does anyone have any small C# examples I can learn from? An example would be searching a drawing for text that is green and changing it to blue.

And as an aside: is there an ssget equivalent in C#?

Thanks,

steve
« Last Edit: January 20, 2010, 12:21:38 AM by steve.k »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
« Last Edit: January 22, 2010, 02:51:29 AM by Kerry Brown »
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.

fixo

  • Guest
Re: Newbie looking for simple C# examples
« Reply #2 on: January 20, 2010, 04:11:59 AM »
Hi,

I've just been through the C# Hello World example here http://www.cadalyst.com/cad/autocad/autocad-commands-c-cad-clinic-civil-3d-tutorial-3069.

Does anyone have any small C# examples I can learn from? An example would be searching a drawing for text that is green and changing it to blue.

And as an aside: is there an ssget equivalent in C#?

Thanks,

steve

Here is what you asked about

Feel free to change to your suit

~'J'~

Glenn R

  • Guest
Re: Newbie looking for simple C# examples
« Reply #3 on: January 20, 2010, 11:10:51 AM »
Start off by learning the language first - forget the autocad side of it for now, as it sounds like you're at the very beginning. You'll be glad you did in the long run.

SteveK

  • Guest
Re: Newbie looking for simple C# examples
« Reply #4 on: January 20, 2010, 04:20:44 PM »
http://through-the-interface.typepad.com/
Cheers Kerry, that site (above) is quite good. Here's a couple I found I can read through.
Using pickfirst selection
http://through-the-interface.typepad.com/through_the_interface/2006/09/using_the_pickf.html
Creating an AutoCAD layer
http://through-the-interface.typepad.com/through_the_interface/2010/01/creating-an-autocad-layer-using-net.html


Here is what you asked about
Feel free to change to your suit
~'J'~
Thanks very much Fixo! I'll get back to you with questions   :-)


Start off by learning the language first - forget the autocad side of it for now, as it sounds like you're at the very beginning. You'll be glad you did in the long run.
I got plenty of holes in my knowledge, but I know the basics of C++ so I'm gonna see how far I can get with that.  :?

SteveK

  • Guest
Re: Newbie looking for simple C# examples
« Reply #5 on: January 20, 2010, 06:17:35 PM »
Fixo, I just went through your code. It actually made sense! The only thing that looks a bit foreign is the bit bracketed: "using (Transaction..."

Can I ask a few questions?...

1. Where does the object Regex come from? As in the line:
Code: [Select]
newtext = Regex.Replace(dbt.TextString, sFind, sReplace);
2. Is the
Code: [Select]
catch (Autodesk.AutoCAD.Runtime.Exception ex) the common error catcher? Ie, what if I use:
Code: [Select]
catch (...)?

3. What does
Code: [Select]
[assembly: CommandClass(typeof(SelText.TextMod))] at the top of the cs file do?

4. How does autoCAD know to run the Initialize function in InitCommand.cs? Don't we need to call it because it's in a function?

5. Out of interest, do we ever use classes apart from a single class to house our commands?

6. Lastly, I just want to make sure there's no apropos button in SharpDevelop, like there is in the Visual Lisp Editor. And the best thing to use as a quick reference is http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer%27s%20Guide/index.html?

Thanks!!  :-)

steve
« Last Edit: January 20, 2010, 06:49:41 PM by steve.k »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Newbie looking for simple C# examples
« Reply #6 on: January 20, 2010, 06:59:35 PM »
1) System.Text.RegularExpressions.Regex

2) what do you mean by ; catch (...)
You catch exceptions thrown (Please Read The Documentation )

3) not mandatory, but improves loading performances. (Please Read The Documentation )

4) public class InitCommand : Autodesk.AutoCAD.Runtime.IExtensionApplication

5) yes (Please Read The Documentation )

6) You mean Intellisence ?
   re the quick reference : did you see my first link ?

regards
Kerry

[edit]
RTFM changed to Please Read The Documentation
« Last Edit: January 22, 2010, 07:47:22 PM by Kerry Brown »
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.

SteveK

  • Guest
Re: Newbie looking for simple C# examples
« Reply #7 on: January 20, 2010, 07:42:06 PM »
Kerry, I know you know a great deal, but if you don't want to genuinely help then please don't post! Let someone else.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Newbie looking for simple C# examples
« Reply #8 on: January 20, 2010, 07:50:05 PM »
Steve

ALL of my answers are correct and relevant to your question.

The (Please Read The Documentation ) is for additional information.

If you expect me ( or anyone) to write a thesis to cover information already included in documentation you will be disappointed I think.

... oh, and you're welcome :)


RTFM changed to Please Read The Documentation
« Last Edit: January 22, 2010, 07:48:19 PM by Kerry Brown »
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.

SteveK

  • Guest
Re: Newbie looking for simple C# examples
« Reply #9 on: January 20, 2010, 08:13:27 PM »
Kerry, You expect a thanks when you were being rude? There's a difference between correct and helpful.

You know yourself you posted what you did because you've either seen these questions a hundred times or you've read them countless times in the .NET manual and you think I could have found the answer if I'd searched it or the web.

In answer I have made a search for these questions. And I just like finding out details in a forum. It's how myself and countless others have learnt lisp. Yes I've read a hundred questions that boil down to the same one asked last year, but so long as someone show's an effort to learn I quite enjoy helping them along.

Anyways, that's enough of that. Thanks Kerry, question 1 was beneficial to me.

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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Newbie looking for simple C# examples
« Reply #11 on: January 20, 2010, 08:44:53 PM »


Regarding 2)

what do you mean by :

catch (...) ?
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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Newbie looking for simple C# examples
« Reply #12 on: January 20, 2010, 08:51:22 PM »

Regarding 3)
Quote
What does
[assembly: CommandClass(typeof(SelText.TextMod))]at the top of the cs file do?
do

I answered
3) not mandatory, but improves loading performances.

http://www.autodesk.com/autocad-net-developers-guide
http://through-the-interface.typepad.com/through_the_interface/2006/09/optimizing_the_.html
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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Newbie looking for simple C# examples
« Reply #13 on: January 20, 2010, 08:52:47 PM »
Regarding 5)

yes.
I have no further comment other than :
If you don't know this I suggest you read Glenn's post
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.

SteveK

  • Guest
Re: Newbie looking for simple C# examples
« Reply #14 on: January 20, 2010, 09:33:38 PM »
Thanks Kerry.

2. Ignore this. catch (...) was an afterthought from C++. It doesn't work. My bad.
3. That link is helpful.
4. No I don't understand that, but once again those links put me on the right track I think.
5. It was more a general question I just thought an experienced C#'er could comment on. I'm sure I'll notice when I come across it, was just curious if classes are used in code that run simple autocad commands. I can't think how, and it doesn't matter.

Thanks again Kerry, and sorry I didn't mean to be a blight on your day.