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

0 Members and 1 Guest are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Newbie looking for simple C# examples
« Reply #15 on: January 20, 2010, 09:41:42 PM »

Quote
.... and sorry I didn't mean to be a blight on your day.

No worries, To quote an Irish Farmer who lived next door to us.

"I've been stuffed around by experts and you've got a long way to go to qualify boy."

"I only get upset by what I consider important, this isn't important. "


Happy learning.
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: Newbie looking for simple C# examples
« Reply #16 on: January 20, 2010, 10:42:22 PM »

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


Firstly, everything in C# is a class - 'everything', I think BOO,F#, IronPython/Ruby et al may be the exceptions where you can write simple functions to do a task without being a class method.
Yes, the commands class is what carries out your orders but any application with any sort of real purpose will be comprise of many classes. In the case of acad, a lot of them may be termed as 'helper' classes and some real world objects to hold and manipulate data. Besides that you wouldn't want 5000 lines of code for a command class I wouldn't think :)
"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

fixo

  • Guest
Re: Newbie looking for simple C# examples
« Reply #17 on: January 21, 2010, 04:58:04 AM »
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

Steve, sorry for the belating, I've been sick as always
And thanks to Kerry Brown for saveing my time because of
my poor english level I would be spend a ton of time on it :)

~'J'~

Glenn R

  • Guest
Re: Newbie looking for simple C# examples
« Reply #18 on: January 21, 2010, 05:07:02 AM »
If I remember correctly, catch(...) in C++ is a catch-all (almost like On Error Resume Next in VB - let the fight begin ;-) ) and the equivalent in C# is catch().

I seriously discourage it's use however. As all exceptions derive from System.Exception, that's your last catch clause in a multi-catch.

I do remember reading somewhere, that there's an System.ApplicationException...ah, here it is.

Glenn R

  • Guest
Re: Newbie looking for simple C# examples
« Reply #19 on: January 21, 2010, 05:12:17 AM »
It appears from that link I posted, that MS have changed their recommended exception handling strategies from when I first heard about ApplicationException.

BTW, I reiterate - get a good book and start there. Forget about doing anything in AutoCAD until you have a solid grasp of the language.

SteveK

  • Guest
Re: Newbie looking for simple C# examples
« Reply #20 on: January 21, 2010, 05:30:48 AM »
Hi Glenn, thanks for clearing that up (about catch). I'll stick with the runtime exception. I suppose some people probably wouldn't get far enough (before getting bored) to do anything worthwhile if they started with a textbook. Without doubt, their knowledge would be full of holes and they'll never get to the level of some people on this forum, but they'll be able to do some simple fun stuff, and be content.

Fixo, no worries mate, you've already helped a ton! If you have any more simple examples by all means post em! Eg Changing an attribute in a block.  :wink:

And thanks Mick, you understood my question. I like reading those type of comments, I reckan it helps.  :-)

Thanks guys, sorry to be an irritation, there just aren't too many AutoCAD C# forums around for noob questions. (I'll wait for a link Kerry)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Newbie looking for simple C# examples
« Reply #21 on: January 21, 2010, 05:52:25 AM »
Quote
Eg Changing an attribute in a block.

'cause I'm feeling a little mellow from limechicken and a couple of glasses of red ;

a piccy to ponder :)

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 #22 on: January 21, 2010, 05:53:45 AM »
< .. >  there just aren't too many AutoCAD C# forums around for noob questions.

 :angel:

I know of one.
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 #23 on: January 21, 2010, 06:07:37 AM »
a piccy to ponder :)
Yeah I pondered but I haven't had enough red wine to ponder for too long. Ok I get the point, no more unimportant noob questions!

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Newbie looking for simple C# examples
« Reply #24 on: January 21, 2010, 06:11:40 AM »

Steve
If you pull your head out of your arse for a little while you may be able to learn something here.
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 #25 on: January 21, 2010, 07:23:50 AM »
you're a real pal Kerry

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Newbie looking for simple C# examples
« Reply #26 on: January 21, 2010, 10:01:57 AM »
lol, would read again
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Maverick®

  • Seagull
  • Posts: 14778
Re: Newbie looking for simple C# examples
« Reply #27 on: January 21, 2010, 10:06:46 AM »
MP IN DA HIZZHOUSE!  :-D

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Newbie looking for simple C# examples
« Reply #28 on: January 22, 2010, 02:32:19 AM »

[ intermission ]

Long time Michael !!

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.

mohnston

  • Bull Frog
  • Posts: 305
  • CAD Programmer
Re: Newbie looking for simple C# examples
« Reply #29 on: January 22, 2010, 07:02:49 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.

This is an interesting reaction.
I think it has to do with what a person thinks "RTFM" stands for. There is certainly room for (mis)interpretation.
I've heard it used as:
Reboot The *expletive* Machine
or
Read The *expletive* Manual

Either way it seems harsh.

Or maybe it was supposed to be:
Run To First Method
Rob The Flea Market
Rate Two Fat Monkeys
Ring Twice For M . . . .
It's amazing what you can do when you don't know what you can't do.
CAD Programming Solutions