This article is based on a case study presented at ADN DevCamp 2012 on how improve interoperability between Civil 3D and Inventor. The image below is a summary of what was done and presented: read Corridor data at Civil 3D to create a spline at a Inventor sketch. It is required some Inventor API knowledge, so if you now familiar with it, please visit the Inventor Developer Center.
The idea was to use Inventor out-of-process COM API from Civil 3D in-process .NET API based plug-in as the main architecture. This approach allow us direct access to the objects without use of any intermediate file, which is also a common practice, but can result in a lot of extra work. One disadvantage is that both application must be installed and running (although we can launch automatically).
Below is a very simplified version of the plug-in to demonstrate the idea, but you can download the full version here. For a given Civil 3D Corridor Feature Line, get all AutoCAD Geometry Points, then create a Inventor 3D Sketch, where the 3D Spline will be drawn. Like AutoCAD Civil 3D, Inventor has a type of geometry entities called Transient Geometry, so the code creates Inventor Transient Points based on the AutoCAD Geometry Points XYZ coordinates, which are then used to create Inventor Sketch Points that compose the Inventor Sketch Spline.
// Get the feature line collection of Acad geometry points
Point3dCollection points = new Point3dCollection();
// Iterate through the collection of feature points
foreach (FeatureLinePoint flPoint in featureLine.FeatureLinePoints)
{
// If is between the margin we seek
if (flPoint.Station > startStation && flPoint.Station < endStation)
{
// Add to the collection
points.Add(flPoint.XYZ);
}
}
// Get running Inventor and its open document (Part Doc)
Inventor.Application app = GetApplication();
Inventor.PartDocument partDoc =
app.ActiveDocument as Inventor.PartDocument;
// Create a new sketch
Inventor.Sketch3D sketch =
partDoc.ComponentDefinition.Sketches3D.Add();
// Access Inventor Transient Geometry object,
// used to create non-visual (in memory geometry) objects
Inventor.TransientGeometry tg = app.TransientGeometry;
// Create a collection of points
Inventor.ObjectCollection pointForInventor =
app.TransientObjects.CreateObjectCollection();
// Convert each Acad Geometry point into Inventor Geometry points
// and store into the collection
foreach (Point3d acadPt in points)
{
pointForInventor.Add(
sketch.SketchPoints3D.Add(
tg.CreatePoint(acadPt.X, acadPt.Y, acadPt.Z)));
}
// Finally use the collection of points to create the
// new spline at the new sketch
Inventor.SketchSpline3D spline = sketch.SketchSplines3D.Add(
pointForInventor);
It is possible to note here that the raw data, basically coordinates as double values, is immediately transferred without any lost or intermediate conversion. For a approach like that it is required to go deep enough (i.e. from Civil 3D Corridor, to Feature Line, to Geometry Points) and then back (i.e. from Inventor Transient Point, to Sketch Point, to Sketch Spline) so it’s possible to base the execution only on raw data.


Leave a Reply