Have a look at the following example, which I have taken from my blog. It creates a label like this.
In the function: "Label.New(doc As Document, name As String, point1 As Point, vector As UnitVector)" I create a red cone-shaped SurfaceBody (and text and a line) using ClientGraphics.
Public Class ThisRule
Sub Main()
Dim orign As Point = ThisApplication.TransientGeometry.CreatePoint(0, 0, 0)
Dim direction As UnitVector = ThisApplication.TransientGeometry.CreateUnitVector(1, 0, 0)
Dim l1 As New Label(ThisDoc.Document, "www.hjalte.nl", orign, direction)
End Sub
End Class
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, 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
Me.name = 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 oCompDef As ComponentDefinition = doc.ComponentDefinition
Try
oClientGraphics = oCompDef.ClientGraphicsCollection.Add(ClientGraphicsName)
oDataSets = doc.GraphicsDataSetsCollection.Add(GraphicsDataSet)
Catch ex As Exception
oClientGraphics = oCompDef.ClientGraphicsCollection.Item(ClientGraphicsName)
oDataSets = doc.GraphicsDataSetsCollection.Item(GraphicsDataSet)
Return
End Try
' Create the cone!
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(255, 0, 0)
'Create text
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, 0, 255)
textGraphics.BurnThrough = True
textGraphics.DepthPriority = -10000000
'Create line
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
ThisApplication.ActiveView.Update()
End Sub
End Class
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Blog: hjalte.nl - github.com