Tuesday, August 18, 2009

Autopopulating Custom Fields via VBA

I know that VBA didn't ship with AutoCAD 2010, but it did with Civil 3D 2010. And since old habits are hard to break, I continue to use it.

As I have stated before, building the perfect template may involve customization outside the DWT file. Sometimes the perfect template contains custom project fields. Wouldn't it be nice to be able to autopopulate these fields in other drawings?

Configure a userform and associate text box to a field:

Private Sub ProjectFields()
Dim oProjectKey As String
Dim oProjectValue As String
oProjectKey = "Project" 'name of custom field
ThisDrawing.SummaryInfo.SetCustomByKey oProjectKey, oProject
End Sub

When you hit the OK button, not only does the value get assigned to a field, but it gets written out to an XML file:

Private Sub ExportXML()
Dim strFileName As String
Dim FSO
Dim oXML
Dim oProjectKey As String
Dim oProjectValue As String
oProjectKey = "Project" 'name of custom field
ThisDrawing.SummaryInfo.GetCustomByKey oProjectKey, oProjectValue
strFileName = ActiveDocument.Path + "\" + "Project.xml" 'writes file in active DWG directory
Set FSO = CreateObject("Scripting.FileSystemObject")
Set oXML = FSO.CreateTextFile(strFileName, True)
oXML.WriteLine ("")
oXML.WriteLine ("")
oXML.Write ("")
oXML.Write (oProjectValue)
oXML.Write ("")
oXML.WriteLine
oXML.WriteLine ("")
oXML.Close
End Sub

Now when the userform initializes, it would be nice if the text boxes were autopopulated with values from the XML if set previously in another drawing (this required loading up the Microsoft XML, v6 reference):

Dim fSuccess As Boolean
Dim FSO
Dim oXML As MSXML2.DOMDocument
Dim oRoot As MSXML2.IXMLDOMNode
Dim oChild As MSXML2.IXMLDOMNode
Dim oChildren As MSXML2.IXMLDOMNodeList
Dim oProjectKey As String
Dim oProjectValue As String
oProjectKey = "Project"
Set oXML = New MSXML2.DOMDocument
oXML.async = False
oXML.validateOnParse = False
fSuccess = oXML.Load(ActiveDocument.Path + "\Project.xml")
If Not fSuccess Then
GoTo ExitHere
End If
Set oXML = New MSXML2.DOMDocument
oXML.async = False
oXML.validateOnParse = False
fSuccess = oXML.Load(ActiveDocument.Path + "\Project.xml")
If Not fSuccess Then
GoTo ExitHere
End If
Set oRoot = oXML.documentElement
Set oChildren = oRoot.childNodes
For Each oChild In oChildren
If oChild.nodeName = "ProjectValue" Then
oProjectValue = oChild.nodeTypedValue
End If
Next oChild
ThisDrawing.SummaryInfo.SetCustomByKey oProjectKey, oProjectValue
ThisDrawing.SummaryInfo.GetCustomByKey oProjectKey, oProjectValue
MainDialog.Project.Text = (oProjectValue) 'puts value in pertaining textbox in userform
ExitHere:
End Sub

All of this code is available in various places on the web. Just thought I would bring it together in one place.

Sunday, May 3, 2009

Non Style-based Civil 3D Customization

Outside styles and label styles, additional customization can be provided:

Pipe and Structure Libraries

Pipes and structures are three dimensional parametric parts. Not only must they be drawn, but values, extrusions, planes, and constraints must be configured as well. Creating a custom structure is not easy. If it were, then everyone would be making them and we would all be happy with our parts. There is a little bit of information available on various websites and blogs that can help with getting started. There are no books or classes on it unless you catch a quick one at AU. www.autodesk.com/au has some archived information that can be downloaded.

Custom Assembly Sets

Typical sections can be created and saved as blocks in the template or another DWG file. These blocks can be configured to be inserted and exploded via tool palettes. An advantage to setting up typical sections ahead of time in this manner is that code sets can be modified based on the subassemblies used in these sections. Also, pay items can be configured in these code sets for use with QTO.

In 2010, we can define an "assembly set" for use with the new intersection tool. An assembly set actually comes from an XML file definition that declares what assembly is to be used in full section, left half section, right half section, and on the curb return for primary and secondary roads. The XML file also stores the path and filename where the assemblies reside.

Plan Production Template(s)

The plan production template or sheet settings template contains layout configurations for plan, profile or plan & profile sheets. The sheets are arranged along an alignment and match lines are inserted where needed. You would configure your layout with viewport types and scales, border, north arrow, legend, typical notes... anything particular you would want to see on each of the sheets produced.

There has always been a debate about how the plan production template customization should be served:
  • Layouts in Civil 3D Styles Template - This option was preferred when plan production tools was initially released in 2007. The styles had to exist in the main template file so that they would exist in the newly created files. But this became unnecessary with the release of a service pack. Now, when sheet files are created, Civil 3D brings in the necessary styles.
  • Layouts in One Sheet Settings Template - This option would involve one plan production template. This template contains all layout situations: border, scaled viewports, viewport arrangements, etc.
  • Layouts in Multiple Sheet Settings Templates - When Civil 3D is creating sheets with this tool, each sheet file will contain all layout tabs from the sheet settings template. This is not ideal since this potentially could create a lot of useless layouts in one drawing. So a way to avoid the mess is to create one sheet settings template per configured layout.

Sheet Set Template(s) and Data Files

To fully implement sheet set manager, a custom sheet set data (DST) file should be set up. This file contains custom field values, block callout designations, and reference to a sheet set creation template with a configured layout tab and plot setup. The sheet set creation template does not require a configured viewport.

Project Template(s)

The easiest part of Civil 3D configuration is creating a project template which is simply a named folder containing subfolders that represent standard directory structure in your Civil 3D project. Project templates are selected when creating a data shortcuts folder or when creating a Vault project.

QTO Customization

Civil 3D 2010 comes with a feature called QTO that enables you to extract pay items from your design. Pay items can be configured to code sets (corridors pavement quantities) and part lists (pipe network quantities).Pay item information can be configured in a block definition. Pay item information can manually assigned to a block, Civil 3D point, linework, and hatch patterns.

Civil 3D 2010 comes with some pay items files and categorization files already customized. However, they are not complete. Civil 3D can extract quantities for area (pavement and sod), linear measurement (pipes and curb), and individually counted items (trees and lightpoles).

Hopefully, this has got your wheels turning a bit with regard to completing your Civil 3D customization.

Wednesday, April 8, 2009

Civil 3D Jewels

A brief discussion concerning marker styles...

Marker styles are Civil 3D jewels that can used for emphasis in other display styles.

  • Alignments can possess markers. Various marker styles can be assigned at different types of horizontal geometry intersections and other points of interest on alignments. Profiles can possess markers. Various marker styles can be assigned at different types of vertical geometry as well as vertical points of interest on alignments. Both alignments and profiles have a Markers tab that can be used to configure styles to these locations.
    Marker styles are assigned to codes sets to delineate the locations of intersecting links which can be very important when constructing an assembly.
  • Marker styles can be configured to feature line styles for projection into views.
  • Survey network styles use marker styles to delineate types of points observed in the field.
  • Survey figure styles use marker styles to illustrate various points of interest along an observed linear feature.
  • Marker styles can be configured to interference styles to mark where pipes are in conflict.
  • Marker styles can be assigned to certain types of labels that are not a part of a label set.
  • Marker styles can be selected at time of label creation.
Marker styles can be configured as you would AutoCAD points using the DDPTYPE command. Alternately, marker styles can use blocks. Either method allows you to scale the marker to a plotted height or a specified scale. Property overrides on the Display Properties tab do not affect styles using blocks as markers. Any property overrides for marker styles using blocks must be made in the block definition itself.

I recommend the use of separate marker styles if the same shape is being utilized in multiple styles. For instance, if a circle is being used in both an alignment style as well as an assembly code set, use two separate styles so that you can scale them independently of each other.

Thursday, March 19, 2009

Short PVI Extensions

http://c3dsupport.blogspot.com/2009/03/short-pvi-extensions-better-way.html

This is helpful to know if you are trying to build your perfect template. Peter Funk showed this to me when I was up in Manchester and my reaction was "duh" i.e. I couldn't believe I was doing it the hard way all this time.

Parcel Area – Commas

There is a wonderful trick on the Civil 3D Reminders blog on how to work commas in your parcel areas using one label style!

Click here to see the original blog: Parcel Area – Commas

Just to clarify, the trick involves six expressions:

  • HundredsSize: IF({Parcel Area}>1000,0.0000000000000001,0.1/12)
  • Hundreds: ({Parcel Area}/1000000-TRUNC({Parcel Area}/1000000))*1000
  • ThousandsSize: IF({Parcel Area}>1000, IF({Parcel Area}<1000000,0.1/12,0.0000000000000001),0.0000000000000001)
  • Thousands: {Parcel Area}/1000000
  • MillionsSize: IF({Parcel Area}>1000000,0.1/12,0.0000000000000001)
  • Millions: {Parcel Area}/1000000000

The label involves 4 text components: Parcel Name, Hundreds, Thousands, Millions

  • Parcel Name is the parcel name.
  • Hundreds is the area label configured for when parcel area is less than 1000.
  • Thousands is the area label configured for when parcel area is more than 1000 and les than 1,000,000.
  • Millions is the area label configured for when parcel area is more than 1,000,000.

The latter three components size themselves down to nothing as per the "Size" expressions listed above depending upon how their conditions check. In this example, labels will go in at 0.1" i.e. 0.1/12 as the expression reads. If you label using a smaller height like at 0.08", change each "Size" expression to use 0.08/12.

Think this is brilliant? Thank Christopher Fugitt who posted it at 12:31 AM this morning!

AU File & Object Layer Eccentricities

I developed a bare bones template working file for my 2008 AU class called "Building the Perfect Template-Making All of Your Civil 3D 2009 Dreams Come True". It was loaded up with sample styles and sample content. The style components are all configured to layer 0.

The object layers were configured to layer names prefixed with $. The reason for this was so that they would easily stand out if we spent a lot of time talking about them. Object layers cannot be simply renamed. You must create the new layer names and redirect the object layer items in Drawing Settings to the new layers. These new layers can be created with layer manager or with the "New" tool in the Layer Selection dialog box that appears when you click into the layer field in the Object Layer tab.

Object layers can easily be purged out of a drawing if they are not being used. This can be bad if you've configured color and linetype to them. If objects are created in an object layer that has been purged from a drawing, the layer will be recreated using color 7 and continuous linetype. No worries if you are leaning on component layers to define color and linetype for you.

Tuesday, March 17, 2009

Starting with a Blank Canvas

If you do want to use your own layer standard, text style, blocks and linetypes in your Civil 3D template and want to avoid issues with not being able to purge undesirable, existing content out of your template file, I always suggest that people create their template from acad.dwt. This will provide you with an empty file. You can then use Design Center to bring in your standards. However, there are some issues to be aware of before you start your customization:

Standard Styles are not at Ground Zero
The components in the Standard styles are set to use layer “0”, but are configured with color overrides and linetypes set to byblock. If you try to create a new style at the object level, your new style will be produced with the same settings. It would be ideal if colors and linetypes were both set to bylayer. If it were at least so in the Standard styles, we could create new styles with a copy with “Ground Zero” configuration.

Ambient, Feature & Command Settings
Always start at Drawing Settings and work your way down. If you examine the Ambient Settings tab in the Drawing Settings dialog, you’ll find that precisions for each of the units may not suit you. In addition, overrides have been placed for you. Personally, I like to have total command over the overrides so I kill them at the drawing level and reconfigure units, formats and precisions to my standards. Then I visit Feature Settings and Command Settings in case there are overrides I want to make in a particular area.

Label Style Defaults
There are some settings and overrides issues here as well. Killing the overrides at this level, setting the default orientation reference to “View”, and configuring text style and height will allow you to start dictating label standards at higher levels in your template. Make any adjustments on these settings at lower levels keeping in mind the Civil 3D hierarchy of settings.

The Standard text style is configured into all of the label settings and styles in the acad.dwt template. If you are open to using a text style called “Standard” as your standard with your preferred font settings, the modifications will be inherited in the labels, tables and views therefore cutting out a good amount of work. Although text style can be overridden at the drawing level for labels, view styles and table styles require that you open up each and make those changes.

In Conclusion
Addressing these issues will get you a “Ground Zero” template providing you a blank canvas to start your work. But you’ll get there faster if you download the following file in which all of these issues have already been addressed. C3D2009_Ground_Zero.DWT

Enjoy!