- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
create a centerline by two points
Trying to add a centerline to a drawing view but it keeps failing at the centerlines.add method. All I get is an ambiguous error message. What am i missing?
DrawingDocument oDoc = (DrawingDocument)oInventorApp.ActiveDocument;
Sheet oSheet = oDoc.ActiveSheet;
DrawingView oView = oSheet.DrawingViews[1];
Centerlines oLines = oSheet.Centerlines;
DrawingSketch oSketch = oView.Sketches.Add();
SketchPoints oPoints = oSketch.SketchPoints;
oSketch.Edit();
SketchPoint pnt1 = oPoints.Add(oITransGeo.CreatePoint2d(0, 0), false);
SketchPoint pnt2 = oPoints.Add(oITransGeo.CreatePoint2d(216 * 2.54, 0), false);
oSketch.ExitEdit();
GeometryIntent oInt1 = oSheet.CreateGeometryIntent(pnt1);
GeometryIntent oInt2 = oSheet.CreateGeometryIntent(pnt2);
ObjectCollection oCollection = oInventorApp.TransientObjects.CreateObjectCollection();
oCollection.Add(oInt1);
oCollection.Add(oInt2);
Centerline line = oLines.Add(oCollection);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
It might be the declaration of sketchpoint instead of offering point2d directly into geometry intent.
See intent help page here
Or if this helped you, please, click (like)
Regards
Alan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Just another odd thought that comes to mind, but it may be a stretch of the imagination. Since this is a drawing sketch being created within a drawing view, you may have to translate the two transient Point2d objects from 'sheet space' to 'view space' and/or to 'sketch space'.
DrawingSketch.SheetToSketchSpace
DrawingView.SheetToDrawingViewSpace
Wesley Crihfield
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
So this may not be the best way to do it, but I ended up adding two workpoints to the assembly then translated them using modeltosheetspace and adding a sketchline between those points. Then I changed the linetype to chained.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Yes that would be a good way to tie a centerline to the model. You can also project a curve into the sketch and constrain the line to that curve.
Here is a quick sample in VB.NET of just adding a sketchline and changing layer to Centerline.
Dim drawView As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a drawing view")
Dim drawDoc As DrawingDocument= ThisApplication.ActiveDocument
Dim sketch1 As DrawingSketch = drawView.Sketches.Add
sketch1.Edit
Dim startPt As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(0,0)
startPt = drawView.SheetToDrawingViewSpace(startPt)
Dim endPt As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(216*2.54,0)
endPt = drawView.SheetToDrawingViewSpace(endPt)
Dim oLine As SketchLine = sketch1.SketchLines.AddByTwoPoints(startPt, endPt)
Dim layers As LayersEnumerator = drawDoc.StylesManager.Layers
oLine.Layer = layers.Item("Centerline (ANSI)")
sketch1.ExitEdit
This isn't tied to any specific geometry, the centerline is just of the sheet.
Or if this helped you, please, click (like)
Regards
Alan