800 likes | 1.95k Views
Introduction to Autodesk® Inventor® API and Assemblies. Wayne Brill API Consultant - Autodesk. Image courtesy of Engineering Center LTD, Russia. About the Presenter. Wayne Brill Developer Technical Services.
E N D
Introduction to Autodesk® Inventor® API and Assemblies Wayne Brill API Consultant - Autodesk Image courtesy of Engineering Center LTD, Russia
About the Presenter Wayne Brill Developer Technical Services Wayne has been a member of Autodesk Developer Technical services supporting ADN (Autodesk Developer Network) for nine years. Currently, Wayne provides API support for Autodesk Inventor®, AutoCAD, AutoCAD® Mechanical, AutoCAD OEM, and RealDWG™.
Goals Show you how to get started with the Inventor API (Application Programming Interface) Help you understand how the API can make you and your colleagues more productive with Inventor Help you gain some expertise with the Inventor API for assemblies
Areas of focus Introduction to the Inventor API Utility API objects API for Assemblies Introduction to B-Rep
Visual Basic C++ Other... .Net C# VB.Net Other... Inventor COM API Inventor COM • The API is exposed through a COM Automation interface.
Inventor Applications Add-In Client App Inventor Application Client App Add-In VBA Apprentice Inventor Data
Inventor API Classes/Objects • Functionality is exposed as classes/objects • Object corresponds to something in Inventor • Object may have methods, properties, and events. • Top object in the hierarchy is the Application object.
Get to an object using the hierarchy Application AssemblyDocument AssemblyComponentDefinition ComponentOccurrences WorkPlanes
COM API Utilities • Tools available to help in understanding the object model. • Object Model Chart - http://www.autodesk.com/developinventor • Object Browser • VBA Debugger
Demo Access API using VB.NET Create a VB.NET application, connect to an Inventor Session. Get the name of the active document, run a command, change an assembly setting
Entity Selection - SelectSet • Contains entities currently selected by the end-user • Object first then action behavior • Useful for debugging and simple macros. • Edit the contents of the select set by adding additional entities, removing specified entities, and clearing the entire select set
Units of Measure • Inventor has internal units • Length: Centimeters • Angle: Radians • Time: Second • Mass: Kilogram • Units in Document Settings are converted to / from internal units • The UnitsOfMeasure object provides similar functionality in API. • Provides functions to help with unit handling
Parameter Objects • Values are stored using internal units • Support for changing the type of the parameter • Create Parameter Groups • DiaabledActionTypes- Prohibit deletion of user parameters
Assembly API Overview • API supports most of the assembly functionality. • Placing & creating components. • Editing components • Patterns • Constraints • Work features • Parameters • iMates • Sketches • Features • Representations • iAssemblies • BOM • AssemblyDocument is the top level object for Assemblies
AssemblyDocument • AssemblyDocument Properties • references to ipt files and iam files • occurrence information • constraints • work features • No geometry (other than assembly features) is in the assembly document, only references to parts and other assemblies
ComponentOccurrences • ComponentOccurrences • Allows iteration over all existing occurrences • Use the Add method to add additional occurrences.
Creating Occurrences Through the API • 1. Get the AssemblyDocument • 2. Create a Matrix to used for the location of the occurrence • 3. Call one of the Add methods
Creating Occurrences – AddWithOptions() • NameValueMap (sets Options) • LevelOfDetailRepresentation • DesignViewRepresentation • PositionalRepresentation
DocumentDescriptorsEnumerator • DocumentDescriptorsEnumerator provides access to the documents referenced by the assembly
Bill Of Materials • Query and Export BOM Data • BOM property of ComponentDefinition • BOMRow ComponentDefinitions • Data can be retrieved using PropertySets
Demo Assembly Occurrences Use the API to open an Assembly Use the API to create a new Assembly Add occurrences to an Assembly Create sub assembly using Level of Detail Open assembly using Level of Detail Print out the file paths of referenced components Print BOM data to the immediate window
Transient Geometry • Allows you to create a matrix that controls the location of an occurrence
Vectors • Vectors define a direction and magnitude and used to define a change of location for an occurrence • UnitVector defines a direction. Its magnitude is always 1 CrossProduct – Determines a new vector that is perpendicular to the plane defined by the two input vectors
Matrix • Rectangular array of numbers. • A 3-D matrix is a 4x4 matrix. 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1
A Matrix as a Coordinate System • A Matrix can define a coordinate system (this example is the identity matrix. (xAxis = 1,0,0 – yAxis = 0,1,0 – zAxis = 0,0,1) • UnitVectors
A Matrix as a Transformation • Defines change in position and orientation (move and/or rotate) • Reposition an occurrence within an assembly. • Defining the change from one coordinate system to another. • in an assembly transform a point from one part into another part • TransfromBy • Applies the transform defined by one matrix to another matrix
Matrix and Occurrences • When placing an occurrence the matrix defines the position of the part within the assembly. • Transformation property of an occurrence returns the matrix that defines the occurrence’s current position in the assembly. • Setting the Transformation property repositions the occurrence (taking into account any constraints). • SetTransformWithoutConstraints transforms the occurrence ignoring any constraints (until the next recompute of the assembly).
Demo Vector and Matrix for Occurrences • Place a component in an assembly use Vectors and a Matrix to define the position and rotation • Use a Matrix to move all the components
Proxy Objects • A proxy represents an entity as if the entity actually exists in the assembly • Derived from the regular object they represent. • Support methods and properties of the regular object • Methods & properties return information in assembly context • Proxies also have these properties • ContainingOccurrence • NativeObject
Demo Proxy objects • Get a vertex of an occurrence using B-Rep. Print out it’s coordinates. Get the definition of that occurrence and get the same vertex in the PartComponentDefinition. • Use CreateGeometryProxy to create a VertexProxy
Constraints • Constraint creation can take as input work geometry from the assembly or proxies to entities in the attached parts • Query of a constraint returns the associated entities and the parameter controlling the constraint
Demo Assembly Constraints Constrain two vertexes Use Proxy workplanes to constrain faces
B-Rep • The B-Rep or “Boundary Representation” provides a complete geometric description of a solid model. • It is ignorant of the methods used to create the solid. • It provides access to both the topology and the geometry of the solid model.
B-Rep FaceShell One FaceShell Two FaceShells
B-Rep Face 6 Faces
B-Rep Edge 4 EdgeLoops, 4 Edges Edge shared between faces - unlike an EdgeUse object.
B-Rep EdgeUse A face has its own set of EdgeUse objects, which apply only to that face. Defined in terms of the 2D parameter space of face. Two EdgeUse objects for each Edge Object. Contain information specific to a face, including a conceptual flow direction for the face edges, useful in traversing faces.
B-Rep Access • Accessing B-Rep entities • Traversing the B-Rep structure. • From existing features. (Faces, EndFaces, StartFaces, SideFaces) • Near a specified point. (LocateUsingPoint) • Intersected by a specified vector. (FindUsingRay) • Selected by the end-user. • Querying based on previously assigned attributes.
Access B-Rep Objects from a Feature • Some features support properties to directly access related B-Rep entities. • All features • Faces, SurfaceBody • ExtrudeFeature, RevolveFeature, SweepFeature, LoftFeature, HoleFeature • EndFaces, StartFaces, SideFaces
Demo Boundary Representation (B-Rep) • B-Rep Traversal • Find UsingRay • Evaluators
Summary Introduction to the Inventor API Utility API objects API for Assemblies Introduction to B-Rep API
Learning More • Programming help • SDK samples • Developer Center • www.autodesk.com/developinventor • DevTV • Discussion Groups • http://discussion.autodesk.com • autodesk.inventor.customization • API Training Classes • www.autodesk.com/apitraining • Autodesk Developer Network • www.autodesk.com/joinadn