71
Autodesk Confidential Info AutoCAD Civil 3D 2008 API Overview Partha Sarkar Developer Technical Services

Civil3d 2008 API

Embed Size (px)

Citation preview

Page 1: Civil3d 2008 API

Au

tod

esk

Co

nfid

en

tial I

nfo

AutoCAD Civil 3D 2008API Overview

Partha SarkarDeveloper Technical Services

Page 2: Civil3d 2008 API

© 2005 Autodesk 2

Au

tod

esk

Co

nfid

en

tial I

nfo

Autodesk may make statements regarding planned or future development efforts for our existing or new products and services in this document. These statements are not intended to be a promise or guarantee of future delivery of products, services or features but merely reflect our current plans, which may change.  Purchasing decisions should not be made based upon reliance on these statements.

Autodesk assumes no obligation to update these forward-looking statements to reflect events that occur or circumstances that exist or change after the date on which they were made.

Legal Disclaimer

Page 3: Civil3d 2008 API

© 2005 Autodesk 3

Au

tod

esk

Co

nfid

en

tial I

nfo

AgendaOverview of Civil 3D API

Points Surfaces Parcels Alignments Profiles Sections Custom Subassembly (VBA) Survey Piping C++ API (customDraw)

New API in Civil 3D 2008 (Beta)

.NET based Subassembly Enhancements to existing API

New!New!

Page 4: Civil3d 2008 API

© 2005 Autodesk 4

Au

tod

esk

Co

nfid

en

tial I

nfo

Referencing the Automation Type Libraries Before any coding begins, this ActiveX programming interface requires references to automation type libraries as follows:

AEC Base 5.5 Object Library (AecXBase) AEC Base 5.5 Application Library (AecXUiBase) Autodesk Civil Engineering Land 5.0 Object Library (AeccXLand) Autodesk Civil Engineering UI Land 5.0 Object Library

(AeccXUiLand)

Page 5: Civil3d 2008 API

© 2005 Autodesk 5

Au

tod

esk

Co

nfid

en

tial I

nfo

Referencing the Automation Type Libraries If referencing Roadway objects, then additional references must be added as follows:

Autodesk Civil Engineering Corridor 5.0 Object Library (AeccXRoadway)

Autodesk Civil Engineering UI Corridor 5.0 Object Library (AeccXUIRoadway)

Page 6: Civil3d 2008 API

© 2005 Autodesk 6

Au

tod

esk

Co

nfid

en

tial I

nfo

Getting the Application ObjectsFollowing is the recommended method (assuming VBA is used) to get an instance of AeccApplication:

Dim AeccApp as AeccApplication Set AeccApp = ThisDrawing.Application.GetInterfaceObject("AeccXUiLand.AeccApplication")

VB users can get the AeccApplication object through an instance of the AutoCAD.Application object:

Dim oTest As AutoCAD.AcadApplicationOn Error Resume NextoTest = GetObject(,"AutoCAD.Application")If Err.Number <> 0 Then   Err.Clear()   oTest = CreateObject("AutoCAD.Application")  If Err.Number <> 0 Then    Exit Sub  End IfEnd IfDim oAeccApp as AeccXUiLandLib.AeccApplication

oAeccApp = oTest.GetInterfaceObject("AeccXUiLand.AeccApplication")

Page 7: Civil3d 2008 API

© 2005 Autodesk 7

Au

tod

esk

Co

nfid

en

tial I

nfo

PointsAeccPoint Object in Civil 3D encapsulates a COGO point object, with associated information such as elevation, marker display styles, etc.

To create a new point with the given location use Add() method of AeccPoints Collection.

Dim point1 As Variant Dim oPoint As AeccPoint

point1 = ThisDrawing.Utility.GetPoint(, “Select a Location : ") Set oPoint = g_oAeccDb.Points.Add(point1)oPoint.Elevation = 100oPoint.RawDescription = "Test Description"

oPoint.Name = "Mytest Point"

Page 8: Civil3d 2008 API

© 2005 Autodesk 8

Au

tod

esk

Co

nfid

en

tial I

nfo

Points – Import / Export from External FilesTo import points into Civil 3D from ASCII (text) file or a Microsoft Access database (.mdb) file, use the ImportPoints() method.

Public Sub InsertPoints() getCivilObjects

Dim cPoints As AeccPoints Dim options As New AeccPointImportOptions options.ExpandCoordinateData = True

Set cPoints = g_oAeccDb.Points cPoints.ImportPoints "c:\Existing Ground Points - PENZD.txt", "PENZD (space delimited)", options

End Sub

Note -1. This method will fail if you don't specify a supported FileFormatName.

Note -2. When you add points using the ImportPoints method, it is possible that the point Numbers will conflict with those that already exist in the drawing. In such cases, the user is given an option to renumber the point numbers from the file, or to cancel the operation which will result with a Visual Basic error. An application that uses ImportPoints should take this into account.

Page 9: Civil3d 2008 API

© 2005 Autodesk 9

Au

tod

esk

Co

nfid

en

tial I

nfo

Points – Import / Export from External FilesThe second parameter of the ImportPoints and ExportPoints methods is a string that describes how the point values are stored in the file. The following table lists some commonly available file formats. Custom formats can be created by using the Point File Format dialog box.

Page 10: Civil3d 2008 API

© 2005 Autodesk 10

Au

tod

esk

Co

nfid

en

tial I

nfo

Points Adding to Point Group

' Add point 1 and point 2 to the point group.oPtGroup.QueryBuilder.IncludeNames = "point1," & oPoint2.Name

' Add point 3 to the point group by using its number.oPtGroup.QueryBuilder.IncludeNumbers = oPoint3.Number

' You can also use wildcards. The following would select all points with a ‘ name beginning with "pol".oPtGroup.QueryBuilder.IncludeNames = "pol*"

' Exclude those points with an alitude above 300.oPtGroup.QueryBuilder.ExcludeElevations = ">300"

' And include those points with identification numbers 100 through 200 ' inclusive, and point number 206.oPtGroup.QueryBuilder.IncludeNumbers = "100-200,206"

Page 11: Civil3d 2008 API

© 2005 Autodesk 11

Au

tod

esk

Co

nfid

en

tial I

nfo

Surfaces

Surfaces are basic building blocks in Autodesk Civil 3D. A surface is a three-dimensional geometric representation of the surface of an area of land, or, in the case of volume surfaces, is a difference or composite between two surface areas. Points or contours are usually a primary part of the original surface information and are supplemented with breaklines and boundaries. Breaklines are constraint lines, such as retaining walls, stream banks and beds, ridge lines, curbs, and other abrupt changes in the surface.

Page 12: Civil3d 2008 API

© 2005 Autodesk 12

Au

tod

esk

Co

nfid

en

tial I

nfo

SurfacesAddTinSurface() method creates a new TIN surface using the specified creation data.

Public Sub createSurfaceByImport() If getCivilObjects = True Then Dim oSurface As AeccSurface Dim oTinSurfaceData As New AeccTinCreationData Const sPointFile = "D:\C3D2008API\Points_PENZD.txt"

oTinSurfaceData.Description = "Existing Surface" oTinSurfaceData.Name = "adsk_EG" Dim oTinSurface As AeccTinSurface

Set oTinSurface = g_oAeccDb.Surfaces.AddTinSurface(oTinSurfaceData) oTinSurface.DefinitionProperties.UseAddPoint = True oTinSurface.PointFiles.Add (sPointFile) ' Setting a criteria to Exclude Points with an ' Elevation Less Than a value (here set to 100) oTinSurface.DefinitionProperties.ExcludeElevationsLessThan = True oTinSurface.DefinitionProperties.LowerElevation = 100 oTinSurface.Rebuild End IfEnd Sub

Page 13: Civil3d 2008 API

© 2005 Autodesk 13

Au

tod

esk

Co

nfid

en

tial I

nfo

Surfaces – Create From LandXML

Using AeccSurfaces:: ImportXML() Method we can add a LandXML surface data file to create a new Surface (AeccSurface) in Civil 3D.

Dim oSurface As AeccSurfaceDim sFileName As StringsFileName = “D:\My_Temp\EG.xml"Set oSurface = oAeccDocument.Surfaces.ImportXML(sFileName) Dim oTinSurface as AeccTinSurfaceIf (oSurface.Type = aecckTinSurface) Then Set oTinSurface = oSurfaceEnd If

Page 14: Civil3d 2008 API

© 2005 Autodesk 14

Au

tod

esk

Co

nfid

en

tial I

nfo

Surfaces – Adding DEM files / Contours / BreakLine etc

‘ Adding a DEM file oTinSurface.DEMFiles.Add("D:\Temp_Test\file1.dem")

' adding a contour to a surfaceDim oNewContour As AeccSurfaceContourSet oNewContour = oTinSurf.Contours.Add(oEntities, "Sample Contour", dWeedDist, dWeedAngle, dDist, dMidOrdDist)

' adding a Standard BreakLineThisDrawing.Utility.GetEntity Ent, Pt, "Select a polyline for breakline"Set SelObjs(0) = EntSet oBrkLn = oTinS.Breaklines.AddStandardBreakline(SelObjs, BrklnDesc, 1#)oTinS.Rebuild

Page 15: Civil3d 2008 API

© 2005 Autodesk 15

Au

tod

esk

Co

nfid

en

tial I

nfo

SurfacesUse AeccTinVolumeSurface to perform a volume calculation i.e. cut & fill quantities.

Dim oSurfaces As AeccSurfacesDim oTinVolSurfData As New AeccTinVolumeCreationDataSet oTinVolSurfData.BaseSurface = g_oAeccDb.Surfaces.Item(“EG")Set oTinVolSurfData.ComparisonSurface = g_oAeccDb.Surfaces.Item("FG")oTinVolSurfData.Name = "adsk_TinVol"Dim oTinVolSurface As AeccTinVolumeSurfaceSet oTinVolSurface = g_oAeccDb.Surfaces.AddTinVolumeSurface(oTinVolSurfData)Dim CutVol As Long, FillVol As Long, NetVol As LongCutVol = oTinVolSurface.Statistics.CutVolumeFillVol = oTinVolSurface.Statistics.FillVolumeNetVol = oTinVolSurface.Statistics.NetVolume

Page 16: Civil3d 2008 API

© 2005 Autodesk 16

Au

tod

esk

Co

nfid

en

tial I

nfo

SurfacesWe can create a 3dPolyline between two selected points on the surface along with a LWPolyline. Viewing them together in an Object Viewer will show the actual surface profile between the selected points. Use the SampleElevations

function to get the point array between two selected points on the surface. Dim oSurf As AeccSurface Set oSurf = g_oAeccDb.Surfaces.Item(0) If oSurf Is Nothing Then MsgBox "Error: no surface exists." End If Set oSurf = g_oAeccDoc.Surfaces.Item(0) oPoint1 = ThisDrawing.Utility.GetPoint(, "Select a point on the surface ") oPoint2 = ThisDrawing.Utility.GetPoint(oPoint1, "Select a point on the surface ") pointarray = oSurf.SampleElevations(oPoint1(0), oPoint1(1), oPoint2(0), oPoint2(1)) Set polyObj = ThisDrawing.ModelSpace.Add3DPoly(pointarray)

Page 17: Civil3d 2008 API

© 2005 Autodesk 17

Au

tod

esk

Co

nfid

en

tial I

nfo

ParcelsAeccParcel objects in Autodesk Civil 3D are typically used to represent real estate parcels, such as lots in a subdivision. Parcel objects can also represent other features with closed boundaries, such as bodies of water and soil regions.

Page 18: Civil3d 2008 API

© 2005 Autodesk 18

Au

tod

esk

Co

nfid

en

tial I

nfo

Sites

All sites in a document are held in the AeccDocument.Sites collection, an object of type AeccSites. The AeccSites.Add method will create a new empty site with the specified name.

' Create a new site.Dim oSites As AeccSitesSet oSites = oAeccDocument.SitesDim oSite As AeccSiteSet oSite = oSites.Add("Sample Site")

Page 19: Civil3d 2008 API

© 2005 Autodesk 19

Au

tod

esk

Co

nfid

en

tial I

nfo

ParcelsTo create a Parcel, we need to access an existing AeccSite object and next start creating AeccParcelSegment objects for each side of the parcel boundary. Use properties of AeccParcelSegment objects like AddLine, AddCurve, etc to define the physical outline of the parcel.

Set oSite = g_oAeccDb.Sites.Item(0)Const sParcelStyleName = "Adsk_ParcelStyle"Dim oParcelStyle As AeccParcelStyleConst sLbl = "adsk_ParcelLabelStyle"Dim oParcelLabelStyle As AeccLabelStyleSet oParcelStyle = g_oAeccDb.ParcelStyles(sParcelStyleName)Set oParcelLabelStyle =

g_oAeccDb.ParcelLabelStyles.AreaLabelStyles.Item(sLbl ) Dim oPSeg01 As AeccParcelSegment Dim oPSeg02 As AeccParcelSegmentSet oPSeg01 = oSite.ParcelSegments.AddLine(0, 0, 0, 200)Set oPSeg02 = oSite.ParcelSegments.AddCurve(0, 200, -0.5, 200, 200)

Page 20: Civil3d 2008 API

© 2005 Autodesk 20

Au

tod

esk

Co

nfid

en

tial I

nfo

Parcels - SettingsAeccSite site class has many essential properties which allows Set and Get these settings like - NextAutoCounterParcel , NextManualCounterParcel, NextAutoCounterParcelLine etc.

For Each oSite In g_oAeccDoc.Sites If oSite.Name = sSiteName Then GoTo SiteFound Next Set oSite = g_oAeccDoc.Sites.Add(sSiteName) oSite.NextAutoCounterParcel = 20 oSite.NextManualCounterParcel = 20 oSite.NextAutoCounterParcelCurve = 20 oSite.NextAutoCounterParcelLine = 20

Page 21: Civil3d 2008 API

© 2005 Autodesk 21

Au

tod

esk

Co

nfid

en

tial I

nfo

Parcels - StatisticsAeccParcelStatistics Object encapsulates statistical data about the parcel, such as area and perimeter.

'Check if parcel exists in the drawing Dim oParcel As AeccParcel If oSite.Parcels.Count = 0 Then MsgBox "No parcels found" Exit Sub Else Set oParcel = oSite.Parcels.Item(0) End If ' Display parcel statistics MsgBox "Parcel name : " & oParcel.Name & vbLf _ & "Area : " & Format(CStr(oParcel.Statistics.Area), "0.####") & vbLf

_ & "Perimeter : " & Format(CStr(oParcel.Statistics.Perimeter), "0.####")

Page 22: Civil3d 2008 API

© 2005 Autodesk 22

Au

tod

esk

Co

nfid

en

tial I

nfo

Alignments

Alignment objects can represent centerlines, lanes, shoulders, right-of ways, or construction baselines. Creating and defining the horizontal alignment is one of the first steps in roadway, railroad, or site design. You can draw the alignment geometry as a polyline and create the named alignment from that geometry, or create an alignment object using the Alignment Layout Tools. You can also make edits to alignments using grips, or the commands on the Alignment Layout Tools toolbar, while automatically maintaining tangency between the alignment components.

Page 23: Civil3d 2008 API

© 2005 Autodesk 23

Au

tod

esk

Co

nfid

en

tial I

nfo

AlignmentsWe create alignments as a combination of lines, curves, and spirals that are viewed as one object. Alignments can be stand-alone objects or the parent object of profiles, profile views, and cross sections. If we edit an alignment, the changes are automatically reflected in any related objects.

Dim oAlignment As AeccAlignmentSet oAlignment =

g_oAeccDb.Sites.Item("adsk_site1").Alignments.Add(strAlignName, "alignment", g_oAeccDb.AlignmentStyles.Item("Design Style"), g_oAeccDb.AlignmentLabelStyleSets.Item("All Labels"))

Dim fstLine As AeccAlignmentTangentSet fstLine = oAlignment.Entities.AddFixedLine1(pt1, pt2)

Other methods...

AddFreeCurve1()AddFloatingCurve1()AddFixedSpiral1()

Page 24: Civil3d 2008 API

© 2005 Autodesk 24

Au

tod

esk

Co

nfid

en

tial I

nfo

Alignments

Sub AlignmentWithAddFreeSTSGroup1() Dim Curve1 As AeccAlignmentArc Dim Curve2 As AeccAlignmentArc ' Create the 1st Curve Set Curve1 = oAlignment.Entities.AddFixedCurve1(0,

pt1, pt2, pt3) ' Create the 2nd Curve Set Curve2 = oAlignment.Entities.AddFixedCurve1(0,

pt1, pt2, pt3) ' Add STS (Spiral-Line-Spiral) oAlignment.Entities.AddFreeSTSGroup1 Curve1.Id,

Curve2.Id, 30, 25, aeccAlignmentSpiralClothoid, True End Sub

Page 25: Civil3d 2008 API

© 2005 Autodesk 25

Au

tod

esk

Co

nfid

en

tial I

nfo

Alignment - Create From Offset of Another Alignment

Alignments can also be created based on the layout of existing alignments. The AeccAlignment.Offset method will create a new alignment with a constant offset and add it to the same parent site as the original alignment.

' Add an offset alignment 10.0 units to the left of the original.oAlignment.Offset -10.0

Page 26: Civil3d 2008 API

© 2005 Autodesk 26

Au

tod

esk

Co

nfid

en

tial I

nfo

Alignment - Add Station Equation

Dim oAlign As AeccAlignment Dim oStationEquation As AeccStationEquation ThisDrawing.Utility.GetEntity obj, pt, "pick alignment" If TypeOf obj Is AeccAlignment Then Set oAlign = obj End If Set oStationEquation = oAlign.StationEquations.Add(700, 0, 1100,

aeccIncreasing)

Page 27: Civil3d 2008 API

© 2005 Autodesk 27

Au

tod

esk

Co

nfid

en

tial I

nfo

Alignment - Add Design Speeds

If TypeOf obj Is AeccAlignment Then Set oAlign = obj ' Starting at station 0 + 00.00 Set oDesignSpeed = oAlign.DesignSpeeds.Add(0#) oDesignSpeed.Value = 40 oDesignSpeed.Comment = "Straightaway" ' Starting at station 1 + 00.00 Set oDesignSpeed = oAlign.DesignSpeeds.Add(100#) oDesignSpeed.Value = 60 oDesignSpeed.Comment = "Straight Road" ' Starting at station 6 + 0.00 to the end. Set oDesignSpeed = oAlign.DesignSpeeds.Add(600#) oDesignSpeed.Value = 45 oDesignSpeed.Comment = "Curves start here" ZoomExtents MsgBox "Design Speeds are Added to Alignment !"End If

Page 28: Civil3d 2008 API

© 2005 Autodesk 28

Au

tod

esk

Co

nfid

en

tial I

nfo

Siteless Alignments

AlignmentsSiteless

Alignments can now be created outside of sites. The AeccDocument object contains a new property called AlignmentsSiteless which contains a collection of alignments.

' Get the collection of all siteless alignments.Dim oAlignments as AeccAlignmentsSet oAlignments = oDocument.AlignmentsSiteless

New!New!

Page 29: Civil3d 2008 API

© 2005 Autodesk 29

Au

tod

esk

Co

nfid

en

tial I

nfo

Siteless Alignments – What is it ?

If Alignments are placed on a site, they will interact with other objects on the site in two ways :

If an alignment exists on a site with parcels, the alignment will subdivide any parcels it crosses over.

If one or more alignments on a site form a closed region, a parcel will be created from the region.

If you do not want an alignment to interact with other objects use this new object - AlignmentsSiteless while creating an Alignment.

Page 30: Civil3d 2008 API

© 2005 Autodesk 30

Au

tod

esk

Co

nfid

en

tial I

nfo

Profiles

There are two distinct Civil 3D entities when using Profiles, the Profile itself and the Profile View. The Profile is the actual section cut through a surface or the proposed design profile and has it's associated style and label style. The Profile View is the data surrounding the display of the profile line - grids, axes, labels and desired band styles, which contain data on any side of the grid, horizontal / vertical geometry data etc.

Page 31: Civil3d 2008 API

© 2005 Autodesk 31

Au

tod

esk

Co

nfid

en

tial I

nfo

Profiles

'Create a profile named "Adsk Sample Profile"Dim oProfile As AeccProfileSet oProfile = oProfiles.AddFromSurface(sProfileName, aeccExistingGround, oProfileStyle, _oSurf.Name, oAlignment.StartingStation, oAlignment.EndingStation, "0") If oProfile Is Nothing Then MsgBox "Error creating an existing ground profile" Exit Sub End If 'Set properties to the newly created profileoProfile.Style.LineDisplayStyle2d.color = acRedoProfile.Style.PVIPointDisplayStyle2d.color = acGreen

Page 32: Civil3d 2008 API

© 2005 Autodesk 32

Au

tod

esk

Co

nfid

en

tial I

nfo

Profiles

Creating a Profile View –

'Set parameters that are need to create a profile view

Dim oProfileView As AeccProfileView . . 'Get access to existing AeccProfileViewBandStyleSet in the drawing

Dim oPVBandStyleSet As AeccProfileViewBandStyleSet Set oPVBandStyleSet = g_oAeccDoc.ProfileViewBandStyleSets.Item(0) 'Create a Profile view by adding a AeccProfileView object to the ProfileViews collection

If oProfileView Is Nothing Then Set oProfileView = oAlignment.ProfileViews.Add(sPViewName, _ sLayerName, originPt, oPVStyle, oPVBandStyleSet) End If

Page 33: Civil3d 2008 API

© 2005 Autodesk 33

Au

tod

esk

Co

nfid

en

tial I

nfo

Profiles Creating a Profile By Layout –

'Add a new profile to the AeccAlignment object Dim oProfl As AeccProfile Set oProfl = oAlignment.Profiles.Add("FGProfile", aeccFinishedGround, "Finished Ground", oAlignment.StartingStation, oAlignment.EndingStation, "0") Dim oPVIs As AeccProfilePVIs Set oPVIs = oProfl.PVIs

'Add PVIs to the profile oPVIs.Add 0 + 2.51, 286.7, aeccTangent oPVIs.Add 0 + 23.14, 284.09, aeccTangent oPVIs.Add 0 + 37.021, 288.23, aeccTangent oPVIs.Add 0 + 57.486, 288.29, aeccTangent oPVIs.Add 0 + 88.251, 291.86, aeccTangent oPVIs.Add 0 + 91.892, 289.3, aeccTangent

Page 34: Civil3d 2008 API

© 2005 Autodesk 34

Au

tod

esk

Co

nfid

en

tial I

nfo

Sections

Typically, sections are cut across horizontal (plan) alignments at a specified station interval using specified swath widths. These sections are then plotted, individually for a station, or as a group for a range of stations.

Page 35: Civil3d 2008 API

© 2005 Autodesk 35

Au

tod

esk

Co

nfid

en

tial I

nfo

Sections

Creating Sample Lines –

' Create a sample line group Dim oSampleLineGroup As AeccSampleLineGroup Set oSampleLineGroup = oAlignment.SampleLineGroups.Add(sSLGName, sLayerName, oGPStyle, oSLStyle, oSLabelStyle) 'Set parameters for sample line Dim oSampleLine As AeccSampleLine Const sKey = "Adsk Sample Line" Dim dStationID As Double dStationID = 0 + 51.963 Dim dLeftSwathLenghth As Double dLeftSwathLenghth = 30# 'Create sample line by Station If oSampleLine Is Nothing Then Set oSampleLine = oSampleLineGroup.SampleLines.AddByStation(sKey, dStationID, dLeftSwathLenghth, dRightSwathLenghth) End If

Page 36: Civil3d 2008 API

© 2005 Autodesk 36

Au

tod

esk

Co

nfid

en

tial I

nfo

Sections

Creating Section View –

'Set parameters for section view Const sSectionView = "Adsk Section View" Const sLayer = "Adsk Layer" Dim originPt(0 To 2) As Double ' Select the Origin Point 'Set section view style for the section view Dim oSVStyle As AeccSectionViewStyle 'Set section view band style set for the section view Dim oSVBStyleSet As AeccSectionViewBandStyleSet 'Create section view Dim oSectionView As AeccSectionView If oSectionView Is Nothing Then Set oSectionView = oSampleLine.SectionViews.Add(sSectionView, sLayer, originPt, oSVStyle, oSVBStyleSet) End If

Page 37: Civil3d 2008 API

© 2005 Autodesk 37

Au

tod

esk

Co

nfid

en

tial I

nfo

Corridors & Subassemblies

A corridor model builds on and uses various Autodesk Civil 3D objects and data, including subassemblies, assemblies, alignments, surfaces, and profiles. Corridor objects are created a baseline (alignments) by placing a 2D section (assembly) at incremental locations and by creating matching slopes that reach a surface model at each incremental location

Page 38: Civil3d 2008 API

© 2005 Autodesk 38

Au

tod

esk

Co

nfid

en

tial I

nfo

Creating Custom Subassemblies

Subassemblies are the basic building blocks of a corridor design. A subassembly is an AutoCAD drawing object (AECCSubassembly) that defines the geometry of a component used in a corridor section. Through the tool palette and tool catalogues, Autodesk Civil 3D provides preconfigured subassemblies for components such as carriageways, kerbs, batter slopes and ditches. These subassemblies are defined by a set of points, links, and optionally closed areas referred to as shapes. The subassemblies provided with Autodesk Civil 3D have built-in intelligent behavior.

Page 39: Civil3d 2008 API

© 2005 Autodesk 39

Au

tod

esk

Co

nfid

en

tial I

nfo

Creating Custom Subassemblies

You can develop Visual Basic for Applications (VBA) scripts to define custom subassemblies that provide specific behavior. The actions that occur when a subassembly is used in an assembly, and when subassemblies are processed during corridor creation, are specified through VBA scripts. The Autodesk Civil 3D COM API includes objects, methods, and properties specifically designed to provide an interface to assemblies and corridor models for subassembly VBA scripts.

Page 40: Civil3d 2008 API

© 2005 Autodesk 40

Au

tod

esk

Co

nfid

en

tial I

nfo

Creating Custom SubassembliesVBA Structure for Subassemblies -

Each subassembly should have a separate module in the VBA library, where the module name matches the subassembly name. For example, the subassembly “adskRailType01” is executed by the subroutines in a module that is also called “adskRailType01”.

There are several standard subroutines that must be implemented for each subassembly within its module. These subroutines are described below for a sample subassembly called adskRailType01.

Page 41: Civil3d 2008 API

© 2005 Autodesk 41

Au

tod

esk

Co

nfid

en

tial I

nfo

Creating Custom SubassembliesVBA Structure for Subassemblies -

Page 42: Civil3d 2008 API

© 2005 Autodesk 42

Au

tod

esk

Co

nfid

en

tial I

nfo

Creating a Subassembly Tool CatalogYou can create an Autodesk tool catalog to organize groups of customized subassemblies and make them available to Autodesk Civil 3D users. Autodesk tool catalogs are defined using xml-formatted files with an .atc (Autodesk Tool Catalog) extension. You also need to create a catalog registry file since catalogs must be registered in the Windows registry. Some items within the .atc and registry files must contain unique identifiers known as GUIDs (Global Unique Identifiers).

Page 43: Civil3d 2008 API

© 2005 Autodesk 43

Au

tod

esk

Co

nfid

en

tial I

nfo

Creating a Subassembly Tool CatalogSample Tool Catalog ATC File –

1. <Catalog>2. <ItemID idValue="{410D0B43-19B3-402F-AB41-05A6E174AA3F}"/>3. <Properties>4. <ItemName>Corridor Modeling Catalogs (Imperial)</ItemName>5. <Images>6. <Image cx="93" cy="123" src=".\Images\AeccCorridorModel.png"/>7. </Images>8. <AccessRight>0</AccessRight>9. <Description>This catalog contains Subassembly tools for corridor modeling with Imperial units.</Description>

<Refer Civil 3D Help File for the complete Sample>

Page 44: Civil3d 2008 API

© 2005 Autodesk 44

Au

tod

esk

Co

nfid

en

tial I

nfo

Corridors

New Methods in Civil 3D 2008 :

AeccBaseline.AddStation AeccBaseline.DeleteStation AeccCorridors.Add AeccCorridor.AddBaseline

New!New!

Page 45: Civil3d 2008 API

© 2005 Autodesk 45

Au

tod

esk

Co

nfid

en

tial I

nfo

Survey

Function GetSurveyObjects()' Function to set up the Civil 3D Survey application, document and database object Dim oApp As AcadApplication Set oApp = ThisDrawing.Application Dim sAppName As String sAppName = "AeccXUiSurvey.AeccSurveyApplication" Set g_oCivilSurveyApp = oApp.GetInterfaceObject(sAppName) If g_oCivilSurveyApp Is Nothing Then MsgBox "Error creating " & sAppName & ", exit." GetCivilObjects = False Exit Function End If Set g_oAeccSurveyDoc = g_oCivilSurveyApp.ActiveDocumentEnd Function

Page 46: Civil3d 2008 API

© 2005 Autodesk 46

Au

tod

esk

Co

nfid

en

tial I

nfo

Survey

‘ Create a Survey Project Set oSurveyProjs = g_oAeccSurveyDoc.Projects If oSurveyProjs.Count = 0 Then Set oSurveyProj = oSurveyProjs.Create("Survey 1") Else

'Create a Survey network

Set oNetworks = oSurveyProj.Networks If oNetworks.Count = 0 Then Set oNetwork = oSurveyProj.Networks.Create("Survey Network 1") Else

Page 47: Civil3d 2008 API

© 2005 Autodesk 47

Au

tod

esk

Co

nfid

en

tial I

nfo

Survey – Create Figures / Lineworks

‘ Add Figure ObjectsDim oFigure As AeccSurveyFigureSet oFigure = oSurveyProject.Figures.Create("Figure_01")

' Draw a line to the location of survey point 3001.Dim oPoint1 As AeccSurveyPointSet oPoint1 = oSurveyProject.GetPointByNumber(3001)oFigure.AddLineByPoint oPoint1.Easting, oPoint1.Northing, 3001

' Draw a line 30 meters long at 10 degrees from the major axis.oFigure.AddLineByAzimuthDistance 0.17453, 30

Page 48: Civil3d 2008 API

© 2005 Autodesk 48

Au

tod

esk

Co

nfid

en

tial I

nfo

Survey – Add Figures to DrawingAdding lines and arcs to a figure changes the survey database but does not automatically change the drawing. After adding elements to the figure use AeccSurveyFigure.AddToDrawing method to make them visible and editable through the user interface.

'Save figure and write it to drawing oFig.Save oFig.AddToDrawing ThisDrawing.Application.ZoomExtents

Page 49: Civil3d 2008 API

© 2005 Autodesk 49

Au

tod

esk

Co

nfid

en

tial I

nfo

Pipe Network

A pipe network object manages a collection of pipe objects and structure objects that are associated with each other to represent a pipe system.Typically, the pipes and structures are connected to each other, forming a single pipe run or pipe network. The pipe and structure objects in a pipe network are typically associated with an alignment, and/or a surface(s), which provide them with station offset and elevation data.

The pipe network object is used as the container object to associate pipes and structures that are part of the same pipe run or pipe network. A pipe network typically contains pipe objects and structure objects.

Page 50: Civil3d 2008 API

© 2005 Autodesk 50

Au

tod

esk

Co

nfid

en

tial I

nfo

Pipe

A pipe object is a drawing shape that represents straight or curved pipes used in utility networks, such as sewer and irrigation systems. In a drawing, the three-dimensional pipe shape is defined by: 1) the two-dimensional Part Shape (circular, elliptical, egg-shaped, or rectangular) of the pipe part that is selected from the part catalog; and 2) by specifying a linear path (for straight piped) or a curved path (for curved piped). Object names for pipes are not displayed in the Prospector tree. They are, however, displayed in the Prospector list view when you click Pipes under a pipe network in the Prospector tree.

Page 51: Civil3d 2008 API

© 2005 Autodesk 51

Au

tod

esk

Co

nfid

en

tial I

nfo

Structure

A structure object is a drawing shape that is used to represent items, such as manholes, catch basins, and headwalls, used in utility networks. Structure shapes are inherently more complex than pipe shapes. In a drawing, the three-dimensional structure shape is defined by the definition of the structure part that is selected from the part catalog. Like pipes, object names for structures are not displayed in the Prospector tree. They are, however, displayed in the Prospector list view when you click Structures under a pipe network in the Prospector tree.

Page 52: Civil3d 2008 API

© 2005 Autodesk 52

Au

tod

esk

Co

nfid

en

tial I

nfo

Getting the Pipe Application ObjectsFollowing is the recommended method (assuming VBA is used) to get an instance of AeccPipeApplication:

Dim AeccPipeApp as AeccPipeApplication AeccPipeApplication Set AeccPipeApp = ThisDrawing.Application.GetInterfaceObject("AeccXUiPipe.AeccPipeApplication")

VB users can get the AeccPipeApplication object through an instance of the AutoCAD.Application object:

Dim oTest As AutoCAD.AcadApplicationOn Error Resume NextoTest = GetObject(,"AutoCAD.Application")If Err.Number <> 0 Then   Err.Clear()   oTest = CreateObject("AutoCAD.Application")  If Err.Number <> 0 Then    Exit Sub  End IfEnd IfDim oAeccPipeApp as AeccXUiPipe.AeccPipeApplication

oAeccApp = oTest.GetInterfaceObject("AeccXUiPipe.AeccApplication")

Page 53: Civil3d 2008 API

© 2005 Autodesk 53

Au

tod

esk

Co

nfid

en

tial I

nfo

Create Pipe NetworkTo create Network, you should get the networks through AeccPipeDocument firstly, then use add method to create it or use Item method to return it by inputting the name

Dim oNetworks As AeccPipeNetworks Dim oNetwork As AeccPipeNetwork Set oNetworks = g_oAeccPipeDoc.PipeNetworks Set oNetwork = Nothing Set oNetwork = oNetworks.Item("SampleNetwork") If oNetwork Is Nothing Then Set oNetwork = oNetworks.Add("SampleNetwork") End If

' set the reference alignment and surface Dim oAlign As AeccAlignment Dim oSurface As AeccSurface Set oAlign =

g_oAeccPipeDoc.Sites.Item(0).Alignments.Item("ROAD1") Set oSurface = g_oAeccPipeDoc.Surfaces.Item("EG") oNetwork.ReferenceAlignment = oAlign oNetwork.ReferenceSurface = oSurface

Page 54: Civil3d 2008 API

© 2005 Autodesk 54

Au

tod

esk

Co

nfid

en

tial I

nfo

Creating Pipe and StructureAfter we get or create the network object, we can create pipe or structure object, before we do this we should return the PartFamilyGuid and PartSizeFilter to prepare for the creation. Just like the following code:

Dim oAeccPipeSettingRoot As AeccPipeSettingsRoot Set oAeccPipeSettingRoot = g_oAeccPipeDb.Settings Dim oAeccPartlists As AeccPartLists Dim oAeccPartlist As AeccPartList Set oAeccPartlists = oAeccPipeSettingRoot.PartLists Set oAeccPartlist = oAeccPartlists.Item(0) Dim oPartFamily As AeccPartFamily Dim oPipeSizeFilters As AeccPartSizeFilters Dim oPipeSizeFilter As AeccPartSizeFilter Dim sPipeGuid As String For Each oPartFamily In oAeccPartlist If oPartFamily.Domain = aeccDomPipe Then If oPartFamily.Name = "Concrete Pipe" Then sPipeGuid = oPartFamily.GUID Set oPipeSizeFilter = oPartFamily.SizeFilters.Item(1) Exit For End If End If Next

Page 55: Civil3d 2008 API

© 2005 Autodesk 55

Au

tod

esk

Co

nfid

en

tial I

nfo

Create Pipe and StructureAdd a new structure to the network: Dim oStructure As AeccStructure

Set oStructure = oNetwork.Structures.Add(sStructGuid, oStructSizeFilter, pt0, 1) ‘set the style Set oStructure.Style = oStructureStyle

Add a new Pipe to the network:

Dim oPipe As AeccPipe Set oPipe = oNetwork.Pipes.Add(sPipeGuid, oPipeSizeFilter, pt0, pt1) Set oPipe.Style = oPipeStyle 'connect the pipe to the structure oPipe.ConnectToStructure aeccPipeStart, oStructure

Page 56: Civil3d 2008 API

© 2005 Autodesk 56

Au

tod

esk

Co

nfid

en

tial I

nfo

Pipe and Structure InformationGo through the current drawing to print the main properties of the pipe or structure object information:

Sub outputPipeInfo() Dim obj As AcadObject Dim oPipe As AeccPipe Dim oStructure As AeccStructure For Each obj In ThisDrawing.ModelSpace If TypeOf obj Is AeccPipe Then Set oPipe = obj ThisDrawing.Utility.Prompt (vbCrLf & "pipe's name:" & oPipe.Name) ThisDrawing.Utility.Prompt (vbCrLf & "Description:" & oPipe.Description) ThisDrawing.Utility.Prompt (vbCrLf & "Start point:(" & oPipe.StartPoint.X & "," & oPipe.StartPoint.Y & "," & oPipe.StartPoint.Z & ")") ThisDrawing.Utility.Prompt (vbCrLf & "End point:(" & oPipe.EndPoint.X & "," & oPipe.EndPoint.Y & "," & oPipe.EndPoint.Z & ")") Dim dSlope As Double dSlope = (oPipe.EndPoint.Z - oPipe.StartPoint.Z) / oPipe.Length2D ThisDrawing.Utility.Prompt (vbCrLf & "Slope :" & dSlope & vbCrLf) ElseIf TypeOf obj Is AeccStructure Then Set oStructure = obj ThisDrawing.Utility.Prompt (vbCrLf & "Structure name:" & oStructure.Name) ThisDrawing.Utility.Prompt (vbCrLf & "Description:" & oStructure.Description) ThisDrawing.Utility.Prompt (vbCrLf & "Position:(" & oStructure.Position.X & "," & oStructure.Position.Y & "," & oStructure.Position.Z & ")" & vbCrLf) End If Next

End Sub

Page 57: Civil3d 2008 API

© 2005 Autodesk 57

Au

tod

esk

Co

nfid

en

tial I

nfo

Pipe and Structure Styles

New Objects in Civil 3D 2008 :

AeccPipeNetworkLabelStyles AeccPipeLabelStyles AeccStructureLabelStyles

New!New!

Page 58: Civil3d 2008 API

© 2005 Autodesk 58

Au

tod

esk

Co

nfid

en

tial I

nfo

Custom Draw API

A C++ API used to enhance / supplant existing graphics for customized display

Used in Object ARX context

No proxy objects / no object enablers involved

CustomDraw Sample available at – <AutoCAD Civil 3D 2008 Installation Folder>\Sample\Civil 3D API\VC++\CustomDraw

Page 59: Civil3d 2008 API

© 2005 Autodesk 59

Au

tod

esk

Co

nfid

en

tial I

nfo

Custom Draw APIHow it works -

One or more user-implemented callback functions are registered when application is initialized, e.g. AeccCustomDraw.setAlignmentDraw(AlignmentCallbackFunction)

During object draw, the callback function is called with an interface pointer for the object as well as an anonymous block

bool AlignmentCallbackFunction(const AeccDisplayOrientation &viewMode, IAeccAlignment *pAlign, IAcadBlock *pAnonymousBlock ){////}Return true, if you want Civil 3D to draw the block, false otherwise

Using the object you calculate the graphics to draw an add them to the anonymous block (instead of Modelspace)

Block is returned to the object, and added to the graphics stream

New graphics are part of the object for the display

Page 60: Civil3d 2008 API

© 2005 Autodesk 60

Au

tod

esk

Co

nfid

en

tial I

nfo

.NET Subassemblies The default subassemblies included with Civil 3D 2008 are now created using .NET framework.

New!New!

Page 61: Civil3d 2008 API

© 2005 Autodesk 61

Au

tod

esk

Co

nfid

en

tial I

nfo

.NET Subassemblies To maintain backward compatibility, VBA

subassemblies are also supported in Civil 3D 2008. Civil 3D 2008 includes a Utility to convert VBA

Subassemblies to .NET

New!New!

Page 62: Civil3d 2008 API

© 2005 Autodesk 62

Au

tod

esk

Co

nfid

en

tial I

nfo

Designing Subassemblies (.NET)

Detailed information about these requirements of designing custom subassemblies are available in Civil 3D 2008 Developer’s Guide topic – “Designing Custom Subassemblies”.

Page 63: Civil3d 2008 API

© 2005 Autodesk 63

Au

tod

esk

Co

nfid

en

tial I

nfo

Creating Subassemblies Help FilesYou can provide detailed construction and behavior information of Custom Subassembly in a Help file. The same help file can be displayed in AutoCAD Civil 3D using any of the following methods:

From a Tool Palette - Right-click a subassembly in a tool palette, then click Help.

From a Tool Catalog - Right-click a subassembly in a tool catalog, then click Help.

From the Subassembly Properties dialog box Parameters tab - Right-click a subassembly in the Prospector tree, then click Properties Parameters tab Subassembly Help.

You can use any type of document file (.dwf, .doc, .pdf, .txt, .chm, .hlp) to create the subassembly help file. For more information, see Creating Customized Help in the AutoCAD Developer Help.

Page 64: Civil3d 2008 API

© 2005 Autodesk 64

Au

tod

esk

Co

nfid

en

tial I

nfo

Structure of Subassembly (.NET)

The Subassembly Template (SATemplate.vb)

The Corridor State Object

Support Files (CodeSpecific.vb, Utility.vb)

Page 65: Civil3d 2008 API

© 2005 Autodesk 65

Au

tod

esk

Co

nfid

en

tial I

nfo

Subassembly Template (SATemplate.vb)

All custom subassemblies are defined as classes that inherit from the SATemplate class. SATemplate provides four methods which you can override in your own class to provide functionality of your subassembly.

New!New!

Page 66: Civil3d 2008 API

© 2005 Autodesk 66

Au

tod

esk

Co

nfid

en

tial I

nfo

Corridor State Object

The CorridorState object is the primary interface between the custom subassembly and the collection of points, links, and shapes of the current assembly which the subassembly is to connect to.

The CorridorState methods provide useful calculation functions for corridor design. These include the following:

Page 67: Civil3d 2008 API

© 2005 Autodesk 67

Au

tod

esk

Co

nfid

en

tial I

nfo

Support Files (CodeSpecific.vb, Utility.vb)

You can also use the two support files CodeSpecific.vb and Utility.vb in your subassembly.

CodeSpecific.vb provides the CodeType and AllCodes structures and the global variable Code - an instance of an AllCodes structure with all code information filled.

Utility.vb provides a series of shared helper functions for error handling, computing subassembly geometry, attaching code strings, and other tasks. For example, to report a “parameter not found” error to the Civil event viewer, use the following line:

Utilities.RecordError(corridorState, CorridorError.ParameterNotFound, "Edge Offset", "BasicLaneTransition")

Page 68: Civil3d 2008 API

© 2005 Autodesk 68

Au

tod

esk

Co

nfid

en

tial I

nfo

Sample VB.NET Subassembly

Imports System.MathImports Autodesk.AutoCAD.DatabaseServicesImports Autodesk.Civil.CorridorImports Autodesk.CivilImports Autodesk.Civil.AlignmentImports Autodesk.Civil.ProfileImports Shape = Autodesk.Civil.Corridor.ShapeImports DBTransactionManager = Autodesk.AutoCAD.DatabaseServices.TransactionManager

.NET source code of subassemblies available at - C:\Documents and Settings\All Users\Application Data\Autodesk\C3D 2008\enu\Sample\Civil 3D API\C3DstockSubAssemblies

New!New!

Page 69: Civil3d 2008 API

© 2005 Autodesk 69

Au

tod

esk

Co

nfid

en

tial I

nfo

Custom Subassemblies - Installation1. Copy the compiled subassembly .dll library to its destination directory. By

default, libraries are located in C:\Program Files\Autodesk Civil 3D 2008\Data\Models.

2. Copy the tool catalog .atc files to its destination directory. The tool catalog files are normally located in the C:\Documents and Settings\All Users\Application Data\Autodesk\C3D 2007\enu\Tool Catalogs directory.

3. Copy optional files such as the image file representing the subassemblies or the help file to their destination directory.

4. Copy the catalog cover page .html file to its destination. Usually this is the same location as the .atc file, although it can be any directory as long as the .atc file has the correct relative path information.

5. Register the tool catalog using a registry (.reg) file. This .reg file must have the correct paths to the .atc file and the catalog image file from steps 2) and 3).

Page 70: Civil3d 2008 API

© 2005 Autodesk 70

Au

tod

esk

Co

nfid

en

tial I

nfo

Developer Resources

Civil 3D API Help file

Code Samples provided with Product installation at - C:\Program Files\Autodesk Civil 3D 2008\Sample\Civil 3D API

ADN site & Devnotes

Civil 3D site www.autodesk.com/civil3d

Page 71: Civil3d 2008 API

© 2005 Autodesk 71

Au

tod

esk

Co

nfid

en

tial I

nfo

Thank You