Search for the lowest point

Search for the lowest point

orhan.alihanov
Participant Participant
314 Views
1 Reply
Message 1 of 2

Search for the lowest point

orhan.alihanov
Participant
Participant

 

 

 

Hello! I want to create the drawing , add a view of 3D , create a sketch, add a line through the lowest point of the projection. I've already written the bulk of the code, but I can't seem to get the projection of the geometry onto the sketch to find the lowest point...

Dim invApp As Inventor.Application
invApp = ThisApplication
Dim partDoc As PartDocument = ThisDoc.Document
Dim tg As TransientGeometry = ThisApplication.TransientGeometry
' Определение пути к шаблону
Dim templatePath As String
templatePath = ".\Templates\Standard.dwg"
Dim newDrawingDoc As DrawingDocument
newDrawingDoc = invApp.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, templatePath, True)
newDrawingDoc.Activate()
	
Dim oSheet As Sheet = newDrawingDoc.ActiveSheet
Dim frontView As DrawingView
		
frontView = oSheet.DrawingViews.AddBaseView(partDoc, tg.CreatePoint2d(x,y), 1/50, ViewOrientationTypeEnum.kBackViewOrientation, DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle)
			
Dim sketch As Sketch = frontView.Sketches.Add()
sketch.Edit

'all geometry is projected here, 
' the lowest point is determined,
'startPoint and endPoint are defined

Dim line As SketchLine = sketch.SketchLines.AddByTwoPoints(startPoint, endPoint)
line.LineWeight = 0.01

sketch.ExitEdit()


	

 

 

0 Likes
315 Views
1 Reply
Reply (1)
Message 2 of 2

JelteDeJong
Mentor
Mentor

Most of the code below I took from this blog post "Automatically generate overall dimensions". (Here I use the first drawing view on the active sheet. That is different from your code.)  It has a function to get all intent points of a view. That list includes the bottom point. With a sorting function, you can get the bottom intent and use it in your sketch. 

Public Class ThisRule

    Private _doc As DrawingDocument
    Private _sheet As Sheet
    Private _view As DrawingView
    Private _intents As List(Of GeometryIntent) = New List(Of GeometryIntent)()


    Sub Main()

        _doc = ThisDoc.Document
        _sheet = _doc.ActiveSheet
        _view = _sheet.DrawingViews.Item(1)

        CreateIntentList()
        CreateLowestPointLine()

    End Sub

    Private Sub CreateLowestPointLine()
        Dim orderedIntents = _intents.OrderByDescending(Function(s) s.PointOnSheet.Y)

        Dim intentBottom = orderedIntents.Last

        Dim sketch As DrawingSketch = _view.Sketches.Add()
        sketch.Edit()

        Dim bottomSketchPoint As Point2d = sketch.SheetToSketchSpace(intentBottom.PointOnSheet)
        Dim sketchPointEnd As Point2d = ThisApplication.TransientGeometry.
            CreatePoint2d(bottomSketchPoint.X - 5, bottomSketchPoint.Y)

        sketch.SketchLines.AddByTwoPoints(bottomSketchPoint, sketchPointEnd)

        ' If you need the SketchEntity to constraint your line then you can get it like this:
        ' Dim entity As SketchEntity = sketch.AddByProjectingEntity(intentBottom.Geometry)

        sketch.ExitEdit()
    End Sub

    Private Sub CreateIntentList()

        For Each oDrawingCurve As DrawingCurve In _view.DrawingCurves
            Select Case oDrawingCurve.ProjectedCurveType
                Case _
                        Curve2dTypeEnum.kCircleCurve2d,
                        Curve2dTypeEnum.kCircularArcCurve2d,
                        Curve2dTypeEnum.kEllipseFullCurve2d,
                        Curve2dTypeEnum.kEllipticalArcCurve2d

                    addIntent(oDrawingCurve, PointIntentEnum.kCircularTopPointIntent, True)
                    addIntent(oDrawingCurve, PointIntentEnum.kCircularBottomPointIntent, True)
                    addIntent(oDrawingCurve, PointIntentEnum.kCircularLeftPointIntent, True)
                    addIntent(oDrawingCurve, PointIntentEnum.kCircularRightPointIntent, True)

                    addIntent(oDrawingCurve, PointIntentEnum.kEndPointIntent, False)
                    addIntent(oDrawingCurve, PointIntentEnum.kStartPointIntent, False)

                Case _
                        Curve2dTypeEnum.kLineCurve2d,
                        Curve2dTypeEnum.kLineSegmentCurve2d

                    addIntent(oDrawingCurve, PointIntentEnum.kEndPointIntent, False)
                    addIntent(oDrawingCurve, PointIntentEnum.kStartPointIntent, False)

                Case _
                    Curve2dTypeEnum.kPolylineCurve2d,
                    Curve2dTypeEnum.kBSplineCurve2d,
                    Curve2dTypeEnum.kUnknownCurve2d

                    ' Unhandled curves types
                Case Else
            End Select
        Next
    End Sub

    Private Sub addIntent(Geometry As DrawingCurve, IntentPlace As Object, onLineCheck As Boolean)
        Dim intent As GeometryIntent = _sheet.CreateGeometryIntent(Geometry, IntentPlace)
        If intent.PointOnSheet Is Nothing Then Return

        If onLineCheck Then
            If (IntentIsOnCurve(intent)) Then
                _intents.Add(intent)
            End If
        Else
            _intents.Add(intent)
        End If
    End Sub

    Private Function IntentIsOnCurve(intent As GeometryIntent) As Boolean
        Dim Geometry As DrawingCurve = intent.Geometry
        Dim sp = intent.PointOnSheet

        Dim pts(1) As Double
        Dim gp() As Double = {}
        Dim md() As Double = {}
        Dim pm() As Double = {}
        Dim st() As SolutionNatureEnum = {}
        pts(0) = sp.X
        pts(1) = sp.Y

        Try
            Geometry.Evaluator2D.GetParamAtPoint(pts, gp, md, pm, st)
        Catch ex As Exception
            Return False
        End Try
        Return True
    End Function

End Class

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes