Thursday, April 26, 2012

Draw Order Extended

In my last post, I mentioned that I have been working on modifying the Draw Order By Layer command found on the Autodesk Labs Plugin of the month page here. I think I have pretty much perfected it to the best of by ability and for what I wanted it to do.

First, I added additional tabs for other items needed to adjust draw order. The tabs added were XREFs, Blocks, Civil3D Surfaces, and a Checked Items Tab. Now, many of these items could have been moved to a separate layer and then adjusted via the basic Draw Order By Layer tab, but for many of these items, that goes against company standards. We typically put all of our XREFs on one XREF layer and Civil3D surfaces automatically go on one surface layer, so why not just allow for adjustment of these items? The blocks tab was added for me personally as many times I might have the same block on multiple layers and need to adjust accordingly for all instances, thus selecting the block name made sense. The checked items tab I think is the coolest, as it allows for you to work with all object on a selected layer (or multiple layers), XREF objects selected, and blocks selected - and if you think outside the box it will handle all Civil3D surfaces via the layer the surfaces go on. Trust me, I tried to incorporate Civil3D surfaces to this list as well, but Civil3D would crash hard when adjusting - and I'm not sure why.

Here is what the command looks like:








The best workflow I have found with the command is to begin by adjusting your surfaces in the order they should display. You'll see from the image examples below the existing surface was brought over the analysis surface. Once completed rerun the command and select the necessary layers (include the default surface layer), and/or XREFs, and/or Blocks, then go to the Selected Items tab and use the update button on the far left to generate the list of checked items. Re-order everything in the desired order from top to bottom (surfaces most likely at bottom) and you'll see in the last image everything has been updated.




--------------------------------------------------------------------------------------------------------------------------------------------------
AutoCAD Civil3D 2011 Version - as shown above
--------------------------------------------------------------------------------------------------------------------------------------------------
Zip File
If you are interested in the Zip file for the actual code, you can download from here.

DLL File
If you are interested in the dll file for the plugin command, you can download from here. Then run the NETLOAD command in Civil3D and select the file. The command will runs with the command DOEXT.
--------------------------------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------------------------------------
AutoCAD 2011 Version - minus the Surfaces tab shown above
--------------------------------------------------------------------------------------------------------------------------------------------------
Zip File
If you are interested in the Zip file for the actual code, you can download from here.

DLL File
If you are interested in the dll file for the plugin command, you can download from here. Then run the NETLOAD command in Civil3D and select the file. The command will runs with the command DOEXT.
--------------------------------------------------------------------------------------------------------------------------------------------------

Wednesday, April 25, 2012

AutoCAD VB.net Programming with DXFCODEs

Over the last couple of weeks I've been working with the code for the January 2011 release of DrawOrder by Layer for AutoCAD on the Autodesk Labs Plugin of the month page which can be found here. The code uses a selection filter via the DXFCODE protocol to find the layer names matching the strings in the list generated from the block table record. I am currently revising this command to add some additional items and will post it once it is complete. Here is what the code looks like to select objects on the selected layer:

For Each lay As String In revLst
Dim psr As PromptSelectionResult
Dim tvs(0) As TypedValue
tvs(0) = New TypedValue(DxfCode.LayerName, lay)
Dim sf As New SelectionFilter(tvs)
psr = ed.SelectAll(sf)
If psr.Value IsNot Nothing Then
dot.MoveToTop(New ObjectIdCollection(psr.Value.GetObjectIds))
End If
pm.MeterProgress()
System.Windows.Forms.Application.DoEvents()
Next

While doing this I have been looking through the DXFCODE format codes in VB.net and have been trying to find a list of what these all do and what they are for. I found a pretty good list here, also displayed below in relation to the {}Autodesk.AutoCAD.DatabaseServices namespace. Note that these are in order by the group code and not alphabetical.

DXFCODE Group Names, Codes, and Descriptions
Group Name Group Code Description
Invalid -9999
XDictionary -6
PReactors -5 APP: persistent reactor chain
Operator -4 APP: conditional operator (used only with ssget)
FirstEntityId, XDataStart -3 APP: extended data (XDATA) sentinel (fixed)
Header -2 APP: entity name reference (fixed)
End -1 APP: entity name. The name changes each time a drawing is opened. It is never saved (fixed)
Start 0 Text string indicating the entity type (fixed)
Text, XRefPath 1 Primary text value for an entity
AttributeTag, BlockName, MlineStyleName, ShapeName, SymbolTableName, SymbolTableRecordName 2 Name (attribute tag, block name, and so on)
AttributePrompt, CLShapeName, Description, DimensionAlternativePrefixSuffix, DimPostString, DimStyleName, LinetypeProse, SymbolTableRecordComments, TextBigFontFile, TextFontFile 3-4 Other text or name values
DimensionBlock, Handle 5 Entity handle; text string of up to 16 hexadecimal digits (fixed)
DimBlk1, LinetypeName 6 Linetype name (fixed)
DimBlk2, TextStyleName 7 Text style name (fixed)
LayerName 8 Layer name (fixed)
CLShapeText 9 DXF: variable name identifier (used only in HEADER section of the DXF file)
XCoordinate 10 Primary point; this is the start point of a line or text entity, center of a circle, and so on DXF: X value of the primary point (followed by Y and Z value codes 20 and 30 APP: 3D point (list of three reals)
YCoordinate 20 DXF: Y values of the primary point
ZCoordinate 30 DXF: Z values of the primary point
Elevation 38 DXF: entity's elevation if nonzero
Thickness 39 Entity's thickness if nonzero (fixed)
PixelScale, Real, ShapeScale, ShapeXOffset, ShapeYOffset, TxtSize, TxtStylePSize, TxtStyleXScale, ViewBackClip, ViewFrontClip, ViewHeight, ViewLensLength, ViewportAspect, ViewportHeight,ViewWidth, 40-48 Floating-point values (text height, scale factors, and so on)
LinetypeScale 48 Linetype scale; floating-point scalar value; default value is defined for all entity types
DashLength, LinetypeElement, MlineOffset 49 Repeated floating-point value. Multiple 49 groups may appear in one entity for variable-length tables (such as the dash lengths in the LTYPE table). A 7x group always appears before the first 49 group to specify the table length
Angle, ViewportSnapAngle, ViewportTwist 50-58 Angles (output in degrees to DXF files and radians through AutoLISP and ObjectARX applications)
Visibility 60 Entity visibility; integer value; absence or 0 indicates visibility; 1 indicates invisibility
LayerLinetype 61 Layer Linetype
Color 62 Color number (fixed)
HasSubentities 66 "Entities follow" flag (fixed)
ViewportVisibility 67 Space-that is, model or paper space (fixed)
ViewportActive 68 APP: identifies whether viewport is on but fully off screen; is not active or is off
ViewportNumber 69 APP: viewport identification number
CircleSides, Int16, LinetypeAlign, LinetypePdc, RegAppFlags, TxtStyleFlags, ViewMode, ViewportGrid, ViewportIcon, ViewportSnap, ViewportSnapPair, ViewportSnapStyle, ViewportZoom 70-78 Integer values, such as repeat counts, flag bits, or modes
Int32 90-99 32-bit integer values
Subclass 100 Subclass data marker (with derived class name as a string). Required for all objects and entity classes that are derived from another concrete class. The subclass data marker segregates data defined by different classes in the inheritance chain for the same object. This is in addition to the requirement for DXF names for each distinct concrete class derived from ObjectARX (see "Subclass Markers")
EmbeddedObjectStart 101
ControlString 102 Control string, followed by "{" or "}". Similar to the xdata 1002 group code, except that when the string begins with "{", it can be followed by an arbitrary string whose interpretation is up to the application. The only other control string allowed is "}" as a group terminator. AutoCAD does not interpret these strings except during drawing audit operations. They are for application use
DimVarHandle 105 Object handle for DIMVAR symbol table entry
UcsOrg 110
UcsOrientationX 111
UcsOrientationY 112
XReal 140
ViewBrightness 141
ViewContrast 142
Int64 160 64-bit integer values
XInt16 170 16-bit integer values
NormalX 210 Extrusion direction (fixed)DXF: X value of extrusion direction APP: 3D extrusion direction vector
NormalY 220 DXF: Y values of the extrusion direction
NormalY 230 DXF: Z values of the extrusion direction
XXInt16 270
Int8 280 8-bit integer values
RenderMode 281
Bool 290-299 Boolean flag value
XTextString 300-309 Arbitrary text strings
BinaryChunk 310-319 Arbitrary binary chunks with same representation and limits as 1004 group codes: hexadecimal strings of up to 254 characters represent data chunks of up to 127 bytes
ArbitraryHandle 320-329 Arbitrary object handles; handle values that are taken "as is." They are not translated during INSERT and XREF operations
SoftPointerId 330-339 Soft-pointer handle; arbitrary soft pointers to other objects within same DXF file or drawing. Translated during INSERT and XREF operations
HardPointerId 340-349 Hard-pointer handle; arbitrary hard pointers to other objects within same DXF file or drawing. Translated during INSERT and XREF operations
SoftOwnershipId 350-359 Soft-owner handle; arbitrary soft ownership links to other objects within same DXF file or drawing. Translated during INSERT and XREF operations
HardOwnershipId 360-369 Hard-owner handle; arbitrary hard ownership links to other objects within same DXF file or drawing. Translated during INSERT and XREF operations
LineWeight 370-379 Lineweight enum value (AcDb::LineWeight). Stored and moved around as a short. Custom non-entity objects may use the full range, but entity classes only use 371-379 DXF group codes in their representation, because AutoCAD and AutoLISP both always assume a 370 group code is the entity's lineweight. This allows 370 to behave like other "common" entity fields.
PlotStyleNameType 380-389 PlotStyleName type enum (AcDb::PlotStyleNameType). Stored and moved around as a short. Custom non-entity objects may use the full range, but entity classes only use 381-389 DXF group codes in their representation, for the same reason as the Lineweight range above.
PlotStyleNameId 390-399 String representing handle value of the PlotStyleName object, basically a hard pointer, but has a different range to make backward compatibility easier to deal with. Stored and moved around as an Object ID (a handle in DXF files) and a special type in AutoLISP. Custom non-entity objects may use the full range, but entity classes only use 391-399 DXF group codes in their representation, for the same reason as the Lineweight range above.
ExtendedInt16 400-409 16-bit Integers
LayoutName 410-419 String
ColorRGB 420
ColorName 430
Alpha 440
GradientObjectType 450
GradientPatType 451
GradientTintType 452
GradientColCount 453
GradientAngle 460
GradientShift 461
GradientTintVal 462
GradientColVal 463
GradientName 470
Comment 999 DXF: The 999 group code indicates that the line following it is a comment string. SAVEAS does not include such groups in a DXF output file, but OPEN honors them and ignores the comments. You can use the 999 group to include comments in a DXF file that you've edited
ExtendedDataAsciiString 1000 ASCII string (up to 255 bytes long) in extended data
ExtendedDataRegAppName 1001 Registered application name (ASCII string up to 31 bytes long) for extended data
ExtendedDataControlString 1002 Extended data control string ("{"or "}")
ExtendedDataLayerName 1003 Extended data layer name
ExtendedDataBinaryChunk 1004 Chunk of bytes (up to 127 bytes long) in extended data
ExtendedDataHandle 1005 Entity handle in extended data; text string of up to 16 hexadecimal digits
ExtendedDataXCoordinate 1010 A point in extended data DXF: X value (followed by 1020 and 1030 groups) APP: 3D point
ExtendedDataWorldXCoordinate 1011 A 3D world space position in extended data DXF: X value (followed by 1021 and 1031 groups) APP: 3D point
ExtendedDataWorldXDisp 1012 A 3D world space displacement in extended data DXF: X value (followed by 1022 and 1032 groups) APP: 3D vector
ExtendedDataWorldXDir 1013 A 3D world space direction in extended data. DXF: X value (followed by 1022 and 1032 groups) APP: 3D vector
ExtendedDataYCoordinate 1020 DXF: Y and Z values of a point
ExtendedDataWorldYCoordinate 1021 DXF: Y and Z values of a world space position
ExtendedDataWorldYDisp 1022 DXF: Y and Z values of a world space displacement
ExtendedDataWorldYDir 1023 DXF: Y and Z values of a world space direction
ExtendedDataZCoordinate 1030 DXF: Y and Z values of a point
ExtendedDataWorldZCoordinate 1031 DXF: Y and Z values of a world space position
ExtendedDataWorldZDisp 1032 DXF: Y and Z values of a world space displacement
ExtendedDataWorldZDir 1033 DXF: Y and Z values of a world space direction
ExtendedDataReal 1040 Extended data floating-point value
ExtendedDataDist 1041 Extended data distance value
ExtendedDataScale 1042 Extended data scale factor
ExtendedDataInteger16 1070 Extended data 16-bit signed integer
ExtendedDataInteger32 1071 Extended data 32-bit signed long

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.

Civil 3D Labels Showing "XREF Moved"

Last week I ran into an issue where a drawing's Civil 3D labels were displaying XREF Moved as shown in the image below:

I did some research and found a blog regarding this issue (a link to the blog can be found at the bottom of this page). Though the blog's reasoning for this error may be correct, I found that it was not the solution to the issue I was having. After further research in the drawing, I found that indeed, the XREF had actually been moved. The labels were creating by lableing contours through the XREF, thus when the XREF was moved the labels reflected the error - kudos to Autodesk for thinking of this. Had the labels not stated the XREF was moved, it may not have been noticed by anyone reviewing plans as it was moved a very minor amount.


Track back to original blog solution that was not the solution of my problem.
http://beingcivil.typepad.com/my_weblog/2009/04/xref-moved.html

Chicago Civil 3D User Group

Last we Tuesday we held the first group meeting for the Chicago Civil 3D User Group. It was a success thanks to everyone who came out with interest and support. We had 12 attendees. The next group meeting will be on Tuesday, April 17th from 7:00pm-8:30pm. Definitely looking forward to that meeting as we will be covering the new features of AutoCAD Civil 3D 2013.

Should you or anyone you know be interested in the group, you can view the group page on LinkedIn here: Chicago Civil 3D User Group Page.