Tuesday, April 3, 2012

VB.net Programming for AutoCAD, Civil 3D, and Map 3D

Over my 15 years of using AutoCAD and other Autodesk software, I've fooled around with writing LISP routines to a very beginner type extent. I've taken classes at Autodesk University on LISP and some of the APIs of the various softwares, but it's been over my head for a lot of it. Within the last month or so, I finally decided to start learning VB.net programming. After a few weeks into it and some coaching help from a friend, I finally wrote my first command - needless to say I am hooked.

The command I wrote automates a process in Map 3D that I despised doing. The process involves labeling GIS data of soil boundaries. I typically bring these in from a SHP file, Create Object Data, and import as polylines. From here the labeling process begins with the Map Annotation commands. To initiate the annotation, the user must first define a template for the annotation, in this case a Soils Label. Within the template, Edit Annotation Text msut be inserted (typically with the "MAPANNTEXT" command). This text is a special kind of attibute text that allows for accessing the Object Data Tables and Fields. Thus the user would browse to the correct table and field to generate labels based on the selected boundary's Object Data. From here the template would be saved.

Upon completion of the template, the user would then use the Map Annotation Insert template command, call up the created template and could insert once at a picked point, or insert for entire drawing at the centroid of the object. Typically the fastest way to do this is via the centroid of the object, however, the centroid does not always occur within the soil boundary - thus you would then have to move the labels around and check properties of each boundary to ensure the label is inside the correct boundary.

My VB.net command automates this entire process, which in turn saves a lot of trivial time of moving labels around. Basically to explain the command in english, it first calls up the dialog shown below and provides some instruction. It then auto populates the Table Name based on the Object Data in the drawing, then allows for the user to type in the corresponding Field Name for the soil name. From here the user can click "Label Boundaries" in which the program checks to see if an annotation template with the name of SoilLbl has been created. If not it creates the template based on the given prompts on the dialog.

Next it prompts the user to select a boundary to label, then prompts for label insertion point and repeats the label insertion point prompt until the user hits escape. Essentially this allows the user to lable one boundary at a time, ensuring for more accurate labeling of soil boundaries, and less time involved of going through the above process. 


I would like to encourage everyone to jump into the coding!! It opens a whole new realm of AutoCAD, Civil 3D, and Map 3D.

4 comments:

  1. Hi, I'm trying to access Object Data tables in my civil 3d drawing via VB.net and am at a loss. All new to me. Can you help me out with which command/object does this? I'm searching all over and cannot seem to find anything. Thanks for your time. julabay@gmail.com

    ReplyDelete
  2. Hi, here are a few links that might help you out...

    http://adndevblog.typepad.com/infrastructure/2012/05/want-to-know-which-object-data-tables-are-in-the-current-drawing-file.html

    http://adndevblog.typepad.com/infrastructure/2012/06/removing-all-object-data-from-an-entity-using-map-3d-api.html

    http://adndevblog.typepad.com/infrastructure/2012/05/adding-object-data-records-to-entity-using-map-3d-api.html

    http://forums.autodesk.com/t5/net/vb-map-3d-reading-object-data-tables-from-dwg-in-side-database/td-p/3934361

    ReplyDelete
  3. Can you share the code you used to complete your task of labeling soils data?

    ReplyDelete
  4. Hi Brian,

    I'll see what I can do. I have started a side business now doing programming/apps. If you need assistance. Email me at steve@redtransitconsultants.com.

    ReplyDelete