28
Walt Disney World Swan and Dolphin Resort Orlando, Florida 11/30/2005 - 5:00 pm - 6:30 pm Room:Swan 5/6 (Swan) Programming Corridor Assemblies in Autodesk® Civil 3D® The ultimate power of the corridor model in Civil 3D lies in the subassembly code. This class will show you how to unlock that power by creating new subassemblies. We will start by setting up the subassembly and adding it to your catalog. We'll then do some programming with the corridor API to produce a subassembly that does amazing things. CV35-3 About the Speaker: Peter Funk - Autodesk Peter is the API product manager of Autodesk's Infrastructure Solutions Division. He spends his time traveling the world helping customers and partners extend and enhance the GIS and civil engineering applications from Autodesk. [email protected]

Programming Corridor Assemblies in Autodesk® …...Programming Corridor Assemblies in Autodesk® Civil 3D® 4 C3DStockSubassemblyScripts.codes When you add a point, link or shape

  • Upload
    others

  • View
    30

  • Download
    0

Embed Size (px)

Citation preview

Walt Disney World Swan and Dolphin ResortOrlando, Florida

11/30/2005 - 5:00 pm - 6:30 pm Room:Swan 5/6 (Swan)

Programming Corridor Assemblies in Autodesk® Civil 3D®

The ultimate power of the corridor model in Civil 3D lies in the subassembly code. This class will show you how to unlock that power by creating new subassemblies. We will start by setting up the subassembly and adding it to your catalog. We'll then do some programming with the corridor API to produce a subassembly that does amazing things.

CV35-3

About the Speaker:

Peter Funk - Autodesk

Peter is the API product manager of Autodesk's Infrastructure Solutions Division. He spends his time traveling the world helping customers and partners extend and enhance the GIS and civil engineering applications from [email protected]

Programming Corridor Assemblies in Autodesk® Civil 3D®

2

Programming Corridor Assemblies in Autodesk® Civil 3D®

Subassemblies are a key component the most powerful tool in Autodesk® Civil 3D®: corridor modeling. Subassemblies build off the age old concept of the cross section template, but add intelligence and flexibility with the addition of simple VBA programming. This gives the power to make subassemblies that are infused with design intelligence.

This class will focus on how to make a subassembly and add it to your current system. To that end, we’ll make a few new subassemblies that illustrate the range of the subassembly and the API. In addition, we will look at post-processing a corridor model to extract information from the subassemblies.

Concepts of the corridor model A corridor model is made of three essential components: an alignment, a profile and an assembly. Civil 3D generates a corridor by stepping down the alignment and running a series of VBA routines (subassemblies) to calculate the cross sections. The subassemblies are processed from the centerline of the assembly first to the right, and then to the left, starting at the x,y of the alignment and the z from the profile. As each subassembly is processed, it picks up where the last one left off. The subassemblies will produce a collection of coded points that can be combined together to form links, and the links can be combined to form shapes (in cross section). In addition, points with the same codes are linked together from section to section to form feature lines, and links with the same codes can be joined together to form surfaces. As the design elements change (alignments, profiles and assemblies), the model and associated surfaces and cross sections will be updated to reflect the changes.

TIP: The Civil 3D help file has a complete section on how to make subassemblies. READ IT!

Points, links and shapes Making subassemblies is like playing “Connect the Dots”; you set out a series of points, connect them with lines and admire your handiwork. In Figure 1 there are four points: Point1-Point4, linked together by four links: Link1-Link4 and the four links form the outline for Shape1.

Figure 1

There are a few rules that you need to follow when using points, links and shapes:

1. All the points must lie within the plane of the corridor section

2. All the links must be straight lines. If you want to make a curved figure, you’ll have to tessellate the shape into straight line segments.

3. Shapes must be formed from contiguous links.

Codes As points, links and shapes are added to the corridor model, optional codes can be added to them as identifiers. These codes are used to control the display of the elements, their grouping and to allow other programs to identity them.

Programming Corridor Assemblies in Autodesk® Civil 3D®

3

Feature Lines

In Figure 2, you see a typical section of a corridor model with the point codes called out.

Figure 2

Feature lines are added between liked named points on sequential corridor sections, (that match the code of the points they link together, and on the same side of the corridor).

Surfaces

In Figure 3, you see the same section of corridor model, this time with the Link codes displayed, and an optional surface created between the links.

Figure 3

Corridor surfaces can be made by taking all the like named links for a corridor and adding them together to make a surface. This is one reason that you can’t make curved links. If you intend for your links to be used to make surfaces, don’t make perfectly vertical links. Instead, move the top or bottom of the link out slightly

Programming Corridor Assemblies in Autodesk® Civil 3D®

4

C3DStockSubassemblyScripts.codes

When you add a point, link or shape to the corridor model in Civil 3D, you can either supply a static code string, or you can look up a code from an external file. The advantage of looking up the code is that you can modify the codes file, and all your subassemblies will be modified. I’ve added a utility function “GetCode” to the sample application that will do the look up.

VBA and ATC files working together There are two programming components to make a complete subassembly, the VBA code that drives the corridor creation, and the ATC file that supplies the input for the VBA code, and the tool on the tool palette. Because these two files work together, you need to be very careful when you create them - Spelling and formatting count! The one thing that will trip you up is spelling, you need to make sure that the ATC file and the VBA file use exactly the same spelling for variable, macro names or things just won’t run (and you won’t know why).

When you make subassemblies for your organization, make a new subassembly catalog file, DO NOT add your subassemblies to one of the shipping subassembly file. In addition, instead of modifying an existing subassembly, make a copy of the subassembly ATC and VBA code and add it to your file. There are two reasons for this; if you modify existing code, you many change the behavior of corridors that were built with the old code, and more importantly, when you update Civil 3D (new version or service pack), we may override your files and you would lose all your hard work.

Designing subassemblies The first thing you should do when you make a subassembly is to design it. This is a critical step, and as with any engineering project, the time spent in design will reduce the time spent in construction. When we design subassemblies at Autodesk, the first thing we make is a page for the help file that will describe the subassembly. On this page, we layout the basic shape of the subassembly and callout all the parameters needed, including the option parameters. The behavior of the subassembly is also described both in design and layout mode. This is the most important section of the design. It should tell what parameters control the subassembly, and what to do in key situations. We also layout the coding diagram so that the point, link and shape codes maintain consistency.

What you can do? I like to say that “I don’t know what you can’t do with subassemblies”. I haven’t run into a situation that I couldn’t make a subassembly to solve the problem in a corridor model. In some cases, the subassembly would have become overly complex to use and would have obscured the

WallBridge Bottom

Programming Corridor Assemblies in Autodesk® Civil 3D®

5

design process, but it could be done! Not only do you have the full Civil 3D toolkit available, but you also have the AutoCAD API. You can query alignments, profiles, surfaces as well as other AutoCAD entities. For example, you could make a subassembly that would follow two polylines (on a specific layers or with Xdata attached) to make a meandering sidewalk. There are now tools in the corridor API to do this, but it’s only a matter of finding the right polylines and calculating the closest point on the line to the current corridor cross section. One of the only limitations is that you shouldn’t prompt for user input while the subassembly is processing, as this would interrupt the program flow.

Help files Appendix A, B and C are the help files for three of the subassemblies that we will make for this class, and are included to show the level of design that should be done before any code is created. These follow the standard Autodesk template for subassembly help and contain four critical parts: the Behavior, Variable Tables, Coding diagrams and the Layout / design mode.

I created the help files using Microsoft Word and then saved each file as a HTML document. After all the pages were created, I used Microsoft’s HTML Help Workshop to compress the documents (and associated graphics) into a single compiled help file (.chm). You can use any help file utility that can make a compiled help file. I download the free utility “HTML Help Workshop” at: http://www.microsoft.com/office/orkarchive/XPddl.htm.

You need to place your help compiled files in the Civil 3D Help directory.

Description

The first section in your help file should show a picture of the subassembly and a brief description of what you want it to do, and how it should be used.

Behavior

This is the most important section, as it spells out how the assembly is designed to work. You should describe how you expect the subassembly will be used, where it should be attached, how it will interact with optional alignments, profiles and surfaces, and any other special behaviors that you intend for it to have. This is your specification.

Variable Tables

By making the before you start coding the ATC file, you will have the complete picture of what is needed, how they will be used and all the parameters necessary for them.

Subassembly sketches and Coding diagrams

The coding diagram should be added to a sketch of how the subassembly will look when completed. Without this sketch you shouldn’t even attempt to start the code.

As part of the sketches, if you layout has a different look in layout mode, you should add that as well. Not only will that help in your coding, but will also explain to your users why the subassembly looks differently in layout mode.

The ATC File The ATC file is the conduit from your subassembly program to the user, and is the first step in making a new subassembly. The ATC file is a XML file with the extension ATC (Autodesk Tool Catalog). There are any number of editors designed to work with XML files, including Altova® XMLSpy®, Microsoft Visual Studio, but Notepad works fine as well.

Programming Corridor Assemblies in Autodesk® Civil 3D®

6

TRICK: Rename your ATC file XML and edit the file with a XML editor instead of Notepad. While testing the file, make a copy of the XML file, and change just the extension back to ATC.

Catalogs, categories, tools The ATC file is broken into three sections, Catalogs, Categories and Tools. If you look at the shipping ATC files from Autodesk, because of the large number of subassemblies we ship, we split the Catalogs and Categories out from the tools. These three sections correspond with the three levels found in the Tool Catalog.

Catalogs

This is the top level of the ATC file, and is used as the container for all your subassemblies. In the shipping ATC file from Autodesk, we have two catalogs for subassemblies, one for metric and the other for imperial.

See the sample ATC file for an example of how to make your own catalog. Be sure to replace the GUID in the sample file with a new unique one.

Categories

The next level down is categories. Categories are used to organize your tools into logical groups. In the shipping catalog, we have categories for Rehab, Transportation, Subdivisions, Generic Links and one for getting started.

See the sample ATC file for an example of how to make your own category. Be sure to replace the GUID in the sample file with a new unique one.

Tools

The tools are the subassemblies. Each subassembly is added into the catalog as a tool. These tools can then be added to a palette, or run directly from the catalog. We’ll break down the different parts of the tool

ID

The Item ID is a GUID that Civil 3D uses to identify this tool. The Item ID must be unique. If you use sample files that are part of this class, I suggest that you change the GUIDs for the Catalog, Category and Tools before you use them on your machine.

GUIDS

A GUID is a Globally Unique Identifier, a unique 128-bit number (very large number), that is generated based on a combination of some unique things (e.g. your IP Address, system time). We use the GUID to identify the tools on the tool palette and find our way back to your ATC file.

To generate GUIDS, you’ll need to have a copy of the Microsoft utility GUIDgen.exe. You can download a free copy at: http://www.microsoft.com/downloads/details.aspx?FamilyID=94551F58-484F-4A8C-BB39-ADB270833AFC&displaylang=en.

Programming Corridor Assemblies in Autodesk® Civil 3D®

7

When you create your GUIDs, you need to make sure they are in the “Registry Format”. After starting GUIDgen, use the “Copy” button to put the new GUID on the clip board, and then paste it into the ATC file. If you need another one, press “New GUID” to generate a new one, and repeat the copy.

NOTE: Don’t overwrite the “StockToolRef” GUID, or you won’t be able to drag your new tool on to the palette.

Item Name

The Item Name is the name that shows up in the tool catalog, and also the default name on the tool palette and forms the base of the name when inserted into an assembly, for example: LaneOutsideSuper (14) would be the 14th subassembly added to the drawing.

Image

The image for a tool should be a 64x64 pixel PNG file. If the file is any other size, it will be stretched or compressed into 64x64.

Description

This is the description the user sees when they hover over the tool.

Help File

This should be a link to the help page that you made in the design stage. It has three parts: the help file (placed in the Civil 3D Help directory), the help command (don’t change the default value), and the Help Data (the page in the help file).

Stock Tool ID

The value for the Stock Tool Reference is: {7F55AAC0-0256-48D7-BFA5-914702663FDE}. DO NOT change this value or your subassembly won’t work!

Macro Name

The macro name is supplies the connection between your tool and the subassembly VBA code that generated the corridor model. Make sure that the file name is correct, the path is correct and that the module and function names all match what is in your VBA file. This is one of the most common places for people to make mistakes. There is a system variable “%AECCCONTENT_DIR%” that you can use if you place your VBA file in the same folder as the “C3DStockSubassemblyScripts.dvb” file. By default this is “C:\Program Files\Autodesk Civil 3D 2006\Data\Corridor Model”.

Programming Corridor Assemblies in Autodesk® Civil 3D®

8

Parts of the Macro Name:

• File name (with path and extension)

• Project name (by default “ACADProject”)

• Module name (by default “Module1”)

• Macro Name

Parameters

After the house keeping is done, we can get to the good stuff, the parameters (variables) that are used in the subassembly. A typical parameter has 4 or 5 parts to its definition. We’ll break down the following parameter:

<Width DataType="Double" TypeInfo="16" DisplayName="Width" Description="Basic Width of the Lane">12</Width>

Name In this example the name is “Width”. Notice the line starts with “<Width” and will end with “</Width>”

Data Type

We can specify four different types of data in an ATC file:

• String

• Boolean (yes/no, true/false)

• Long (whole numbers)

• Double (real numbers). In this example a “Double” is specified.

Type Information

See Table A for a list of all the different ways that the data elements can be formatted and displayed to the user. In this case we specify “16” and the number will be displayed in the UI as a distance in the base unit (feet/meters)

Description

This is the description of the parameter that will be displayed when the user hovers over it in the UI.

Default Value

The default value will be placed in the UI.

TIP: Don’t leave out the default value. The subassembly won’t work correctly without it.

Enumerated parameters

Enumerated parameters are a way of presenting a set list of parameters to the user to choose from. For example the left/right variable is done with an enumerated parameter list. We use enumerated parameters for left/right in most of the subassemblies. In the “Amazing Lane” subassembly, you’ll see how to use an enumerated parameter for the superelevation information.

TIP: If the file won’t load, there’s an error in the file. Check for matching <xxx> and </xxx>

The VBA Code The VBA code provides the brains for the subassembly. With it, you program the behavior of the subassembly using all the tools of VBA along with some new corridor specific tools.

When you create a subassembly macro file, use the following file structure:

Programming Corridor Assemblies in Autodesk® Civil 3D®

9

1. Place your code in a separate file from the shipping DVB module so that it won’t be overridden when the software is updated.

2. Place you all your code in a single company file (reduces the loading time).

3. Put each sub assembly in a separate VBA Module, and make sure you specify that module in the ATC file. This simplifies finding your subassembly when you need to modify it.

4. Name the main macro of the subassembly the same as the module name, and make that the same as the Item Name in the ATC file. Make sure all three of these names match, and that you don’t use any spaces in the names.

In your VBA module you will have the main subroutine, for example: ZZZ and three related subroutines: GetLogicalNames_ZZZ, GetInputParameters_ZZZ and GetOutputParameters_ZZZ. I like to think of the three related subroutines as setting up a “bucket o’ parameters” that Civil 3D will fill, and you will get your values from.

Type Libraries

As shown in Figure 4, you’ll need to reference two additional type libraries for your subassembly code: Autodesk Civil Engineering Corridor 3.0 Object Library and the Autodesk Civil Engineering UI Corridor 3.0 Object Library.

Figure 4

NOTE: inside of the Corridor type library, you’ll see references to “Roadway” object such as the Roadway State object, or the Roadway Links collections. Roadway was the original name of the corridor feature, and after we published the first version of the type library, we couldn’t go back and rename the objects (per Microsoft’s COM/ActiveX guidelines).

GetLogicalNames

This subroutine is where you tell Civil 3D about any additional alignments, profiles and/or surfaces that you want to reference in your subroutine. The type of the bucket for these is a long, and you pass in the name of the element and a type from the list below:

• aeccParamLogicalNameTypeAlignment

• aeccParamLogicalNameTypeProfile

• aeccParamLogicalNameTypeSurface

Programming Corridor Assemblies in Autodesk® Civil 3D®

10

The name that you pass in is the same name that will appear in the UI for setting the logical name, so make sure that is descriptive.

You will always have the main alignment and profile for the corridor, so you don’t need to add logical names for these two features.

GetInputParameters

Input Parameters are where you setup the connection between your ATC file and the VBA files. No values are actually retrieved here, but the framework is defined. You can make up to four parameter buckets here, one for each of the different types: string, long, double and Boolean.

When you add the parameters to the different buckets, make sure the string you pass in exactly matches the parameter name in the ATC file. If not, the values won’t be retrieved and you’ll get an error message.

GetOutputParameters

While “Get” Output Parameters may seem like an illogical name for an output function, what it is designed to do is make the parameter buckets for you main macro to put information into. These buckets will then be available to the user interface for other subassemblies to draw information from. If you set the output parameters, you’ll have to add code at the bottom of the main macro to fill out the parameters before you leave the subroutine.

Main Macro

The main macro is the guts of the code. This is where you will generate the cross sectional information for the subassembly. The basic flow of the code is as follows:

1. Get the information from the ATC file

2. Get in information from the Logical Names

3. Get additional information from the model

a. Superelevation information

b. Station offset to a second alignment

c. Secondary profile information

d. Surface information

e. Marked Points (see below)

4. Generate the Points

5. Link the points together to form links

6. Join the links together to form shapes

Getting information from the ATC file

The first step is to get the information from the ATC file. The information is stored in parameter buckets filed by the parameter name (set in the section above).

TRICK: Dimension your variables first as “variant”. This allows you to check if they are “empty” and if they are, then fill them with a default value. If you declare them double, string etc, you can’t check for this state.

Get information from the logical names

The next step would be to get any logical objects that you may need, like a secondary alignment or a surface. Before you do this, you need to make sure the subassembly is being processed as part of a corridor and not in layout mode. You retrieve the objects from unique buckets for each object

Programming Corridor Assemblies in Autodesk® Civil 3D®

11

type. Make sure the name that you pass in is the same as the name you used to create the logical name mapping.

Getting information from the model

There are many different ways to get information from the model, and all the tools of the Civil 3D API and the AutoCAD API are at your disposal.

For example, to retrieve superelevation information, you would get the current alignment and the current station (from the Roadway State object) and then query the alignment for the superelevation information just like you would in any other VBA routine. The Amazing Lane example demonstrates this.

Other example would be to sample a surface for the profile between two points. In the Top Soil Stripping example will illustrate this, and will show how to process the information into corridor points and links.

Figure 5

In figure X you can see some of the information that can be gleaned from the Civil 3D model. For example, you can check to see if a point is above a surface, or project to a surface using tools in the corridor API.

Getting information from the corridor

You can also get information for the corridor about the subassemblies that have already been processed. For example, you could find a “Marked Point”

Programming Corridor Assemblies in Autodesk® Civil 3D®

12

Figure 6

If Figure 6, the current assembly (attached to an offset baseline) is looking back to the previous subassemblies to find the location of the “Marked Point”, and will then generate a link back to that point.

NOTE: Remember the corridor is processed from inside to the outside, first on the right and then on the left. You can’t get information from subassemblies that have yet to be processed.

Geometric calculations

The VBA library inside of AutoCAD is light on tools for making geometric calculations. For simple line/line intersections, I’ve created a utility function that will return the intersection points that I’ve added to the Utilities module in the sample DVB file. For more complex calculations like the intersection of a line with a polylines or alignment, I draw a line entity in model space, and then use the “IntersectWith” method to find the intersection points, and delete the line. This all happens pretty quickly, so the line won’t even be seen on the screen.

TIP: Width * Slope expressed as a percentage = the rise or fall of the line.

TRICK: 2 * Atn(1) = 90° in radians

Drawing the subassembly

When you calculate the points for the subassembly think “Delta Offset, Delta Elevation”. When you add the corridor points, you give the distances in terms of offset and elevation from the insertion point of the subassembly.

Design Mode / Layout Mode

Adding Points, Links and Shapes

The first things to add to the subassembly are the Points. Points require an offset, elevation and a optional Point Code, and are added to the collection of Roadway points.

Figure 7

In Figure 7, we see four points laid out for the basic lane subassembly. They were entered with the offset and elevation from the assembly base point, or origin point for the subassembly.

Programming Corridor Assemblies in Autodesk® Civil 3D®

13

TIP: if you are making add two points that will later be used to make a link that will be used to make a surface, be sure to give your points a slight offset so you don’t create a vertical link.

Adding the Links

After adding the four points, we will then make a series of links. To make a link you need an array of at least 2 points, and an optional code string. Typically we use an array of two roadway points adding two points, making the link, and then reusing the array to make the next link. If you are making a subassembly with many links sharing the same code, you could create a link with more than two points in it.

Figure 8

In Figure 8, you see the four links that we have added for our subassembly. Note that we added the links clockwise. If you don’t, then any shapes made from those links may come out twisted.

Adding the Shapes

The final step would be to take the links and make them into a shape. To add a shape to the shape collection, you need an array of links and an optional shape code.

Figure 9

Figure 9 shows the shape added to the lane.

Layout mode vs. design mode

There are two modes of drawing subassemblies, the design mode inside a corridor and the layout mode where the subassembly is not yet part of a corridor. In the second case, we may not have enough information to fully process the subassembly code, so we use the layout mode as a shorthand notation for the subassembly.

TRICK: Use temporary AutoCAD entities to find intersections; just be sure to erase them when you’re done.

TIP: One limitation to the corridor information can only be passed from inside to outside within a single group (side) of the assembly. However, you can get around this by the use of global variables to pass information between subassemblies or from previous sections.

The shipping subassemblies from Autodesk, Inc. are designed to process lane slopes in the following order: default slope, superelevation slope, and profile elevation, with the last one defined setting the elevation at the outside of the lane.

Programming Corridor Assemblies in Autodesk® Civil 3D®

14

Reading the Corridor Model After the corridor is generated you can use the API to iterate over the corridor and get the points, links and shapes that make up the corridor model. From the points, links and shapes you can get their location, and the codes. With this information you can process the corridor model for reporting.

Reading the corridor model goes beyond the scope of this class, but I’ve added a sample application that will read the corridor model and extract a slope stake report to a series of tables in Microsoft Word for you to use as an example.

Programming Corridor Assemblies in Autodesk® Civil 3D®

15

Type Info Table

Data Type Type String Description Example Boolean Boolean 0 true or false True Boolean No/Yes 1 yes or no Yes Boolean Disabled/Enabled 5 enabled or disabled Enabled Boolean Off/On 6 on or off On Boolean Right/Left 7 right or left Right Long Long 0 any integer value -1,0,1 Non Zero Long 1 any non-zero integer value -1,1 Non Negative Long 2 any zero or positive integer 0,1 Non Negative Non Zero Long 3 any non-zero positive integer 1 Non Positive Long 4 any zero or negative integer -1,0 Non Positive Non Zero Long 5 any non-zero negative integer -1 Double Double 0 any double value Non Negative Double 1 any zero or positive double Non Negative Non Zero Double 2 any non-zero positive double Non Positive Double 3 any zero or negative double Non Positive Non Zero Double 4 any non-zero negative double Non Zero Double 5 any non-zero double Station 6 Station Format Grade 8 for slope or grade input value Transparent Command Grade 9 for grade input values Transparent Command Slope 10 for slope input values Angle 14 angular value Convergence Angle 15 convergence angular value Distance 16 distance value Dimension 17 dimension value Elevation 21 elevation value Percent 25 percent value

Prog

ram

min

g C

orrid

or A

ssem

blie

s in

Aut

odes

k® C

ivil

3D®

16

<Tool>

<ItemID idValue="{82F1302E-A276-4bd3-A19B-FF33767B2C28}" />

<Properties>

<ItemName>AmazingLane</ItemName>

<Images>

<Image cx="64" cy="64" src=".\Images\AmazingLane.png" />

</Images>

<Description>Tool Description</Description>

<Keywords></Keywords>

<AccessRight>1</AccessRight>

<Help>

<HelpFile>.\Help\MySubassembliesHelp.chm</HelpFile>

<HelpCommand>HELP_HHWND_TOPIC</HelpCommand>

<HelpData>AmazingLane.htm</HelpData>

</Help>

<Time createdUniversalDateTime="2002-04-05T21:58:00" modifiedUniversalDateTime="2002-04-05T21:58:00" />

</Properties>

<Source />

<StockToolRef idValue="{7F55AAC0-0256-48D7-BFA5-914702663FDE}"/>

<Data>

<AeccDbSubassembly>

<Macro Module="C:\CV35-3\MySubassemblies.dvb">MySubassemblies.AmazingLane.AmazingLane</Macro>

<Params>

<Side DataType="Long" DisplayName="Side" Description="Specifies which side to place the subassembly">0

<Enum>

<Right DisplayName="Right">0</Right>

<Left DisplayName="Left">1</Left>

</Enum>

</Side>

<Width DataType="Double" TypeInfo="16" DisplayName="Width" Description="Basic Width of the Lane">12</Width>

<EndingWidth DataType="Double" TypeInfo="16" DisplayName="Ending Width" Description="Ending Width of the lane in taper">12</EndingWidth>

<Depth DataType="Double" TypeInfo="17" DisplayName="Depth" Description="Basic depth of the lane">1</Depth>

<Slope DataType="Double" TypeInfo="8" DisplayName="Slope" Description="Default slope for the lane">-0.02</Slope>

<SStation DataType="Double" TypeInfo="6" DisplayName="Starting Station" Description="Starting station of the option taper">0</SStation>

<EStation DataType="Double" TypeInfo="6" DisplayName="Ending Station" Description="Ending station of the optional taper">0</EStation>

<SuperRegion DataType="Long" DisplayName="Super Elevation" Description="Specifies superelevation region">0

<Enum>

<Default DisplayName="Default">0</Default>

<LO DisplayName="LO">1</LO>

<LI DisplayName="LI">2</LI>

<SO DisplayName="LI">3</SO>

<SI DisplayName="LI">4</SI>

</Enum>

</SuperRegion>

<ShapeCode DataType="String" DisplayName="Shape Code" Description="Code that will be use on the shape">""</ShapeCode>

</Params>

</AeccDbSubassembly>

<Units>i</Units>

</Data>

</Tool>

17

Option Explicit

Public Sub AmazingLane()

Dim oRwyState As AeccRoadwayState

Set oRwyState = GetRoadwayState()

' Retrieve parameter buckets from the roadway state

Dim oParamsDouble As AeccParamsDouble

Set oParamsDouble = oRwyState.ParamsDouble

Dim oParamsLong As AeccParamsLong

Set oParamsLong = oRwyState.ParamsLong

'---------------------------------------------------------

' now fetch a few parameters we're interested in

On Error Resume Next

Dim vWidth As Variant

vWidth = oParamsDouble.Value("Width")

If IsEmpty(vWidth) Then vWidth = c_dWidthDefault

Dim vEndingWidth As Variant

vEndingWidth = oParamsDouble.Value("EndingWidth")

If IsEmpty(vEndingWidth) Then vEndingWidth = c_dEndingWidthDefault

Dim vDepth As Variant

vDepth = oParamsDouble.Value("Depth")

If IsEmpty(vDepth) Then vDepth = c_dDepthDefault

Dim vSlope As Variant

Dim dSlope As Double

vSlope = oParamsDouble.Value("Slope")

If IsEmpty(vSlope) Then vSlope = c_dSlopeDefault

Dim vStartingStation As Variant

vStartingStation = oParamsDouble.Value("StartingStation")

If IsEmpty(vStartingStation) Then vStartingStation = c_dStartingStationDefault

Dim vEndingStation As Variant

Prog

ram

min

g C

orrid

or A

ssem

blie

s in

Aut

odes

k® C

ivil

3D®

18

vEndingStation = oParamsDouble.Value("EndingStation")

If IsEmpty(vEndingStation) Then vEndingStation = c_dEndingStationDefault

Dim vSide As Variant

vSide = oParamsLong.Value("Side")

If IsEmpty(vSide) Then vSide = c_iSideDefault

Dim vSuperRegion As Variant

vSuperRegion = oParamsLong.Value("SuperRegion")

If IsEmpty(vSuperRegion) Then vSuperRegion = c_iSuperRegionDefault

Dim dFlip As Double

If vSide = 1 Then

dFlip = 1

Else

dFlip = -1

End If

Select Case vSuperRegion

Case 0

vSuperRegion = "Default"

Case 1

vSuperRegion = "LO"

Case 2

vSuperRegion = "LI"

Case 3

vSuperRegion = "SO"

Case 4

vSuperRegion = "SI"

End Select

If oRwyState.Mode = aeccRoadwayModeDesign Then

Dim oAlignment As AeccAlignment

Set oAlignment = oRwyState.CurrentAlignment

If vSide = 0 Then

Select Case vSuperRegion

Prog

ram

min

g C

orrid

or A

ssem

blie

s in

Aut

odes

k® C

ivil

3D®

19

Case "SI"

dSlope = oAlignment.SuperelevationAtStation(oRwyState.CurrentStation).SegmentCrossSlope(aeccSuperLeftInShoulderCrossSlope)

Case "SO"

dSlope = oAlignment.SuperelevationAtStation(oRwyState.CurrentStation).SegmentCrossSlope(aeccSuperLeftOutShoulderCrossSlope)

Case "LI"

dSlope = oAlignment.SuperelevationAtStation(oRwyState.CurrentStation).SegmentCrossSlope(aeccSuperLeftInLaneCrossSlope)

Case "LO"

dSlope = oAlignment.SuperelevationAtStation(oRwyState.CurrentStation).SegmentCrossSlope(aeccSuperLeftOutLaneCrossSlope)

Case "Default"

dSlope = vSlope

End Select

Else

Select Case vSuperRegion

Case "SI"

dSlope = oAlignment.SuperelevationAtStation(oRwyState.CurrentStation).SegmentCrossSlope(aeccSuperRightInShoulderCrossSlope)

Case "SO"

dSlope = oAlignment.SuperelevationAtStation(oRwyState.CurrentStation).SegmentCrossSlope(aeccSuperRightOutShoulderCrossSlope)

Case "LI"

dSlope = oAlignment.SuperelevationAtStation(oRwyState.CurrentStation).SegmentCrossSlope(aeccSuperRightInLaneCrossSlope)

Case "LO"

dSlope = oAlignment.SuperelevationAtStation(oRwyState.CurrentStation).SegmentCrossSlope(aeccSuperRightOutLaneCrossSlope)

Case "Default"

dSlope = vSlope

End Select

End If

End If

Dim pt1(0 To 1) As Double

Dim pt2(0 To 1) As Double

Dim pt3(0 To 1) As Double

Prog

ram

min

g C

orrid

or A

ssem

blie

s in

Aut

odes

k® C

ivil

3D®

20

Dim pt4(0 To 1) As Double

Dim oRoadwayPoints As AeccRoadwayPoints

Set oRoadwayPoints = oRwyState.Points

pt2(0) = vWidth * dFlip: pt2(1) = vWidth * dSlope

pt3(0) = pt2(0): pt3(1) = pt2(1) - vDepth

pt4(0) = 0: pt4(1) = -vDepth

Dim oPoint1 As AeccRoadwayPoint

Dim oPoint2 As AeccRoadwayPoint

Dim oPoint3 As AeccRoadwayPoint

Dim oPoint4 As AeccRoadwayPoint

Set oPoint1 = oRoadwayPoints.Add(pt1(0), pt1(1), GetCode("ETW"))

Set oPoint2 = oRoadwayPoints.Add(pt2(0), pt2(1), "")

Set oPoint3 = oRoadwayPoints.Add(pt3(0), pt3(1), "")

Set oPoint4 = oRoadwayPoints.Add(pt4(0), pt4(1), "")

Dim oLinkPointArray(1) As AeccRoadwayPoint

Dim oLinkArray(3) As AeccRoadwayLink

Dim oRoadwayLinks As AeccRoadwayLinks

Set oRoadwayLinks = oRwyState.Links

Set oLinkPointArray(0) = oPoint1

Set oLinkPointArray(1) = oPoint2

Set oLinkArray(0) = oRoadwayLinks.Add(oLinkPointArray, "")

Set oLinkPointArray(0) = oPoint2

Set oLinkPointArray(1) = oPoint3

Set oLinkArray(1) = oRoadwayLinks.Add(oLinkPointArray, "")

Set oLinkPointArray(0) = oPoint3

Set oLinkPointArray(1) = oPoint4

Set oLinkArray(2) = oRoadwayLinks.Add(oLinkPointArray, "")

Set oLinkPointArray(0) = oPoint4

Prog

ram

min

g C

orrid

or A

ssem

blie

s in

Aut

odes

k® C

ivil

3D®

21

Set oLinkPointArray(1) = oPoint1

Set oLinkArray(3) = oRoadwayLinks.Add(oLinkPointArray, "")

Dim oRoadwayShapes As AeccRoadwayShapes

Set oRoadwayShapes = oRwyState.Shapes

Dim oShape1 As AeccRoadwayShape

Set oShape1 = oRoadwayShapes.Add(oLinkArray, "")

End Sub

Prog

ram

min

g C

orrid

or A

ssem

blie

s in

Aut

odes

k® C

ivil

3D®

Programming Corridor Assemblies in Autodesk® Civil 3D®

22

AmazingLane Description The Amazing Lane subassembly is designed to demonstrate the subassembly API. This is an example and not designed to be used in production engineering applications.

The Amazing Lane is a basic lane sub assembly that demonstrates some of the things that you can do with subassemblies.

Attachment The attachment point is at the inside edge of the lane on the finished grade surface. The lane can be attached to either the left or right side.

Input Parameters

Parameter Description Type Default

Side True to insert the shape to the left of the attachment point; False to insert the shape to the right of the attachment point.

Left/Right Right

Width Width of the lane Double 12’/3m

Ending Width Optional final width of the subassembly based on start and end stations

Double 12’/3m

Depth Depth of the lane Double 150mm / 6”

StartingStation Optional starting station for taper Station

EndingStation Optional ending station for taper Station

Shape Code Shape code to apply to the subassembly String

Logical Names

Programming Corridor Assemblies in Autodesk® Civil 3D®

23

Parameter Description Type Status

Width Optional alignment to define width Alignment Optional

Behavior The subassembly will draw a basic lane that will conform to the width, depth and slope specified. Optionally, the lane can widen to a secondary alignment, and the outside edge of the lane can follow a secondary profile. The last option is to have the lane widen over a specified station range.

Layout Mode Operation In layout mode, the sub assembly will draw the lane using the parameters set in the Properties dialog.

Point, Link, and Shape Codes

Type Codes Description

Point1 CROWN Inside Top

Point2 EOP Outside Top

Point3 Inside Bottom

Point4 Outside Bottom

Link1 Top Top Link

Link2 Outside Link

Link3 Datum Bottom Link

Link4 Inside Link

Shape1 Pave Shape

Programming Corridor Assemblies in Autodesk® Civil 3D®

24

CorridorLabel Description The Corridor Label subassembly is designed to demonstrate the subassembly API. This is an example and not designed to be used in production engineering applications.

The Corridor Label subassembly is designed to label ground features on cross sections by adding additional corridor points to the model. It will label the location where alignments and optionally polylines intersect with the cross section.

Behavior The subassembly is designed to be added directly to the base point of the assembly. In the corridor model, it will search the drawing file left and right a user specified distance looking for alignments and polylines. When these are found, the point of intersection with the cross section is optionally projected to the surface. If they aren’t projected to the surface, an offset can be applied to the point to raise it above the centerline of the section. When the points are added, the alignment name or the layer name of polylines is used as point codes with L/R optionally added to the front of the code. In layout mode, a simple point will be added, with no code.

Attachment The attachment point of the subassembly is the base point of the assembly.

Input Parameters

Parameter Description Type Default

LeftSwathWidth Width to sample to the left Double 30m

RightSwathWidth Width to sample to the right Double 30m

ElevationOffset Vertical offset for the point Double 0m

UsePolylines True to search for polylines, False to ignore polylines

True/False True

AddLR True to Add L or R to point code True/False False

Logical Names

Alignment to Label

Offset Elevation

Left Swath Width Right Swath Width

Polyline labeled on

Alignment labeled with Offset

Programming Corridor Assemblies in Autodesk® Civil 3D®

25

Parameter Description Type Status

LabelOnDTM Optional surface to project the points to Surface Optional

Layout Mode Operation In layout mode, the subassembly draws a single point at the origin of the assembly

TopSoilStripping Description The Topsoil Stripping subassembly is designed to demonstrate the subassembly API. This is an example and not designed to be used in production engineering applications.

The Topsoil Stripping subassembly is used to calculate the quantity of top soil that must be removed for the roadway. This must be the last sub assembly that is attached to the assembly, and is typically placed after the daylight assembly. The subassembly can use an optional alignment to define an inner limit for the clearing (for example the edge of an existing shoulder). If this is not supplied, the centerline of the corridor will be used.

Attachment The attachment point should be placed on the outside point of the daylight sub assembly.

Input Parameters

Parameter Description Type Default

Side True to insert the shape to the left of the attachment point; False to insert the shape to the right of the attachment point.

Left/Right Right

TopSoilDepth Depth of the top stripping Double 150mm / 6”

LinkCode Link code to apply to the Datum line String

Logical Names

Parameter Description Type Status

EOES Edge of existing shoulder Alignment Optional

TopSurface Top of existing ground Surface Required

Behavior The subassembly will start at the daylight line, and follow the Top Surface in towards the centerline. If the optional alignment is used, the clearing will stop at that point, and drop down (nearly vertical) the TopSoilDepth, and move back to the daylight line, parallel to the top surface. If the section is in cut, the last section of the clearing line will follow the daylight link. If the section is in fill, the final link will be nearly vertical, and tie in with the top surface.

Layout Mode Operation In layout mode, the sub assembly will draw a box the depth of the stripping.

Clearing Depth

Existing Ground

Optional Alignment

Daylight Link

Programming Corridor Assemblies in Autodesk® Civil 3D®

27

Point, Link, and Shape Codes

Type Codes Description

P1 Inside Top

P2 Outside Top

P3 Inside Bottom

P4 Outside Bottom

Pm Interior Point Code Top

Pn Interior Point Code Bottom

L1 Top Link

L2 Bottom Link

L3 Inside Link

L4 Outside Link

S1 Shape

L1 L1 L1

L2 L2 L2

L3 L3

P2 P1

P3 P4

Pn Pn

S1

Pm Pm

Programming Corridor Assemblies in Autodesk® Civil 3D®