create a centerline by two points

create a centerline by two points

breinkemeyer
Enthusiast Enthusiast
528 Views
5 Replies
Message 1 of 6

create a centerline by two points

breinkemeyer
Enthusiast
Enthusiast

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);

0 Likes
529 Views
5 Replies
Replies (5)
Message 2 of 6

A.Acheson
Mentor
Mentor

Hi @breinkemeyer 

It might be the declaration of sketchpoint instead of offering point2d directly into  geometry intent.

See intent help page here

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 6

WCrihfield
Mentor
Mentor

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

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 6

breinkemeyer
Enthusiast
Enthusiast

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.  

0 Likes
Message 5 of 6

A.Acheson
Mentor
Mentor

Hi @breinkemeyer 

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. 

AAcheson_0-1713375332876.png

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 6 of 6

JBerns
Advisor
Advisor

This was the closest topic match I could find related to my two-point centerline creation issue.

 

I am trying to create a centerline through the bolt (a content center component). I tried retrieving the Work X AXis, but the line needed editing for layer, start position, and end position.

I would have to get info from the bolt to calculate those points.

JBerns_0-1754581268279.png

 

Manually creating a centerline by picking two points gave the best initial result.

JBerns_1-1754581320002.png

The challenge - I would need to get these "points" from the fastener in each view. Would need to factor view scale (I think).

 

Adding a work point or named entities to all the content center library components seems like a daunting task.

 

Is it possible to get the bolt points and create the centerline using iLogic? FYI - this is just one element in a pattern if that makes a difference.

 

I am not looking for code just yet - just checking if possible and any advice to get started. Sample model and drawing attached.

 

Thank you for your time and attention. I look forward to your replies.

 

Regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes