Align 3D annotation to plane/face of feature in a part

Align 3D annotation to plane/face of feature in a part

emilda.chiuye
Enthusiast Enthusiast
1,170 Views
9 Replies
Message 1 of 10

Align 3D annotation to plane/face of feature in a part

emilda.chiuye
Enthusiast
Enthusiast

Hello

So before posting this I did some extensive research and came across a number of posts that were very much similar to mine, however neither of them have responses.

The closest I came to a solution was a post from @AnJanson (attached) whose post differs ever so slightly from mine. I wish to 3D annotate a feature on a single part in the XZ plane that will move along the part when the position of the feature is moved or suppressed. I can achieve this manually however it needs to be automated with the good help of iLogic 🙂

Seen attached is the solution similar to my request, could  someone please assist in tweaking this code to suit my situation?

Regards

Emilda

emildachiuye_0-1628087882274.png

 

0 Likes
Accepted solutions (2)
1,171 Views
9 Replies
Replies (9)
Message 2 of 10

Ralf_Krieg
Advisor
Advisor
Accepted solution

Hello

 

Can you try this:

Dim oDoc As Inventor.PartDocument = ThisDoc.Document
Dim oDef As Inventor.PartComponentDefinition = oDoc.ComponentDefinition
Dim oTG As Inventor.TransientGeometry = ThisApplication.TransientGeometry
Dim oRepMan As Inventor.RepresentationsManager = oDef.RepresentationsManager
Dim oDesignViewReps As Inventor.DesignViewRepresentations = oRepMan.DesignViewRepresentations
Dim oFace As Inventor.Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select a face to attach leader")
Dim oAnnoPlaneDef As Inventor.AnnotationPlaneDefinition = oDef.ModelAnnotations.CreateAnnotationPlaneDefinitionUsingPlane(oDef.WorkPlanes(2))
Dim oLeaderPoints As Inventor.ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection

oLeaderPoints.Add(oTG.CreatePoint(1, 0,1))

Dim oLeaderIntent As Inventor.GeometryIntent = oDef.CreateGeometryIntent(oFace)
oLeaderPoints.Add(oLeaderIntent)
Dim oLeaderDef As Inventor.ModelLeaderNoteDefinition = oDef.ModelAnnotations.ModelLeaderNotes.CreateDefinition(oLeaderPoints, "2000", oAnnoPlaneDef)
Dim oLeader As Inventor.ModelLeaderNote = oDef.ModelAnnotations.ModelLeaderNotes.Add(oLeaderDef)

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
Message 3 of 10

emilda.chiuye
Enthusiast
Enthusiast

Thank you so very much! This places what I am trying to achieve in perspective.

Now is it possible to achieve a code similar to this in the idw environment?

What I am aiming for is the user should type the note in excel which places or updates the leader note in the idw environment. 

I wish there was a coding dictionary that describes what all these phrases mean : (

 

0 Likes
Message 4 of 10

emilda.chiuye
Enthusiast
Enthusiast

The 3D annotation code you kindly provided, where can I attach the leader to the actual feature? Then it eliminates the prompt to "select a face" I just want the note to automatically attach itself to that particular feature.

0 Likes
Message 5 of 10

Ralf_Krieg
Advisor
Advisor

Hello

 

What do you mean with "actual feature"? Is a feature already selected or is it the last feature in the model browser tree or ... ?

There is afaik a new DrawingView.Include3DAnnotations Property in the API to retrieve the model annotations in a drawing view in Inventor 2022.

Before this, you can start the retrieve command, which opens the dialog to include annotations.

 

ThisApplication.CommandManager.ControlDefinitions("DrawingRetrieveDimsCmd").Execute

 

But then your users needs to interact or you simulate some sendkeys.

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 6 of 10

emilda.chiuye
Enthusiast
Enthusiast

What I mean by the actual feature is, instead of being prompted by Inventor to select a face to place the annotated note, the code should stipulate that, the note is allocated to Revolved Feature 1, Revolved Feature 2 etc.

Can the code include that it should be placed in the XZ plane of the Revolved Feature?

Inventor is able to do this manually so surely Inventor can carry out the same task automatically?

0 Likes
Message 7 of 10

emilda.chiuye
Enthusiast
Enthusiast

Hello

In my attempts to get to what I need done, I have played around with some variables and clearly I made a mess of it as it returned with this error : Public member "Feature" on type 'Application' not found

Perhaps this means I cannot have a feature as an application?

Hopefully you get the idea of what I am trying to do. I just want to indicate specifically where the leader should be...at Revolved Feature 1

emildachiuye_1-1628241798412.png

 

 

 

0 Likes
Message 8 of 10

Ralf_Krieg
Advisor
Advisor

Hello

 

What you want to get is the outer face face of RevolveFeature1. If you use named faces in your part, you can get them with one line of code. For instance, if you name the outer face of RevolveFeature1 as "Outer_Face_of_RevolveFeature1", the iLogic would be

Dim NamedEntity = iLogicVb.Automation.GetNamedEntities.FindEntity("Outer_Face_of_RevolveFeature1")

If you don't use named faces, there's a bit more work to do. A revolve feature can have a void inside, can have a cylinder or a cone on the outside and can have more than one face on the outside. You have to check all of this possible situations and grep the right face. Here's an example, but I'm not sure it covers all possible situations.

 

Private Sub Main()
    
    Dim oApp As Inventor.Application= ThisApplication
    Dim oDoc As Inventor.PartDocument= oApp.ActiveDocument
    Dim oDef As Inventor.PartComponentDefinition= oDoc.ComponentDefinition
    Dim oTG As Inventor.TransientGeometry= oApp.TransientGeometry
    Dim oRepMan As Inventor.RepresentationsManager= oDef.RepresentationsManager
    Dim oDesignViewReps As Inventor.DesignViewRepresentations= oRepMan.DesignViewRepresentations
    Dim oOuterFace As Inventor.Face
    Dim oRevolveFeature As Inventor.RevolveFeature

    For Each oRevolveFeature In oDef.Features.RevolveFeatures
        If Feature.IsActive(oRevolveFeature.Name) And oRevolveFeature.HealthStatus = HealthStatusEnum.kUpToDateHealth Then
            If CheckExistLeader(oRevolveFeature) = False Then
                oOuterFace = GetOuterFace(oRevolveFeature)
                
                Dim oAnnoPlaneDef As Inventor.AnnotationPlaneDefinition= oDef.ModelAnnotations.CreateAnnotationPlaneDefinitionUsingPlane(oDef.WorkPlanes(2))
                Dim oLeaderPoints As Inventor.ObjectCollection= oApp.TransientObjects.CreateObjectCollection
                Dim oIntentPoint As Point
                
                Select Case oOuterFace.SurfaceType
                Case SurfaceTypeEnum.kConeSurface:
                    oIntentPoint = GetPointOnCone(oOuterFace)
                Case SurfaceTypeEnum.kCylinderSurface:
                    oIntentPoint = GetPointOnCylinder(oOuterFace)
                End Select
                 
                Dim oLeaderIntent As Inventor.GeometryIntent= oDef.CreateGeometryIntent(oOuterFace, oIntentPoint)
                'The Leaderpoint should be relative positioned to the LeaderPoint 1
                Call oLeaderPoints.Add(oTG.CreatePoint(oIntentPoint.X + 1, 0, oIntentPoint.Z + 1))
                Call oLeaderPoints.Add(oLeaderIntent)

				Dim sFormattedText As String
                sFormattedText = "2000"
                
                Dim oLeaderDef As Inventor.ModelLeaderNoteDefinition = oDef.ModelAnnotations.ModelLeaderNotes.CreateDefinition(oLeaderPoints, sFormattedText, oAnnoPlaneDef)
                
                Dim oLeader As Inventor.ModelLeaderNote= oDef.ModelAnnotations.ModelLeaderNotes.Add(oLeaderDef)
                
                oOuterFace = Nothing
            End If
        End If
    Next
End Sub

Private Function CheckExistLeader(ByVal oRevolveFeature As RevolveFeature) As Boolean
    Dim oPartCompDef As PartComponentDefinition = oRevolveFeature.Parent
    Dim oLeaderNotes As ModelLeaderNotes = oPartCompDef.ModelAnnotations.ModelLeaderNotes
    Dim oIntentFace As Face
    Dim oLeaderNote As ModelLeaderNote
    For Each oLeaderNote In oLeaderNotes
        oIntentFace = oLeaderNote.Definition.Intent.Geometry
    Next
End Function

Private Function GetOuterFace(ByVal oRevolveFeature As Inventor.RevolveFeature) As Inventor.Face
    Dim oFace As Inventor.Face
    Dim oOuterFace As Inventor.Face
    For Each oFace In oRevolveFeature.Faces
        If oFace.SurfaceType = SurfaceTypeEnum.kConeSurface Or oFace.SurfaceType = SurfaceTypeEnum.kCylinderSurface Then
            If Not oOuterFace Is Nothing Then
                If oFace.Geometry.Radius > oOuterFace.Geometry.Radius Then
                    oOuterFace = oFace
                End If
            Else
                oOuterFace = oFace
            End If
        End If
    Next
	GetOuterFace = oOuterFace
End Function

Private Function GetPointOnCone(ByVal oFace As Face) As Point
    Dim oCone As Cone= oFace.Geometry
    Dim oSB As SurfaceBody= oFace.SurfaceBody
    Dim oBasis As Point = oCone.BasePoint
    Dim oRadius As Double = oCone.Radius
    Dim oEnts As Inventor.ObjectsEnumerator
    Dim oPoints As Inventor.ObjectsEnumerator
    Dim oVector As Vector= ThisApplication.TransientGeometry.CreateVector(0, 1, 0)
    
    Call oSB.FindUsingRay(oBasis, oVector.AsUnitVector, oRadius, oEnts, oPoints, False)
    
    If oEnts.Count > 0 Then
        Dim i As Integer
        For i = 1 To oEnts.Count
            If oEnts(i) Is oFace Then
                GetPointOnCone = oPoints(i)
            End If
        Next
    End If
End Function

Private Function GetPointOnCylinder(ByVal oFace As Face) As Point
    Dim oCylinder As Cylinder= oFace.Geometry
    Dim oSB As SurfaceBody= oFace.SurfaceBody
    Dim oBasis As Point = oCylinder.BasePoint
    Dim oRadius As Double= oCylinder.Radius
    Dim oEnts As Inventor.ObjectsEnumerator
    Dim oPoints As Inventor.ObjectsEnumerator
    Dim oVector As Vector = ThisApplication.TransientGeometry.CreateVector(0, 1, 0)
    
    Call oSB.FindUsingRay(oBasis, oVector.AsUnitVector, oRadius, oEnts, oPoints, False)
    
    If oEnts.Count > 0 Then
        Dim i As Integer
        For i = 1 To oEnts.Count
            Call ThisApplication.ActiveDocument.SelectSet.Select(oEnts(i))
            Select Case oEnts(i).Type
            Case kVertexObject:
            Case kEdgeObject:
                Dim oEdge As Edge= oEnts(i)
                Dim oConFace As Face
                For Each oConFace In oEdge.Faces
                    If oConFace Is oFace Then
                        GetPointOnCylinder = oPoints(i)
                    End If
                Next
            Case kFaceObject:
                GetPointOnCylinder = oPoints(i)
            End Select
        Next
    End If
End Function
    

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 9 of 10

Ralf_Krieg
Advisor
Advisor
Accepted solution

Sorry, there are some lines missing in the CheckExistLeader function.

Private Function CheckExistLeader(ByVal oRevolveFeature As RevolveFeature) As Boolean
    Dim oPartCompDef As PartComponentDefinition = oRevolveFeature.Parent
    Dim oLeaderNotes As ModelLeaderNotes = oPartCompDef.ModelAnnotations.ModelLeaderNotes
	Dim oFace As Face
    Dim oIntentFace As Face
    Dim oLeaderNote As ModelLeaderNote
    
	For Each oLeaderNote In oLeaderNotes
		oIntentFace = oLeaderNote.Definition.Intent.Geometry
		For Each oFace In oRevolveFeature.Faces
			If oIntentFace Is oFace Then
				Return True
			End If
		Next
    Next
End Function

R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 10 of 10

emilda.chiuye
Enthusiast
Enthusiast

Thanks so very much for this much needed helpful correction.

😁

0 Likes