More servicesWindows Live
HomeHotmailSpacesOneCare
 
MSN
Sign in
 
 
Spaces home  Bobby C. JonesProfileFriendsBlogMore Tools Explore the Spaces community

Blog

August 11

AutoCAD Top Ten List

I've used AutoCAD for a long time and just like any long term relationship with an inanimate pile of 1's and 0's it is deep love/hate relationship.  Below is my list of the top 10 items that I love about AutoCAD.  Some of them refer to CAD in general and some are more geared towards the vertical applications and the new B.I.M. applications, but they all originated with my use of AutoCAD.

#10 - Vertical Applications
AutoCAD can be used to draw wiring diagrams, circuit boards, auto bodies, engines, buildings, foliage and just about anything else that you can imagine.  The vertical applications take AutoCAD and target it, using many of the items on this list, to specific industries.  Being in the residential housing industry we use ADT to design and create construction documents.  We also do a bit of site development and we use Civil 3D.  We are looking hard at the MEP packages as well.  I hope this trend continues expand to cover additional industries and to shrink to cover niche industries, like the residential housing industry that has very specific needs beyond the general needs of the architectural and construction industry as a whole.

#9 - Fields
Fields give us the ability to input information in one location and have it display in multiple locations.  Changing the source updates all other instances.  Fields also give us the ability to report via text the properties of graphically defined objects.

#8 - The 3rd dimension
Most designers, regardless of their field, form a mental image of their design before they put it on paper.  I'm willing to bet their mental image is not a 2d piece of paper.  The ability to take that 3D image out of your head and show it to someone else in the same format is very powerful indeed.

#7 - Multiple Undo
Design is very sloppy process.  This tool, yes it is a tool, allows a bit of freedom and fluidity to explore multiple design ideas without the need to save each and every iteration along the way.  Although I'm the first to admit that saving an occasional iteration is a great idea.

#6 - The powers of association
There's no way to overstate the power of logically associating one object to another.  Associating some lines and text into a dimension object or a hatch object to its boundary objects is something we now take for granted.  The vertical applications are taking this to the next level.  For instance, in ADT door objects are associated to wall objects and door tag objects are associated to the doors.  Move a wall and the doors move with it, and because the doors moved the tags moved too.  Change the size of the door and the tag updates to show the new size and the wall adjusts to fit the modified door.  There are 3rd party packages that take this to the next level and associate framing members to the the walls and the doors and windows in them.  I do see a bit of danger if this idea is taken so far that the software tries to outsmart the designer running it.  Or maybe I've just watched The Terminator one to many times.

#5 - Style based objects
Style based objects are the ultimate tool for those designers that have a hard time making a final decision. 

"I know that I need a window here, but should it be a rectangular window or an archtop window, or maybe I should go for broke and make it an oval."

Style based objects make it extremely easy to put in a window of one style and change it to another.  Styles have been around for a while, even in straight AutoCAD.  Text and dimension styles have been bread and butter tools for CAD Managers and power users for many years.  I can't imagine drawing without them.

#4 - Blocks
Blocks have been with us for so long that we don't even think about how important they are to us.  Close your eyes and imagine working with AutoCAD without blocks.  No grouping of primitives into meaningful symbols, no symbols libraries, no mass updating of symbols, etc...  Did it send a shiver of dread up your spine?  It does mine.

#3 - Customization
Every industry, every company within an industry, and every individual within a company has their own procedures and workflow.  The ability to customize AutoCAD to fit into that workflow is invaluable.  Our company is currently looking at a variety of initiatives and we are realizing that our workflow will need to change to accommodate them.  It is very comforting to know that I can customize AutoCAD to fit into that workflow and not the other way around.

#2 - Ubiquity
If you are drafting then you are either using AutoCAD, have used AutoCAD, have to deal with AutoCAD drawings, or at the very least have heard of AutoCAD and compared your software to it.  One of the biggest challenges that I may have to deal with as a CAD Manager if we switch to a non-AutoCAD based software is training.  Right now I can place an add for drafters in the local paper and rest assured that 95% of the applicants already know base AutoCAD and I will not need to train them at that level.

#1 - Users
And the number one thing that I like about using AutoCAD.  Yep, it's you.  I have met so many people and found that instant connection because we both work and fight with AutoCAD on a daily basis.  From local user groups, to regional and national gatherings like AUGI CAD Camps and Autodesk University, and to online communities like the Autodesk discussion groups, AUGI, and The Swamp, you can hardly swing a dead mouse around by its USB cord without hitting a fellow AutoCAD user in the head.

There's my list, how does it compare to yours?

Next we'll look at the top 10 items that I hate about AutoCAD.

 

Technorati tags:
July 11

There's Power Under There

Before I get into the CAD stuff, I need to share a little something that you may find useful.  A while back I read a book on speed reading.  And guess what, despite the "As Seen on TV!" warning on the front cover, it really works.  My casual reading speed has increased 100% without any loss of comprehension or retention.  I'm now working on actually increasing comprehension and retention while maintaining my increased speed.  One of the methods the book suggests to do that is to increase your vocabulary.
 
I thought that I had a fairly decent vocabulary, but I tried an exercize outlined in the book.  Anytime I came across a word that I didn't fully understand, I stopped reading and looked it up.  The theory is that eventually your vocabulary will increase, you'll start spending less time in the dictionary, and your reading speed will increase as your grasp of the language increases.  No kidding, on the first page that I read after starting this exercize, I found three words that I either didn't know at all, or only had a vague or partial understanding of the meaning.  The words were pique, balefully, and diatribe.  And let me tell you, after looking up these words and fully grasping their meaning, that part of the story took on a whole new dimension.  I fully encourage you to give this experiment a try, even if you believe that your vocabulary is already Brobdingnagian.
 
Just like a large vocabulary is a key to success with language, knowledge of system variables is a key to success with AutoCAD.  One of my old AutoLISP books had a huge section in the back that listed all of the AutoCAD system variables.  It was instrumental in my early success with AutoCAD.  I still try to keep up with all of the new ones, but I do miss a few.  Here's one that a co-worker taught me about today:
 
PUBLISHALLSHEETS
 
It controls whether or not the PUBLISH command brings in the layout tabs from just the current drawing or from all open drawings.  That one created some monster plot jobs before we figured out what was going on!
 
If you're not familiar with system variables, start exploring, you'll like what you find.  If you think that you're well versed in them, give them another look.  I promise that you'll rediscover variables that you forgot about and you may even find one or two that you never knew existed.
July 10

Before it's too late

Last week on the Autodesk discussion groups I read of the passing of Don Reichle.  I didn't know Don.  I had never interacted with him in the groups.  But I could see from the replies to the news of his passing that he was very well respected and liked.  Lots of people had lots of good things to say about him.  It struck me as sad that he may not have known the impact that he had on the people he knew and the people he didn't.  All those words of kindness were a little too late for Don.
 
I started thinking of the people that I've met online that have had an impact on my career and my life.  While there are many, I could fill pages with their names, 3 come to the top.
 
  • Frank Oquendo
  • R. Robert Bell, or just Bob if you know him.
  • Michael Puckett

So while you're still around to hear it, thank you!  You've been teachers, mentors, and most importantly friends.

July 07

A Blog in the Oven

Owning a Blog is much harder than I originally thought.  It sounds simple enough; throw your thoughts into the machine, mix in a few screen shots, stir, and viola, a Blog is born.  Truth be told, I am very happy with my Blog.  And why shouldn't I be?  I made it exactly the way that I wanted it.  The problem with authoring a Blog is the same problem that Chefs face; who's going to eat it? 

I like brownies.  My motto is that if I'm going to add inches to my waistline, there will be chocolate involved.  In particular I like my brownies extra gooey.  I've found that taking them out of the oven 5 minutes early will achieve gooey perfection.  No one else in my family, immediate or extended, likes them gooey.  They prefer them more cake like.  (I know, it doesn't make sense to me either.)  Just remember, of all my family I only choose one, and I can forgive her the sin of liking cakey brownies.  So when I make brownies for me, they are dense and gooey.  When we take them to a family gathering, they are light and cakey.

How do you like your Blogs, dense and gooey or light and cakey?  My guess is that most readers prefer light and cakey.  As the chef of this Blog, however, I sometimes like to cook and serve up something dense and gooey.  Have you read my very first post?

Most of my posts have been very light and cakey, mostly dealing with work and professional topics.  But that's not me, at least not all of me.  And if I try to stay completely within the light and cakey realm, I'll get bored and stop posting.  (This is my first post since early March for crying out loud!)  I promise that I'll keep the dense and gooey posts to a minimum, with the deepest left inside my journal, but realistically, if I'm going to keep this Blog active it's going to have some deep gooey places.

So until next time, adios!  Will the next time be dense or cakey?  I don't know, but rest assured, there will be a next time.

March 04

Hanging Pictures With Shoes

I am by no stretch of the word old; unless of course you ask my children who may have a different opinion.  But I will admit that I have lost a step or two to old man time.  In years past I could read something once and it was committed to short term memory; committed at least long enough to pass the quiz the next day.  Now however, I find that I must read and re-read certain things in order to understand and memorize them.  I'm hoping that this is just the result of picking up poor reading and memory habits.  So I bought a book on speed reading and reading comprehension.

I'm still in the early chapters, but it has given me a couple of tools that will help me break my bad reading habits.  After explaining these tools, and while giving some encouragement on using them, the author said something that sounded awfully familiar.

You'll always reach for the old familiar ones until you become used to the new ones.  Then you'll pick the best tool for the job.

I have seen, and repeated, this exact same advise, in varying contexts, countless times.  It is just a fact of life so ingrained into my everyday living that I don't really think about it anymore.  But I constantly see this principle being fought, at home and at work.

We don't need this new BIM software.  It's expensive, it's hard to learn, it's different than what we're using now.

I don't need to learn VBA or .NET.  LISP does everything that I need.

We can't use offshore drafting services.  We have a hard enough time training staff here on site.

I'm not saying that the reasons given in any of these scenarios aren't valid.  But the person giving these excuses likely doesn't have enough, if any, experience with the alternate tools to make an educated decision on which is best for which job.  They know their one tool, they know how to manipulate it to do any job, and they'll use it even if they have to jump through incredible hoops to do so.  I know, because I have been the acrobat contorting my body and jumping through flaming hoops suspended hundreds of feet in the air to get from point A to point B.  If I had taken the time to learn a new tool I could have simply walked the short straight distance between A & B.  And the next time a similar problem arose I would have been empowered with the ability to choose between two tools to get the job done.

So the next time your spouse picks up a nail and a strappy little Manolo Blahnik to hang that shot of Rusty catching his first Frisbee, gently remove the $500 shoe from their eager little hands and give them a $3 hammer.

 

Technorati tags:
February 21

Qualities of a Good CAD Test

In my career I have been asked to take surprisingly few CAD tests.  There is only one that I can remember.  The engineer interviewing me asked what was the best method to fill an irregular shaped area in AutoCAD.  He was looking for hatch, I told him hatch, and I passed the test with a 100, A+.  To this day I don't understand how he found that useful.  But that was his litmus test and he was happy with it.  Even though I never had a serious CAD test in my career, now, as a CAD manager, I find them an invaluable tool.

A good CAD test will tell me a lot about a potential employee.  An interview tells you a lot about a person that a CAD test won't, but a CAD test is where the rubber meets the road.  There is no lying about your experience or misrepresenting yourself on a CAD test.  The question is, "What makes a good CAD test?"

 

  • A good CAD test tests for specific industry knowledge or a specific skill set.  I'm adding a section to our test that asks the interviewee to label a wall section.  I know many drafters that can lay down lines all day long representing walls, but ask them how to build a wall and you'll get the blank stare of a deer caught in your headlights.
  • It lets me evaluate what level of CAD training someone has had, or how much they need, or even how much they can give.  You'll know right away if you can train them on your standards and give them a project to run with the next day, or if you're going to need to put them with a mentor for a while.
  • It will evaluate drafting skills.  Our test provides a plan view and a front elevation of a house.  They are asked to extrapolate the side and rear elevations.  I've seen more than a few great resumes paired with a great looking portfolio, but they choked on something as fundamental is this basic drafting skill.
  • It will evaluate problem solving skills.  Our front elevation has a slight error that should be caught when creating the side elevations.  This is an item that I don't deduct a great amount for if it's missed, but I do add to their score if it's caught and corrected.
  • It will evaluate CAD skills; it is a CAD test after all.  I give a hands on test, not a question and answer type test.  The hands on test shows me if they are using layers, blocks, object snaps, and other basic CAD skills.
  • It will also give an idea of how well a person performs under pressure.  An interview is a stressful time.  A CAD test during an interview adds a little more stress.  Make your tests timed, just to tighten the screws a little bit more.  It's nice to know up front how well someone will respond when it's time to buckle down and meet the much too fast approaching deadline when half the office is decimated with the gastrointestinal infection that the boss brought back from his summer vacation to the islands.  Just don't go too far with this idea; you don't want to scare them off before the interview is over.

From the view of a potential employee there may be some mixed feelings about taking a CAD test.  Most people will feel some level of anxiety.  That is normal and is to be expected.  There are a few that see a test as a way to show off their skills.  I start grading a test, looking for these qualities, while explaining the rules to the interviewee.  I don't deduct for those that are nervous, but I do add points for those whose fingers are itching to prove their mettle.  I've heard of some interviewees taking offense when asked to take a CAD test, and actually refusing to take it.  I've never interviewed anyone that has expressed any offense, but if someone did refuse, I simply wouldn't hire them.

So test away, remove the chaffe from the wheat.  And if you're not up to developing a test of your own, just ask them if they know how to use the hatch command.

 

Technorati tags:
February 16

Where's my alter ego?

This past weekend I finally bit the bullet and created an account on Second Life, known as SL to the veterans.  Before joining I couldn't help but imagine SL as a real life, known as RL to the SL veterans, Lord of the Flies, full of anonymous people running around unchecked and behaving badly while hiding behind specious 3D avatars.  Within minutes I discovered just how easy it would be to do so.

Upon entering SL the first task is to learn the basics.  A couple of tutorials walk you through moving around, interacting with objects, and setting your appearance.  It's not easy to create an accurate representation of your real self.  It's much easier to simply drag and drop your way into a look that you'd have trouble achieving in RL with 8 hours a day in the gym with Arnold Schwarzenegger's personal trainer.  You can even give yourself a sex change.  Click...Drag.  Look ma, I'm wearing your shoes.

So I set out with bulging muscles barely contained beneath my skin tight wife beater in search of other Second Lifer's interested in some intellectual chatting.  I found some.  My first encounter went something like this.

Me:  Hi.
Random Guy:  Hey, can I hug you?
Me:  Um...You're kinda scaring me.
Random Girl:  Why, because he's black?  What a $%@#& bigot.

Random Guy and Random Girl run off unchecked to behave badly in some other cyber location.

Fortunately I'm a veteran of newsgroups and other public forums and wasn't discouraged by the high level of intellect of this exchange.  I pressed on and noticed a lone figure on the horizon.  I flew closer for a better look.  I believe that learning to fly is the final tutorial before you're released into the SL wilderness.

As I flew closer, banking hard to the right in what I thought to be a terrific fly by, the figure formed into a woman with jet black hair cut into a severe short crop that reminded me of an 80's hairdo right out of an MTV video.  To complete the look she was wearing black pants, a black shirt with shredded sleeves, no shoes, and a green and red stripped necktie.  However, what really caught my attention was her green skin mottled with dark spots.  Obviously she was just a little lost, like me, and was off in this remote corner looking for someone with whom to share her deep cerebral thoughts.  I guessed that she had mistakenly eaten some bad SL mushrooms to end up in her current state.

I introduced myself, and immediately apologized for my lack of clothing.  I had been trying on bathing suites by the pool and Click...Drag removed them.  I couldn't remember what to Click...Drag to put them back on.  Look ma, I've been swimming in the cold end of the pool.

She was definitely an intellect.  I missed half of our conversation while I thumbed through my dictionary looking up several words that I didn't recognize from her first sentence.  She typed like the wind and her end of the conversation grew off the screen.  My three and four letter interjections didn't slow her a bit.  They may have even spurred her on.  Of course I missed all of that part of the conversation because I was engrossed in reading her bio.  It turns out that she was a member of a number of lesbian groups and more than a couple of other sexually oriented organizations that I never knew existed.  I imagine that if I really had been the single 21 year old multi-millionaire that my bio claimed I would have been thinking that I had struck gold.  I returned to the conversation.

Her:  So what do you think?
Me:  I'm sorry.  What?
Her:  Well, do you want to or not?
Me:  Um...I don't know.  Hey, can I ask you a question?  Were those your mom's shoes that you lost?

I may try again this weekend.  It'll just depend on whether or not I feel like myself.

 

Technorati tags:
February 04

CAD Manager Mistake #2

Don't know everything.

In CAD Manager Mistake #1, I talked about how dangerous it is to be too valuable to your CAD users and how they are more than willing to let you do their work for them if you are willing to do it.  Along those same lines, they will let you do all of their thinking if you are willing to do so.

As a CAD manager you know more about CAD software, construction methods, and drafting techniques than any of your users.  With all that knowledge you can insert yourself as the top knowledge bank in the office.  You can use this as a tool to climb your way into promotions and raises.  Everyone will look up to you, the king of the mountain.  And just like the game you played as a kid, someone will always be looking for a weakness, a way to knock you down so they can have their turn at the top.  As exciting as that sounds, there is a better way.

Don't hoard your knowledge in a vain attempt to be strong.  Instead, work hard to share it.  Be a teacher and a mentor to your users every chance that you get.  Focus your energies on the CAD managers and power users reporting to you.  They will become your support network.  Empower them to teach and mentor the CAD users below them, just as you do for them.  This spreading of knowledge doesn't lesson you, it strengthens you exponentially with each leg that is added to your support network.  Instead of fighting your way to the top, stepping on all in your path, you will be pushed to the top, carried on the shoulders of those that you've helped.

 

Technorati tags: ,

Visual Studio 2005 Code Snippets for the AutoCAD .NET API - Part 2

Now that you've decided that Code Snippets are greatest thing since dual core processors, you've learned the basics of creating and managing them, and you've learned of some of their more advanced features, let's look at a few snippets specific to AutoCAD.  One word of warning, all of these examples are for C#.  I'll see if I can get VB versions coded up and posted; or even better, I'll be more than happy to post your VB translations of them!

 One of my most used snippets is one for starting a Transaction.  It is an Expansion and a SurroundsWith snippet.

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>Start a Transaction</Title>
      <Author>Bobby C. Jones</Author>
      <Description>Inserts a "using(Transaction...)" code block.</Description>
      <Shortcut>tr</Shortcut>
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
        <SnippetType>SurroundsWith</SnippetType>
      </SnippetTypes>
      <Keywords>
        <Keyword>Autocad</Keyword>
      </Keywords>
    </Header>
    <Snippet>
      <Declarations>
        <Literal>
          <ID>database</ID>
          <ToolTip>Replace with the database that owns the transaction.</ToolTip>
          <Default>HostApplicationServices.WorkingDatabase</Default>
        </Literal>
      </Declarations>
      <Code Language="CSharp">
        <![CDATA[
using(Transaction trans = $database$.TransactionManager.StartTransaction())
        {
          $selected$
          $end$
          trans.Commit();
        }]]>
      </Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>

  Another common snippet is one that opens a Database object.

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>Open DBObject</Title>
      <Author>Bobby C. Jones</Author>
      <Description>Opens a DBObject using an existing Transaction.</Description>
      <Shortcut>open</Shortcut>
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
      </SnippetTypes>
      <Keywords>
        <Keyword>Autocad</Keyword>
      </Keywords>
    </Header>
    <Snippet>
      <Declarations>
        <Literal>
          <ID>Type</ID>
          <ToolTip>Replace with the type of the object to open.</ToolTip>
          <Function>SimpleTypeName(Autodesk.AutoCAD.DatabaseServices.DBObject)</Function>
        </Literal>
        <Literal>
          <ID>ObjVarName</ID>
          <ToolTip>Replace with the objects variable name.</ToolTip>
          <Default>dbObject</Default>
        </Literal>
        <Literal>
          <ID>TransVarName</ID>
          <ToolTip>Replace with the name of your Transaction variable.</ToolTip>
          <Default>trans</Default>
        </Literal>
        <Literal>
          <ID>ObjectIdToOpen</ID>
          <ToolTip>Replace with the ObjectId to open.</ToolTip>
          <Default>objectID</Default>
        </Literal>
        <Literal>
          <ID>OpenMode</ID>
          <ToolTip>OpenMode for opening the DBObject</ToolTip>
          <Function>SimpleTypeName(Autodesk.AutoCAD.DatabaseServices.OpenMode)</Function>
        </Literal>
      </Declarations>
      <Code Language="CSharp">
        <![CDATA[
        $Type$ $ObjVarName$ = ($Type$)$TransVarName$.GetObject($ObjectIdToOpen$, $OpenMode$);
        $end$]]>
      </Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>

Here's a snippet to insert code that asks the user to select an entity, Editor.GetEntity().  I like this one, and snippets that insert the other GetXXX calls, because there can be a lot of setup code for the call and a lot of code to check the return values.  It's easy code, but involves a lot of typing, unless you use a snippet to insert it of course.

 

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>Get Entity</Title>
      <Author>Bobby C. Jones</Author>
      <Description>Allows the user to select a single entity.</Description>
      <Shortcut>GetEnt</Shortcut>
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
      </SnippetTypes>
      <Keywords>
        <Keyword>Autocad</Keyword>
      </Keywords>
    </Header>
    <Snippet>
      <Declarations>
        <Literal Editable="false">
          <ID>PromptEntityOptions</ID>
          <Function>SimpleTypeName(Autodesk.AutoCAD.EditorInput.PromptEntityOptions)</Function>
        </Literal>
        <Literal Editable="false">
          <ID>PromptEntityResult</ID>
          <Function>SimpleTypeName(Autodesk.AutoCAD.EditorInput.PromptEntityResult)</Function>
        </Literal>
        <Literal Editable="false">
          <ID>PromptStatus</ID>
          <Function>SimpleTypeName(Autodesk.AutoCAD.EditorInput.PromptStatus)</Function>
        </Literal>
        <Literal>
          <ID>Prompt</ID>
          <ToolTip>Prompt to display to the user.</ToolTip>
          <Default>Select an entity</Default>
        </Literal>
        <Literal>
          <ID>editor</ID>
          <ToolTip>The current Editor object.</ToolTip>
          <Default>Application.DocumentManager.MdiActiveDocument.Editor</Default>
        </Literal>
      </Declarations>
      <Code Language="CSharp">
        <![CDATA[
          //Create a new entity selection options object
          $PromptEntityOptions$ entitySelectionOpts = new $PromptEntityOptions$("\n$Prompt$: ");
          $end$
          //Start the selection process
          $PromptEntityResult$ entitySelectionResult = $editor$.GetEntity(entitySelectionOpts);
          //Exit if an entity is not selected
          if (entitySelectionResult.Status != $PromptStatus$.OK)
          {
            return;
          }
          ]]>
      </Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>

While these examples show inserting small peices of code, there's nothing wrong with snippets that insert entire procedures, or groups of procedures, or even entire class skeletons.

 

February 02

Visual Studio 2005 Code Snippets for the AutoCAD .NET API

In a previous article I discussed how to use Visual Studio Code Snippets to reduce the amount of typing, the number of typos, and coding errors resulting from those typos.  In this follow up article I'm going to show you where to find basic information on creating your own snippets, discuss when to use them instead of creating utility libraries, and talk about some of the more advanced features.  I'll follow up this article with some example snippets specific to accessing the AutoCAD .NET API.

The Basics

There is a lot of information on the net on creating and managing snippets.  I'm not going to rehash the basics here, but I will hit some highlights before passing you off to other sites that will get you up and running with creating basic code snippets and how to manage them.

  • VS Code Snippets are simple XML files with a .snippet file extension.
  • The schema is simple and the files are easily editable.
  • The Visual Studio Code Snippets Manager is used to import and manage snippets.
  • Snippets can be created for C#, VB, J#, and XML, but they are language specific and one snippet will not work for multiple languages.
  • VB snippets can set references to other assemblies and Import namespaces, C# snippets cannot.

The sites listed below will get you up to speed on all of those basics and more.

The problem with most of these sites is that they cover the basics, and they cover them well, but then they stop.  The MSDN sites contain information beyond the basics, but it's not always easy to find.  In the remainder of this article I will move beyond the basics and answer some burning snippet questions.

Snippets vs. Utility Classes

When I first started creating snippets I found that they did speed up the coding process.  It didn't take long, however, before I asked myself when should I create a code snippet versus when should I create little helper utility classes.  I actually flailed around a bit on this one before deciding that for most of what I was doing, gluing together bits and pieces of the AutoCAD .NET API, code snippets were the better choice.  Here's some guidance, the only thing that I could find other than what I found from my own experiences, from the MSDN site:

While a component API is normally used to accomplish one particular, highly specialized task and may consist of hundreds or thousands lines of code, code snippets have more of a ‘connect the dots’ characterization and should be used for simple tasks. You could use a code snippet to demonstrate how to use several apis in conjunction to accomplish a particular goal, e.g. reading the contents of a text file. Inserting a code snippet into code can have an educative purpose for the user, since she actually sees the code that implements a particular functionality. Code snippets also allow for a higher degree of customization because of the replacement fields.

As programmers we're lazy and we want to use tools to decrease the amount of actual typing required to write our code.  There will be times when a reusable utility class, or component, is a good choice, but put some thought into the problem first and see if creating a custom code snippet isn't the better option.

Functions in Snippets

Snippets for C# support Functions that run when the snippet is inserted and modify what the snippet inserts.  There are three built in functions: GenerateSwitchCases(), ClassName(), and SimpleTypeName().  Of these three I use the SimpleTypeName() often in my custom snippets.  This function reduces the call to the supplied Type to as short as possible.  Here is an excerpt from a snippet that uses the SimpleTypeName() function.

<Literal Editable="false">
  <ID>PromptEntityOptions</ID>
  <Function>SimpleTypeName(Autodesk.AutoCAD.EditorInput.PromptEntityOptions)</Function>
</Literal>

First note the attribute, Editable, is set to false.  If this attribute is omitted it defaults to true.  A Literal with Editable set to false defines a replacement element that the user doesn't fill out.  Instead you can use the SimpleTypeName Function to fill out the replacement element.

In the above example all occurrences of $PromptEntityOptions$ in the snippet will be replaced with the fully qualified name, Autodesk.AutoCAD.EditorInput.PromptEntityOptions.  That is unless a using statement is at the top of the class:

using Autodesk.AutoCAD.EditorInput;

When this using statement exists the SimpleTypeName() function shortens the fully qualified name to, PromptEntityOptions.  I do not have any examples of custom snippets using any of the other Functions, but you can read all about them on MSDN.

Functions are unfortunately only supported in C# and J#, VB snippets do not support them.

Snippet Types

There are three types of snippets, Expansion, SurroundsWith, and Refactoring.  A custom code snippet can be assigned as Expansion or SurroundsWith, or both.  Custom snippets cannot be assigned as a Refactoring snippet.

An Expansion snippet simply expands the code defined in the snippet at the current cursor location.  A SurroundsWith snippet will be placed around any lines of code that are selected.  This snippet excerpt shows a snippet that is both an Expansion and a SurroundsWith snippet.  I'll provide the full snippet in my follow up article.

    <Header>
      <Title>Start a Transaction</Title>
      <Author>Bobby C. Jones</Author>
      <Description>Inserts a "using(Transaction...)" code block.</Description>
      <Shortcut>tr</Shortcut>
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
        <SnippetType>SurroundsWith</SnippetType>
      </SnippetTypes>

To use this snippet as an Expansion snippet, type the shortcut, tr, and hit the Tab key twice.  The code expands at the cursor location.

To use it as a SurroundsWith snippet, select some existing lines of code, right click to pull up the context menu, and select the Surround With... option.  Navigate to the desired snippet and select it.  The snippet code will surround the code that was highlighted.

In order for this to work the snippet code must contain a marker that designates where the existing highlighted lines of code will be placed inside the code created by the snippet.  This marker is the $selected$ marker.  It's surrounded by the $ character just like the normal replacement markers described in the basic sites above.  In the excerpt below, which comes from the same snippet as the excerpt above, the existing selected lines of code will be placed inside the using statement created by the snippet.

<Code Language="CSharp">
  <![CDATA[
using(Transaction $TransactionVariableName$ = $database$.TransactionManager.StartTransaction())
  {
    $selected$
    $end$
    $TransactionVariableName$.Commit();
  }]]>
</Code>

This snippet also shows another special marker, the $end$ marker.  This marker will determine the placement of the cursor after the snippet code is inserted into the editor.  An $end$ marker can be placed in Expansion snippets as well.

I'm following this article up with a few of my favorite snippets.  Enjoy and be sure and let me know what interesting snippets you come up with!

January 26

Whatever happened to sex, drugs, and rock & roll?

For Christmas my wife gave me a Zune, the new MP3 player by Microsoft.  I immediately ran to the basement and excavated my box of CD's, and a few cassette tapes, from beneath a mound of dust that had built up undisturbed over I forget just how many years.  After ripping my antique collection to my hard drive I decided that my music library needed some new life.  I hit the Zune Marketplace for some fresh new rock & roll.
 
My first purchase was a track from KoRn, Coming Undone.  It's a superb hard driving guitar riff wrapping a really depressing message.  Here's the chorus and a link to the full song.
Wait
I'm coming undone
Irate
I'm coming undone
Too late
I'm coming undone
One looks so strong
So delicate
Wait
I'm starting to suffocate
And soon I anticipate
I'm coming undone
One looks so strong
So delicate
 
My next purchase was a track, Broken Glass, from Buckcherry, a great sounding band that would have done well competing with the 80's big hair bands.  Here's the chorus: 
Sickened, broken, blood shed, murder you're children
Torture, treason, never falling out of war
Standing on a broken glass!
 
Read them all, if you can stand it.  It's no wonder there's a huge shortage of counselors for teens.
 
Whatever happened to the good wholesome days when rock & roll was all about sex and drugs?  Who can forget Whitesnake and their testosterone pumping Slide It In? 
I'm gonna slide it in
Right to the top,
Slide it in,
I ain't never gonna stop
Slide it in,
Right to the top,
I'm gonna slide it in, slide it in,
Slide it, in baby...
 
Or Guns N' Roses with their mind altering Mr. Brownstone: 
I used to do a little but a little wouldn't do
So the little got more and more
I just keep tryin' ta get a little better
Said a little better than before
I used ta do a little but a little wouldn't do
So the little got more and more
I just keep tryin' ta get a little better
Said a little better than before

Stuck it in the needle and I shot it in the middle
And it, it drove outta my mind
I should've known better, said I wish I never met her Said I,
I leave it all behind Yowsa!
 
Don't you just miss the good ol' days when rock lyrics were uplifting?  I sure do.  Fortunately I did find one new song that was overflowing with good old time values by a group called Nickelback, Animals.  This is my favorite part: 
We were parked out by the tracks
We're sitting in the back
And we just started getting busy
When she whispered "what was that?"
The wind, I think 'cause no one else knows where we are
And that was when she started screamin'
"That's my dad outside the car!"
Oh please, the keys, they're not in the ignition
Must have wound up on the floor while
we were switching our positions
I guess they knew that she was missing
As I tried to tell her dad it was her mouth that I was kissing

Now that I've got my tunes all lined out, I'm working hard on the second article on Visual Studio Code Snippets.  I should finish it before the weekend is over.
 
 
Technorati tags:
January 23

Technology Mishmash

I don't know about you, but I tend to keep an eye on a lot of tech projects that don't currently affect me, but have the potential to do so, directly or indirectly, sometime in the future.

One of them is the Mono Project.  This open source project is an effort to create a runtime that allows .NET code to run in OS's other than Windows, such as Linux, Unix, and even Mac OS X.  I've yet to try Mono and .NET on these OS's, but it's good to know that the technology I'm learning and using now, .NET on Windows, has the potential to make me a bit more multidimensional sometime in the future.

Another interesting project that I've yet to try is Second Life.  Second Life is a 3D virtual world where you can interact with other people from around the real world.  This intrigues me on a personal level as a computer gamer and as someone interested in mingling with a variety of people with different backgrounds, ideas, and cultures.  On a professional level I'm intrigued by the thought of how this technology can be used to help architects and designers interact with their customers, again sometime in the future.  Although at this past AU, Autodesk showcased a customer using it now.

Looking at these technologies separately, I never would have imagined them coming together.  However, here is an interesting article on how the developers of Second Life have contributed to fixing memory leaks in Mono.  This came about because the Second Life developers have been considering using Mono as their scripting engine runtime.  I'm fascinated that these two completely unrelated technologies, at least unrelated to my unimaginative mind, have come together.

It is essential to our careers as CAD Managers to keep looking for these new technologies and new ways of combining existing technologies in order to keep ahead of the globalization curve.  If you've observed an interesting technology mishmash, please shoot me a note and let me know about it!

 

Technorati tags: , , ,

January 18

Autodesk University 2006

I realize that it's rather late to post something on AU 2006, but I just received an email that reminded me of the experience, the good and the bad.

Let's start with the bad.  This year I registered late and got a room at The Flamingo.  Let me tell you, it's a real piece of Las Vegas history.  They didn't have any rooms on the higher floors, which in retrospect was OK since I wasn't about to shell out an extra $40.00 a night for a room overlooking the strip anyway.  The room itself was very comfortable and, thanks to the paper thin walls, I got know my neighbors intimately. 

On the one side was a cowboy and his cowgirl in town for the