@robertast
I fixed it. The code could use some clean up with a sub for the checking note positions instead of repeating the same lines over and over. But at least this works:
Sub Main
Dim oView As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "pick drawing view.")
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oPt As Point2d = oView.Position
Dim BottomPos As Point2d = oTG.CreatePoint2d(oPt.X, oView.Top - oView.Height)
Dim TopPos As Point2d = oTG.CreatePoint2d(oPt.X, oView.Top)
Dim LeftPos As Point2d = oTG.CreatePoint2d(oView.Left, oPt.Y)
Dim RightPos As Point2d = oTG.CreatePoint2d(oView.Left + oView.Width, oPt.Y)
Dim oSheet As Sheet = oView.Parent
Dim oDoc As PartDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim oFront As Face = GetNamedEntity(oDoc, "Front")
Dim oBack As Face = GetNamedEntity(oDoc, "Back")
Dim oLeft As Face = GetNamedEntity(oDoc, "Left")
Dim oRight As Face = GetNamedEntity(oDoc, "Right")
Dim ak1Curve As DrawingCurve
Dim ak2Curve As DrawingCurve
Dim pk1Curve As DrawingCurve
Dim pk2Curve As DrawingCurve
For Each oCurve As DrawingCurve In oView.DrawingCurves
For Each oEdge As Edge In oFront.Edges
If oEdge Is oCurve.ModelGeometry Then ak1Curve = oCurve
Next
For Each oEdge As Edge In oBack.Edges
If oEdge Is oCurve.ModelGeometry Then ak2Curve = oCurve
Next
For Each oEdge As Edge In oLeft.Edges
If oEdge Is oCurve.ModelGeometry Then pk1Curve = oCurve
Next
For Each oEdge As Edge In oRight.Edges
If oEdge Is oCurve.ModelGeometry Then pk2Curve = oCurve
Next
Next
Dim ak1Intent As GeometryIntent = oSheet.CreateGeometryIntent(ak1Curve, kCenterPointIntent)
Dim ak2Intent As GeometryIntent = oSheet.CreateGeometryIntent(ak2Curve, kCenterPointIntent)
Dim pk1Intent As GeometryIntent = oSheet.CreateGeometryIntent(pk1Curve, kCenterPointIntent)
Dim pk2Intent As GeometryIntent = oSheet.CreateGeometryIntent(pk2Curve, kCenterPointIntent)
On Error Resume Next
Dim Ak1 As String = oDoc.PropertySets.Item(4).Item("Ak1").Value
Dim Ak2 As String = oDoc.PropertySets.Item(4).Item("Ak2").Value
Dim Pk1 As String = oDoc.PropertySets.Item(4).Item("Pk1").Value
Dim Pk2 As String = oDoc.PropertySets.Item(4).Item("Pk2").Value
Dim oCol As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
Dim CorrVal As Double = 0
Dim CorrPoint As Point2d = ak1Intent.PointOnSheet
If CorrPoint.IsEqualTo(TopPos) Then CorrVal = 0.1
If CorrPoint.IsEqualTo(BottomPos) Then CorrVal = -0.1
If CorrPoint.IsEqualTo(LeftPos) Then CorrVal = -0.1
If CorrPoint.IsEqualTo(RightPos) Then CorrVal = 0.1
oCol.Add(oTG.CreatePoint2d(ak1Intent.PointOnSheet.X, ak1Intent.PointOnSheet.Y + CorrVal))
oCol.Add(ak1Intent)
Dim Ak1Note As LeaderNote = oSheet.DrawingNotes.LeaderNotes.Add(oCol, Ak1)
oCol.Clear
CorrPoint = ak2Intent.PointOnSheet
If CorrPoint.IsEqualTo(TopPos) Then CorrVal = 0.1
If CorrPoint.IsEqualTo(BottomPos) Then CorrVal = -0.1
If CorrPoint.IsEqualTo(LeftPos) Then CorrVal = -0.1
If CorrPoint.IsEqualTo(RightPos) Then CorrVal = 0.1
oCol.Add(oTG.CreatePoint2d(ak2Intent.PointOnSheet.X, ak2Intent.PointOnSheet.Y + CorrVal))
oCol.Add(ak2Intent)
Dim Ak2Note As LeaderNote =oSheet.DrawingNotes.LeaderNotes.Add(oCol, Ak2)
oCol.Clear
CorrPoint = pk1Intent.PointOnSheet
If CorrPoint.IsEqualTo(TopPos) Then CorrVal = 0.1
If CorrPoint.IsEqualTo(BottomPos) Then CorrVal = -0.1
If CorrPoint.IsEqualTo(LeftPos) Then CorrVal = -0.1
If CorrPoint.IsEqualTo(RightPos) Then CorrVal = 0.1
oCol.Add(oTG.CreatePoint2d(pk1Intent.PointOnSheet.X + CorrVal, pk1Intent.PointOnSheet.Y))
oCol.Add(pk1Intent)
Dim Pk1Note As LeaderNote =oSheet.DrawingNotes.LeaderNotes.Add(oCol, Pk1)
oCol.Clear
CorrPoint = pk2Intent.PointOnSheet
If CorrPoint.IsEqualTo(TopPos) Then CorrVal = 0.1
If CorrPoint.IsEqualTo(BottomPos) Then CorrVal = -0.1
If CorrPoint.IsEqualTo(LeftPos) Then CorrVal = -0.1
If CorrPoint.IsEqualTo(RightPos) Then CorrVal = 0.1
oCol.Add(oTG.CreatePoint2d(pk2Intent.PointOnSheet.X + CorrVal, pk2Intent.PointOnSheet.Y))
oCol.Add(pk2Intent)
Dim Pk2Note As LeaderNote = oSheet.DrawingNotes.LeaderNotes.Add(oCol, Pk2)
Ak1Note.FormattedText = "<Property Document='model' PropertySet='User Defined Properties' Property='Ak1' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='28'>Ak1</Property>"
Ak2Note.FormattedText = "<Property Document='model' PropertySet='User Defined Properties' Property='Ak2' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='28'>Ak2</Property>"
Pk1Note.FormattedText = "<Property Document='model' PropertySet='User Defined Properties' Property='Pk1' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='28'>Pk1</Property>"
Pk2Note.FormattedText = "<Property Document='model' PropertySet='User Defined Properties' Property='Pk2' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='28'>Pk2</Property>"
oSheet.Update
End Sub
Public Function GetNamedEntity(doc As Inventor.Document, name As String) As Object
Dim attribMgr As AttributeManager = doc.AttributeManager
Dim objsFound As ObjectCollection
objsFound = attribMgr.FindObjects("iLogicEntityNameSet", "iLogicEntityName", name)
If objsFound.Count > 0 Then
Return(objsFound.Item(1))
Else
Return(Nothing)
End If
End Function
