In my previous post I showed how to create your own iLogic function “GetProxyIntent()”. With that function it’s possible to get curves from geometry in an assembly and create an intent for it. But as I mentioned to have a good workflow, we are still missing some tools.

The standard iLogic environment will show labels on the faces that have been assigned a name. I have written code that will let you create your own labels. It will let you create labels anywhere you like and with any text that you want. (In fact you can customize everything to your wishes.) In an upcoming post I will use this to create labels on face that have been assigned a name.

The label is created with “Client graphics”. Client graphics provide the ability to draw custom graphics in the Inventor modeling window. But are not part of the model. Client graphics will be maintained for the duration of the session only. That means that the they will stop to exist as soon as you close the document and will not get saved.

I saved this as an external rule named “Label.iLogicVb”.

Imports Inventor

Public Class Label

    Private oClientGraphics As ClientGraphics
    Private oDataSets As GraphicsDataSets
    Private ThisApplication As Inventor.Application
	Private name As String
    Private orign As Point
    Public Sub New(doc As Document, name As String)
        Me.ThisApplication = doc.Parent

        Dim ClientGraphicsName = "hjalte.ClientGraphics-" & name
        Dim GraphicsDataSet = "hjalte.GraphicsDataSet-" & name

        Dim oCompDef As ComponentDefinition = doc.ComponentDefinition
        oClientGraphics = oCompDef.ClientGraphicsCollection.Item(ClientGraphicsName)
        oDataSets = doc.GraphicsDataSetsCollection.Item(GraphicsDataSet)

    End Sub
    Public Sub New(doc As Document, name As String, point1 As Point, vector As UnitVector)

        Me.ThisApplication = doc.Parent

        Dim oTg As TransientGeometry = ThisApplication.TransientGeometry
        Dim arrowLength As Double = 0.2
        Dim arrowRadius As Double = 0.05
        Dim labelLength As Double = 2 = name
        Me.orign = point1
        Dim point2 = oTg.CreatePoint(vector.X * labelLength + point1.X,
                                    vector.Y * labelLength + point1.Y,
                                    vector.Z * labelLength + point1.Z)
        Dim point3 = oTg.CreatePoint(vector.X * arrowLength + point1.X,
                                    vector.Y * arrowLength + point1.Y,
                                    vector.Z * arrowLength + point1.Z)

        Dim ClientGraphicsName = "hjalte.ClientGraphics-" & name
        Dim GraphicsDataSet = "hjalte.GraphicsDataSet-" & name

        'Dim doc As AssemblyDocument = ThisDoc.Document
        Dim oCompDef As ComponentDefinition = doc.ComponentDefinition

            oClientGraphics = oCompDef.ClientGraphicsCollection.Add(ClientGraphicsName)
            oDataSets = doc.GraphicsDataSetsCollection.Add(GraphicsDataSet)
        Catch ex As Exception
            oClientGraphics = oCompDef.ClientGraphicsCollection.Item(ClientGraphicsName)
            oDataSets = doc.GraphicsDataSetsCollection.Item(GraphicsDataSet)
            'Throw New Exception("Could not create label. Name was already used!")
        End Try

        Dim oSurfacesNode As GraphicsNode = oClientGraphics.AddNode(1)
        Dim oTransientBRep As TransientBRep = ThisApplication.TransientBRep

        Dim oBody As SurfaceBody = oTransientBRep.CreateSolidCylinderCone(point3, point1, arrowRadius, arrowRadius, 0)

        Dim oSurfaceGraphics As SurfaceGraphics = oSurfacesNode.AddSurfaceGraphics(oBody)
        oSurfaceGraphics.Color = ThisApplication.TransientObjects.CreateColor(0, 0, 0)

        Dim textGraphics As TextGraphics = oSurfacesNode.AddTextGraphics()
        textGraphics.Text = name
        textGraphics.Anchor = point2
        textGraphics.HorizontalAlignment = HorizontalTextAlignmentEnum.kAlignTextCenter
        textGraphics.VerticalAlignment = VerticalTextAlignmentEnum.kAlignTextMiddle
        textGraphics.Bold = True
        textGraphics.FontSize = 21
        textGraphics.PutTextColor(0, 255, 0)
        textGraphics.BurnThrough = True
        textGraphics.DepthPriority = -10000000

        Dim LineGraphic As LineGraphics = oSurfacesNode.AddLineGraphics()
        Dim oCoordSet As GraphicsCoordinateSet = oDataSets.CreateCoordinateSet(1)
        oCoordSet.Add(1, point1)
        oCoordSet.Add(2, point2)

        LineGraphic.CoordinateSet = oCoordSet

        Dim oGraphicsColorSet As GraphicsColorSet = oDataSets.CreateColorSet(1)
        oGraphicsColorSet.Add(1, 0, 0, 0)
        oGraphicsColorSet.Add(2, 0, 0, 0)
        LineGraphic.ColorSet = oGraphicsColorSet

    End Sub

    Public Sub delete()
    End Sub
End Class

Here is an example showing how you can use this class. 

AddVbFile "Label.iLogicVb"
Dim point As Point = ThisApplication.TransientGeometry.CreatePoint(0, 0, 0)
Dim vector As UnitVector = ThisApplication.TransientGeometry.CreateUnitVector(1, 0, 0)
Dim label As Label = New Label(ThisDoc.Document, "Label 1", point, vector)
' label.delete()

This will produce something like this.


It's possible to remove the label again with the delete() function. Calling that function is not a problem in the same rule as the Label was created. But in other rules you have find the label again and then call the delete() function. here is an example how to do that.

AddVbFile "Label.iLogicVb"
Dim label As Label = New Label(ThisDoc.Document, "Label 1")



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


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


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é


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