iLogic bind annotation to user parameters

iLogic bind annotation to user parameters

robertast
Collaborator Collaborator
2,221 Views
18 Replies
Message 1 of 19

iLogic bind annotation to user parameters

robertast
Collaborator
Collaborator

I have custom parameters created in my part, Ak1 Ak2 Rk1 Rk2

I would like to place iLogic in the selected view in the drawing, the leader's note according to these parameters. And put them on the edge.

Previously, I did not dare to make such a request on the forum, but after seeing what miracles @JhoelForshav  does, I will ask

Kantai.jpg

2,222 Views
18 Replies
Replies (18)
Message 2 of 19

robertast
Collaborator
Collaborator

Forgot to complicate the task. If there is nothing in the custom options, the leader does not appear 😉

Kantai 2.jpg

And for those users who do not know how a callout is made with pens, I attach a video

0 Likes
Message 3 of 19

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @robertast 

It's a difficult task. Maybe this code will at least give you someideas.

Since the view is a simple square i can use its properties top and left to find curve segments on its edges. Then I can create geometry intent from these segments parents (drawing curves).

 

It seems however that text justification is ignored when it comes to leader notes, and since the notes position is the same wether the text is over/under the line as long as it's attached to the line I can't find a way to move it to the outside...

 

This code:

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 Ak1Pos As Point2d = oTG.CreatePoint2d(oPt.X, oView.Top - oView.Height)
Dim Ak2Pos As Point2d = oTG.CreatePoint2d(oPt.X, oView.Top)
Dim Rk1Pos As Point2d = oTG.CreatePoint2d(oView.Left, oPt.Y)
Dim Rk2Pos As Point2d = oTG.CreatePoint2d(oView.Left + oView.Width, oPt.Y)
Dim oSheet As Sheet = oView.Parent

Dim ak1Curve As DrawingCurveSegment = oSheet.FindUsingPoint(Ak1Pos).Item(1)
Dim ak2Curve As DrawingCurveSegment = oSheet.FindUsingPoint(Ak2Pos).Item(1)
Dim rk1Curve As DrawingCurveSegment = oSheet.FindUsingPoint(Rk1Pos).Item(1)
Dim rk2Curve As DrawingCurveSegment = oSheet.FindUsingPoint(Rk2Pos).Item(1)
Dim ak1Intent As GeometryIntent = oSheet.CreateGeometryIntent(ak1Curve.Parent, kCenterPointIntent)
Dim ak2Intent As GeometryIntent = oSheet.CreateGeometryIntent(ak2Curve.Parent, kCenterPointIntent)
Dim rk1Intent As GeometryIntent = oSheet.CreateGeometryIntent(rk1Curve.Parent, kCenterPointIntent)
Dim rk2Intent As GeometryIntent = oSheet.CreateGeometryIntent(rk2Curve.Parent, kCenterPointIntent)


On Error Resume Next
Dim oDoc As PartDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim Ak1 As String = oDoc.ComponentDefinition.Parameters.UserParameters.Item("Ak1").Value
Dim Ak2 As String = oDoc.ComponentDefinition.Parameters.UserParameters.Item("Ak2").Value
Dim Rk1 As String = oDoc.ComponentDefinition.Parameters.UserParameters.Item("Rk1").Value
Dim Rk2 As String = oDoc.ComponentDefinition.Parameters.UserParameters.Item("Rk2").Value
Dim oCol As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
oCol.Add(ak1Intent)
Dim Ak1Note As LeaderNote = oSheet.DrawingNotes.LeaderNotes.Add(oCol, Ak1)
oCol.Clear
oCol.Add(ak2Intent)
Dim Ak2Note As LeaderNote =oSheet.DrawingNotes.LeaderNotes.Add(oCol, Ak2)
oCol.Clear
oCol.Add(rk1Intent)
Dim Rk1Note As LeaderNote =oSheet.DrawingNotes.LeaderNotes.Add(oCol, Rk1)
oCol.Clear
oCol.Add(rk2Intent)
Dim Rk2Note As LeaderNote = oSheet.DrawingNotes.LeaderNotes.Add(oCol, Rk2)


oSheet.Update

will give a result like this:

annotations.PNG

 

Message 4 of 19

JhoelForshav
Mentor
Mentor
Accepted solution

Are the squares around your text something that comes with your note style?

(I only have Inventor 2020 so I can't open your drawing to see how you've done it)

 

I managed to get the annotations in the correct positions now so maybe this is it?

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 Ak1Pos As Point2d = oTG.CreatePoint2d(oPt.X, oView.Top - oView.Height)
Dim Ak2Pos As Point2d = oTG.CreatePoint2d(oPt.X, oView.Top)
Dim Rk1Pos As Point2d = oTG.CreatePoint2d(oView.Left, oPt.Y)
Dim Rk2Pos As Point2d = oTG.CreatePoint2d(oView.Left + oView.Width, oPt.Y)
Dim oSheet As Sheet = oView.Parent

Dim ak1Curve As DrawingCurveSegment = oSheet.FindUsingPoint(Ak1Pos).Item(1)
Dim ak2Curve As DrawingCurveSegment = oSheet.FindUsingPoint(Ak2Pos).Item(1)
Dim rk1Curve As DrawingCurveSegment = oSheet.FindUsingPoint(Rk1Pos).Item(1)
Dim rk2Curve As DrawingCurveSegment = oSheet.FindUsingPoint(Rk2Pos).Item(1)
Dim ak1Intent As GeometryIntent = oSheet.CreateGeometryIntent(ak1Curve.Parent, kCenterPointIntent)
Dim ak2Intent As GeometryIntent = oSheet.CreateGeometryIntent(ak2Curve.Parent, kCenterPointIntent)
Dim rk1Intent As GeometryIntent = oSheet.CreateGeometryIntent(rk1Curve.Parent, kCenterPointIntent)
Dim rk2Intent As GeometryIntent = oSheet.CreateGeometryIntent(rk2Curve.Parent, kCenterPointIntent)


On Error Resume Next
Dim oDoc As PartDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim Ak1 As String = oDoc.ComponentDefinition.Parameters.UserParameters.Item("Ak1").Value
Dim Ak2 As String = oDoc.ComponentDefinition.Parameters.UserParameters.Item("Ak2").Value
Dim Rk1 As String = oDoc.ComponentDefinition.Parameters.UserParameters.Item("Rk1").Value
Dim Rk2 As String = oDoc.ComponentDefinition.Parameters.UserParameters.Item("Rk2").Value
Dim oCol As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
oCol.Add(oTG.CreatePoint2d(ak1Intent.PointOnSheet.X, ak1Intent.PointOnSheet.Y - .1))
oCol.Add(ak1Intent)
Dim Ak1Note As LeaderNote = oSheet.DrawingNotes.LeaderNotes.Add(oCol, Ak1)
oCol.Clear
oCol.Add(oTG.CreatePoint2d(ak2Intent.PointOnSheet.X, ak2Intent.PointOnSheet.Y + .1))
oCol.Add(ak2Intent)
Dim Ak2Note As LeaderNote =oSheet.DrawingNotes.LeaderNotes.Add(oCol, Ak2)
oCol.Clear
oCol.Add(oTG.CreatePoint2d(rk1Intent.PointOnSheet.X - .1, rk1Intent.PointOnSheet.Y))
oCol.Add(rk1Intent)
Dim Rk1Note As LeaderNote =oSheet.DrawingNotes.LeaderNotes.Add(oCol, Rk1)
oCol.Clear
oCol.Add(oTG.CreatePoint2d(rk2Intent.PointOnSheet.X + .1, rk1Intent.PointOnSheet.Y))
oCol.Add(rk2Intent)
Dim Rk2Note As LeaderNote = oSheet.DrawingNotes.LeaderNotes.Add(oCol, Rk2)

oSheet.Update

annotations2.PNG

Message 5 of 19

robertast
Collaborator
Collaborator

Yes, I told you that you are a genius in solving the most difficult problems 👍. Since I am a specialist in creating unsolvable problems  😉

 

Again, I'm doing something wrong, not one of the rules does not work for me 🙁

0 Likes
Message 6 of 19

JhoelForshav
Mentor
Mentor

Hmm... Are the parameter names correct?

Try removing "On Error Resume Next" so we can see the error message 🙂

0 Likes
Message 7 of 19

JhoelForshav
Mentor
Mentor

Does everything look like in this video?

0 Likes
Message 8 of 19

robertast
Collaborator
Collaborator
Accepted solution

I have parameters in the wrong place Here is a video of where they are

 

@JhoelForshav   Is it possible in iLogic to use these parameters?

0 Likes
Message 9 of 19

JhoelForshav
Mentor
Mentor
Accepted solution

Ahaa, those are properties, not parameters 🙂

 

Try this:

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 Ak1Pos As Point2d = oTG.CreatePoint2d(oPt.X, oView.Top - oView.Height)
Dim Ak2Pos As Point2d = oTG.CreatePoint2d(oPt.X, oView.Top)
Dim Pk1Pos As Point2d = oTG.CreatePoint2d(oView.Left, oPt.Y)
Dim Pk2Pos As Point2d = oTG.CreatePoint2d(oView.Left + oView.Width, oPt.Y)
Dim oSheet As Sheet = oView.Parent

Dim ak1Curve As DrawingCurveSegment = oSheet.FindUsingPoint(Ak1Pos).Item(1)
Dim ak2Curve As DrawingCurveSegment = oSheet.FindUsingPoint(Ak2Pos).Item(1)
Dim pk1Curve As DrawingCurveSegment = oSheet.FindUsingPoint(Pk1Pos).Item(1)
Dim pk2Curve As DrawingCurveSegment = oSheet.FindUsingPoint(Pk2Pos).Item(1)
Dim ak1Intent As GeometryIntent = oSheet.CreateGeometryIntent(ak1Curve.Parent, kCenterPointIntent)
Dim ak2Intent As GeometryIntent = oSheet.CreateGeometryIntent(ak2Curve.Parent, kCenterPointIntent)
Dim pk1Intent As GeometryIntent = oSheet.CreateGeometryIntent(pk1Curve.Parent, kCenterPointIntent)
Dim pk2Intent As GeometryIntent = oSheet.CreateGeometryIntent(pk2Curve.Parent, kCenterPointIntent)


On Error Resume Next
Dim oDoc As PartDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument
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
oCol.Add(oTG.CreatePoint2d(ak1Intent.PointOnSheet.X, ak1Intent.PointOnSheet.Y - .1))
oCol.Add(ak1Intent)
Dim Ak1Note As LeaderNote = oSheet.DrawingNotes.LeaderNotes.Add(oCol, Ak1)
oCol.Clear
oCol.Add(oTG.CreatePoint2d(ak2Intent.PointOnSheet.X, ak2Intent.PointOnSheet.Y + .1))
oCol.Add(ak2Intent)
Dim Ak2Note As LeaderNote =oSheet.DrawingNotes.LeaderNotes.Add(oCol, Ak2)
oCol.Clear
oCol.Add(oTG.CreatePoint2d(pk1Intent.PointOnSheet.X - .1, pk1Intent.PointOnSheet.Y))
oCol.Add(pk1Intent)
Dim Pk1Note As LeaderNote =oSheet.DrawingNotes.LeaderNotes.Add(oCol, Pk1)
oCol.Clear
oCol.Add(oTG.CreatePoint2d(pk2Intent.PointOnSheet.X + .1, pk1Intent.PointOnSheet.Y))
oCol.Add(pk2Intent)
Dim Pk2Note As LeaderNote = oSheet.DrawingNotes.LeaderNotes.Add(oCol, Pk2)

oSheet.Update
Message 10 of 19

robertast
Collaborator
Collaborator

@JhoelForshav 

Thank you so much. Everything works fine. I owe you wine again. 😊
You have solved almost all my problems. 😉

But don't be offended, I'll come up with additional
I wrote to @WCrihfield   that he hadn't spoken to me for four days. 😁

Message 11 of 19

JhoelForshav
Mentor
Mentor
Accepted solution

@robertast 

As a little bonus you can use formatted text to have the note linked to the property in the model, so that when you update the properties in the model the drawing will update automatically 🙂

 

Try this, It worked for me 🙂

 

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 Ak1Pos As Point2d = oTG.CreatePoint2d(oPt.X, oView.Top - oView.Height)
Dim Ak2Pos As Point2d = oTG.CreatePoint2d(oPt.X, oView.Top)
Dim Pk1Pos As Point2d = oTG.CreatePoint2d(oView.Left, oPt.Y)
Dim Pk2Pos As Point2d = oTG.CreatePoint2d(oView.Left + oView.Width, oPt.Y)
Dim oSheet As Sheet = oView.Parent

Dim ak1Curve As DrawingCurveSegment = oSheet.FindUsingPoint(Ak1Pos).Item(1)
Dim ak2Curve As DrawingCurveSegment = oSheet.FindUsingPoint(Ak2Pos).Item(1)
Dim pk1Curve As DrawingCurveSegment = oSheet.FindUsingPoint(Pk1Pos).Item(1)
Dim pk2Curve As DrawingCurveSegment = oSheet.FindUsingPoint(Pk2Pos).Item(1)
Dim ak1Intent As GeometryIntent = oSheet.CreateGeometryIntent(ak1Curve.Parent, kCenterPointIntent)
Dim ak2Intent As GeometryIntent = oSheet.CreateGeometryIntent(ak2Curve.Parent, kCenterPointIntent)
Dim pk1Intent As GeometryIntent = oSheet.CreateGeometryIntent(pk1Curve.Parent, kCenterPointIntent)
Dim pk2Intent As GeometryIntent = oSheet.CreateGeometryIntent(pk2Curve.Parent, kCenterPointIntent)


On Error Resume Next
Dim oDoc As PartDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument
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
oCol.Add(oTG.CreatePoint2d(ak1Intent.PointOnSheet.X, ak1Intent.PointOnSheet.Y - .1))
oCol.Add(ak1Intent)
Dim Ak1Note As LeaderNote = oSheet.DrawingNotes.LeaderNotes.Add(oCol, Ak1)
oCol.Clear
oCol.Add(oTG.CreatePoint2d(ak2Intent.PointOnSheet.X, ak2Intent.PointOnSheet.Y + .1))
oCol.Add(ak2Intent)
Dim Ak2Note As LeaderNote =oSheet.DrawingNotes.LeaderNotes.Add(oCol, Ak2)
oCol.Clear
oCol.Add(oTG.CreatePoint2d(pk1Intent.PointOnSheet.X - .1, pk1Intent.PointOnSheet.Y))
oCol.Add(pk1Intent)
Dim Pk1Note As LeaderNote =oSheet.DrawingNotes.LeaderNotes.Add(oCol, Pk1)
oCol.Clear
oCol.Add(oTG.CreatePoint2d(pk2Intent.PointOnSheet.X + .1, pk1Intent.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

 

Message 12 of 19

robertast
Collaborator
Collaborator

All I ran for wine 😁

0 Likes
Message 13 of 19

robertast
Collaborator
Collaborator

Hi @JhoelForshav 

 

Maybe you can still correct the code so that it overlaps by name at the edges of the inscription? Nobody can do it without you. I've already tried looking for help.

Screenshot_2020-08-14 Получить Надпись на чертеже.png

0 Likes
Message 14 of 19

JhoelForshav
Mentor
Mentor

@robertast 

Sorry, but I don't understand what you're asking for here🤔

0 Likes
Message 15 of 19

robertast
Collaborator
Collaborator

Each property should fit in accordance with the face name.
Ak1 = "Front" ; Ak2 = "Back" ; Pk1 = "Left" ; Pk2 = "Right"

Atribute.png

0 Likes
Message 16 of 19

JhoelForshav
Mentor
Mentor
Accepted solution

@robertast 

Like this?

Sub Main

Dim oView As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "pick drawing view.")
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
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
oCol.Add(oTG.CreatePoint2d(ak1Intent.PointOnSheet.X, ak1Intent.PointOnSheet.Y - .1))
oCol.Add(ak1Intent)
Dim Ak1Note As LeaderNote = oSheet.DrawingNotes.LeaderNotes.Add(oCol, Ak1)
oCol.Clear
oCol.Add(oTG.CreatePoint2d(ak2Intent.PointOnSheet.X, ak2Intent.PointOnSheet.Y + .1))
oCol.Add(ak2Intent)
Dim Ak2Note As LeaderNote =oSheet.DrawingNotes.LeaderNotes.Add(oCol, Ak2)
oCol.Clear
oCol.Add(oTG.CreatePoint2d(pk1Intent.PointOnSheet.X - .1, pk1Intent.PointOnSheet.Y))
oCol.Add(pk1Intent)
Dim Pk1Note As LeaderNote =oSheet.DrawingNotes.LeaderNotes.Add(oCol, Pk1)
oCol.Clear
oCol.Add(oTG.CreatePoint2d(pk2Intent.PointOnSheet.X + .1, pk1Intent.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
Message 17 of 19

robertast
Collaborator
Collaborator

Many thanks. I told you that it won't work without you. I turned to other specialists for help, but they could not.
Now the rule works almost perfectly, except that in one projection it overlays the inscription inside the part. But this is not critical - I will correct it with my hands.

Untitled.png

0 Likes
Message 18 of 19

JhoelForshav
Mentor
Mentor
Accepted solution

@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

robertas.PNG

Message 19 of 19

robertast
Collaborator
Collaborator

@JhoelForshav 

You are a wizard 😊