© 2011 Autodesk Understanding the Alignments and Profiles API in AutoCAD® Civil 3D® Isaac Rodriguez Sr. Software Engineer
Dec 25, 2015
© 2011 Autodesk
Understanding the Alignments and Profiles API in AutoCAD® Civil 3D®Isaac RodriguezSr. Software Engineer
© 2011 Autodesk
Autodesk University Session Feedback
Your feedback is very important to Autodesk
Attendees can complete session survey on their mobile device, PC or at a survey station
Each session survey completed will be entered for a daily drawing for a free AU 2012 pass.
You can help make AU 2012 better!
Complete the AU Conference Survey at a survey station and receive an AU 2011 T-Shirt
© 2011 Autodesk
About the Presenter
Isaac is a senior software engineer at Autodesk, and current software development lead of the AutoCAD® Civil 3D® API. Isaac has been with Autodesk for almost eleven years working in different products and technologies like AutoCAD Raster Design and AutoCAD Civil 3D. He has 20 years of software development experience including six years with Microsoft® .NET technologies.
Contact me through email: [email protected] me on Twitter: @CivilDevRead my blog: http://civilizeddevelopment.typepad.com
© 2011 Autodesk
About the Audience
Tell me a little bit about you.
• Software Development implementing Civil 3D applications• Civil Engineer writing automation scripts and internal tools• Are you using .NET?• Which .NET language you prefer?
© 2011 Autodesk
Class Summary
This class covers the basics of the Alignments and Profiles .NET API in Civil 3D. It also dives into the structural components of Alignment and Profile objects and their composition. Finally, the class demonstrates how Alignments and Profiles can be manipulated by changing parameters in their components.
© 2011 Autodesk
Learning Objectives
At the end of this class, you will be able to: Understand the structure of the Alignment and Profile objects Access to Alignment and Profile entities through the API Working with Alignment and Profile Entities according to their type Working with Alignment and Profile Entities and their constraints Complete the C3D API Challenge!!!
© 2011 Autodesk
Structure of Alignment and Profile Objects
© 2011 Autodesk
Alignments and Profiles
Two dimensional, linear objects Composed of other two dimensional, linear objects (Entities) Alignments represent different model features Profiles represent elevation points along an Alignment Structures are similar but representations are different
© 2011 Autodesk 9
Alignment Structure
Alignments contain Entities Entities contain Sub-Entities Sub-Entities different from Entities
Alignment
Entity
Sub-Entity
© 2011 Autodesk
Alignment Entities
Entities have a type Type identified by EntityType property (AlignmentEntityType enumeration) Object class does not identify entity type
Basic Entities contain 1 Sub-Entity Composite Entities contain 2 or more Sub-Entities Entities have constrains
© 2011 Autodesk
Basic Alignment Entities
Contain a single Sub-Entity Lines (Tangents), Arcs (Curves), and
Spirals
Entity Entity Class Entity TypeLine (Tangent) AlignmentLine LineArc (Curve) AlignmentArc CurveSpiral AlignmentSpiral Spiral
© 2011 Autodesk
Composite Alignment Entities
Entity Entity Class Entity TypeSpiral-Curve-Spiral AlignmentSCS SpiralCurveSpiralSpiral-Line-Spiral AlignmentSTS SpiralLineSpiralSpiral-Line AlignmentSTS SpiralLineLine-Spiral AlignmentSTS LineSpiralSpiral-Curve AlignmentSCS SpiralCurveCurve-Spiral AlignmentSCS CurveSpiralSpiral-Spiral-Curve-Spiral-Spiral AlignmentSSCSS SpiralSpiralCurveSpiralSpiralSpiral-Curve-Spiral-Curve-Spiral AlignmentSCSCS SpiralCurveSpiralCurveSpiralSpiral-Curve-Spiral-Spiral-Curve-Spiral AlignmentSCSSCS SpiralCurveSpiralSpiralCurveSpiralSpiral-Spiral (*) AlignmentSCS or AlignmentSTS SpiralSpiralSpiral-Spiral-Curve AlignmentSSCSS SpiralSpiralCurveCurve-Spiral-Spiral AlignmentSSCSS CurveSpiralSpiralCurve-Line-Curve AlignmentCTC CurveLineCurveCurve-Reverse Curve AlignmentCRC CurveReverseCurveCurve-Curve-Reverse Curve AlignmentCCRC CurveCurveReverseCurve
Entity type MultipleSegments not used nor supported(*) AlignmentSCS used if entity between two lines and AlignmentSTS used if entity between two curves
© 2011 Autodesk
Profile Structure
Profiles contain Entities Profile Entities are Simpler
Lines (Tangents) Arcs (Circles) Parabolas
Symmetric Asymmetric
Entities have constrains
Entity Entity Class Entity TypeTangent ProfileTangent TangentCircular ProfileCircular CircularParabola Symmetric ProfileParabolaSymmetric ParabolaSymmetricParabola Asymmetric ProfileParabolaAsymmetric ParabolaAsymmetric
© 2011 Autodesk
Accessing Alignment and Profile Entities
© 2011 Autodesk
Entities Collection < IEnumerable >
Accessed through Entities property Interface to access entities Implements IEnumerable for
AlignmentEntity Entities enumerated by ID ID depends on alignment creation
Time for some Code
© 2011 Autodesk
Entities Collection < EntityAtId() >
FirstEntity and LastEntity provided by collection
EntityBefore and EntityAfter provided by AlignmentEntity
EntityAtId() retrieves entity Suitable for sequential and direct
access
Some More Code
© 2011 Autodesk
Alignment Entities Collection < GetEntityByOrder() >
Zero-based index Less-than Count property value Raises exception with unconnected
entities Not suitable for enumeration Use for direct access
And More Code
© 2011 Autodesk
Working with Entities based on Type
© 2011 Autodesk
Alignment and Profile Entities by Type
Entities have a type Leads to complex logical code Prefer abstractions and polymorphism
© 2011 Autodesk
Entity Abstractions
Create you own entity wrappers Separate wrapper creation from processing Provide interface related to requirements Use virtual functions for specialized functionality (polymorphism)
© 2011 Autodesk
Function Objects (Functors)
Objects that work like functions Flexible and highly customizable Represent application processes
© 2011 Autodesk
Implementing ‘ExportAlignment’ Command
Function Object to export information Customizable order Customizable output target
Entity wrappers responsible for own information Logic to identify entity in Factory class
Let’s look at some code
© 2011 Autodesk
Working with Entities Constraints
© 2011 Autodesk
Constraint Types
Tangency Constraints Relation between entity and surrounding entities Common to all entities
Entity Definition Constraints Specific to an entity Represent how entity was defined (during creation)
© 2011 Autodesk
Tangency Constraints
Relation between entity and surrounding entities Common to all entities
Free / Fixed / Float on Previous / Float on Next Only editable in Alignments feature Not editable through the API They may affect the entire Alignment/Profile object
© 2011 Autodesk
Definition Level Constraints
Specific to an entity type Represent entity definition Indicate which parameters can be modified
© 2011 Autodesk
Recommendations Working with Constraints
Separate logical code from process Use “Strategy Pattern” for processing algorithms Evaluate constraints to decide strategy
© 2011 Autodesk 28
Strategy Pattern
Behavior defines interface Context provide point for
customization Concrete implementations of
interface Decide who customizes behavior
Let’s Look at some code
© 2011 Autodesk
Summary
Alignment and Profiles Linear objects composed by entities Different interfaces to access entities
Provide your own entity abstractions (wrappers) Implement process as Functors (Function Objects) Separate logical code from processing code Centralize logic (Decision methods / Factory methods) Provide customization of behavior (Strategy Pattern)
© 2011 Autodesk
Questions?
© 2011 Autodesk
C3D API Challenge
Reinforce the topics of this class Have fun with them Featured in Civilized Development Details in materials handout Submit entries prior December 31st 2011
© 2011 Autodesk
Autodesk, AutoCAD* [*if/when mentioned in the pertinent material, followed by an alphabetical list of all other trademarks mentioned in the material] are registered trademarks or trademarks of Autodesk, Inc., and/or its subsidiaries and/or affiliates in the USA and/or other countries. All other brand names, product names, or trademarks belong to their respective holders. Autodesk reserves the right to alter product and services offerings, and specifications and pricing at any time without notice, and is not responsible for typographical or graphical errors that may appear in this document. © 2011 Autodesk, Inc. All rights reserved.