Last week I created a class that will let you add labels to models. This week I created a rule to show/hide labels from named faces. To make this work we need to know which attributes are used for named faces.

For this I will use the attributes I proposed in an earlier post “Add function GetProxyIntent() to Ilogic”. (Autodesk has not implemented this feature therefore I proposed my own attributes.)  Finding the named faces with the attributes is not that difficult. But adding a label to the faces is a bit of a challenge. I want the labels to point at the middle of the named face. Also, I need the arrow to be perpendicular to the face. (Perpendicular at the point of the arrow. That is imported for curved faces).

Brian Ekins wrote a paper “How Deep is the Rabbit Hole? Examing the Matrix and other Inventor math and geometry objects” for the Autodesk university 2008 . It’s a very interesting paper and I would recommend it to anyone. The one thing that is interesting for now is the chapter about “Surfaces”. It describes how to get the center and the normal of a face. The normal happens to be a vector that is perpendicular to the face at a point.

With all this information I created the following rule that will show labels for each named face in a assembly. For this rules to work you need to class/rule from my previous post “Label.iLogicVb”

AddVbFile "Label.iLogicVb"
Sub Main()
    Dim doc As AssemblyDocument = ThisDoc.Document
	
    Dim objs As ObjectCollection = doc.AttributeManager.FindObjects("iLogicEntityNameSet", "iLogicProxyEntityName")
    Dim labels As List(Of Label) = New List(Of Label)()
    For Each obj As Object In objs

        If TypeOf obj Is Inventor.FaceProxy Then
            Dim face As Face = obj
            Dim attSet As AttributeSet = face.AttributeSets.Item("iLogicEntityNameSet")
            Dim att As Attribute = attSet.Item("iLogicProxyEntityName")
			Try
				Dim l As Label = addLabelToFace(face, att.Value)
            	labels.Add(l)
			Catch
			End Try
        End If
    Next
End Sub

Private Function addLabelToFace(face As FaceProxy, name As String) As Label

    Dim occ As ComponentOccurrence = face.Parent.Parent

    Dim Params(0 To 3) As Double
    Dim points(0 To 3) As Double
    Dim normals(0 To 3) As Double

    Dim eval As SurfaceEvaluator = face.Evaluator
    Dim box As Box2d = eval.ParamRangeRect
    Params(0) = (box.MaxPoint.X - box.MinPoint.X) / 2 + box.MinPoint.X
    Params(1) = (box.MaxPoint.Y - box.MinPoint.Y) / 2 + box.MinPoint.Y
    face.Evaluator.GetPointAtParam(Params, points)
    face.Evaluator.GetNormalAtPoint(points, normals)

    Dim oPoint As Point = ThisApplication.TransientGeometry.CreatePoint(points(0), points(1), points(2))
    oPoint.TransformBy(occ.Transformation)
    Dim normal As UnitVector = ThisApplication.TransientGeometry.CreateUnitVector(normals(0), normals(1), normals(2))

    Return New Label(ThisDoc.Document, name, oPoint, normal)
End Function

 

I guess that the function “addLabelToFace()” could also be use full in other function.

But now we have the labels added the faces. Now we only need a way to remove them. Closing the document to remove them is not very user-friendly. The following rule will remove all labels.

AddVbFile "Label.iLogicVb"

Dim doc As AssemblyDocument = ThisDoc.Document
Dim objs As ObjectCollection = doc.AttributeManager.FindObjects("iLogicEntityNameSet", "iLogicProxyEntityName")
Dim labels As List(Of Label) = New List(Of Label)()
For Each obj As Object In objs
    If TypeOf obj Is Inventor.FaceProxy Then
        Dim face As Face = obj
        Dim attSet As AttributeSet = face.AttributeSets.Item("iLogicEntityNameSet")
        Dim att As Attribute = attSet.Item("iLogicProxyEntityName")
        Dim label As Label = New Label(doc, att.Value)
        labels.Add(label)
    End If
Next

For Each label As Label In labels
    label.delete()
Next

Skills:

Autodesk Inventor, Vault, Git, C#, vb, .net, php HTML, css, js

Education:

University computer science.
HBO Mechanical engineer.
MBO Fine mechanics.

Experience:

Programmer and Mechanical engineer at Kelvion
(2016 - 20..)

Mechanical engineer at Strukton
(2009 - 2016)

Mechanical engineer at RDG-engineering
(2007 - 2009)

CNC Programmer at VMC
(2005 - 2007)

volunteer at Taizé
(2007)

Certifications:

Objectgeoriënteerd analyseren en ontwerpen, Objectgeoriënteerd programmeren in Java, Webapplicaties: de clientkant, Databases, Security Aware Programmer, Web Security Specialist