Here is the third of four articles on Client Graphics. This was originally in a technical paper written by Autodesk Developer Network engineer Xiaodong Liang.
Note: Segment 2 is here.
This zip file has a VB.NET project with the examples discussed in this section.
Download ClientGraphics_Segment_3
Start of segment 3
Using Index Sets
The Index Set provides a flexible way to arrange the coordinate set, color set and normal set (for triangles). For example, with the same coordinate data, the figure below, on the left, creates the line graphics from 1-2-3-4 where all lines have the same color, while the figure on the right creates the line from 1-3-2-4 and each line has a different color defined using an index set.
‘<code snippet: Line, With Coordinate Index Set and Color Set>
Dim oPointCoords(11) As Double 'create 4 points
oPointCoords(0) = 0: oPointCoords(1) = 0: oPointCoords(2) = 0
oPointCoords(3) = 1: oPointCoords(4) = 1: oPointCoords(5) = 0
oPointCoords(6) = 0: oPointCoords(7) = 1: oPointCoords(8) = 0
oPointCoords(9) = 1: oPointCoords(10) = 0: oPointCoords(11) = 0
Call oCoordSet.PutCoordinates(oPointCoords)
'Line strip: totally, 3 lines
Dim oGraphic As LineGraphics
Set oGraphic = oGraphicsNode.AddLineGraphics
oGraphic.LineWeight = 5
‘Create Coordinate Index Set
Dim oCoordinateIndex As GraphicsIndexSet
Set oCoordinateIndex = oDataSets.CreateIndexSet(oDataSets.count + 1)
oCoordinateIndex.Add 1, 1 'from point 1
oCoordinateIndex.Add 2, 3 'connect to point 3
oCoordinateIndex.Add 3, 3 'from point 3
oCoordinateIndex.Add 4, 2 'connect to point 2
oCoordinateIndex.Add 5, 2 'from point 2
oCoordinateIndex.Add 6, 4 'connect to point 4
'Create the color set: two colors.
Dim oColorSet As GraphicsColorSet
Set oColorSet = oDataSets.CreateColorSet(oDataSets.count + 1)
Call oColorSet.Add(1, 255, 0, 0)
Call oColorSet.Add(2, 0, 255, 0)
' Create the index set for color
Dim oColorIndex As GraphicsIndexSet
Set oColorIndex = oDataSets.CreateIndexSet(oDataSets.count + 1)
oColorIndex.Add 1, 2 'line 1 uses color 2
oColorIndex.Add 2, 1 'line 2 uses color 1
oColorIndex.Add 3, 2 'line 3 uses color 2
oGraphic.CoordinateSet = oCoordSet
oGraphic.CoordinateIndexSet = oCoordinateIndex
Using ‘Strip’ graphics
Strip Graphics are used to group the coordinates associated with a series of connected graphics objects and are only available with LineStrip, TriangleStrip or TriangleFan. You can specify the strip length. e.g. in the code below, points 1,2,3 are defined as one triangle strip, while points 4,5,6,7 are defined as another strip. Each strip is independent of the other strips. You can also specify the color for each.
‘<code snippet: Triangle Strip, Set Strip>
Dim oPointCoords(20) As Double ‘create 7 points,
oPointCoords(0) = 0: oPointCoords(1) = 0: oPointCoords(2) = 0
oPointCoords(3) = 1: oPointCoords(4) = 1: oPointCoords(5) = 0
oPointCoords(6) = 2: oPointCoords(7) = 0: oPointCoords(8) = 0
oPointCoords(9) = 3: oPointCoords(10) = 1: oPointCoords(11) = 0
oPointCoords(12) = 4: oPointCoords(13) = 0: oPointCoords(14) = 0
oPointCoords(15) = 5: oPointCoords(16) = 1: oPointCoords(17) = 0
oPointCoords(15) = 5: oPointCoords(16) = 1: oPointCoords(17) = 0
oPointCoords(18) = 6: oPointCoords(19) = 0: oPointCoords(20) = 0
Call oCoordSet.PutCoordinates(oPointCoords)
‘or Triangle Strip: totally 5 triangles
Dim oGraphic As TriangleStripGraphics
Set oGraphic = oGraphicsNode.AddTriangleStripGraphics
Dim oStrip(1) As Long
oStrip(0) = 3 ‘ point 1,2,3 for strip 1
oStrip(1) = 4 ‘ point 4,5,6,7 for strip 2
oGraphic.PutStripLengths oStrip
'Create the color set: two colors.
Dim oColorIndex As GraphicsIndexSet
Set oColorIndex = oDataSets.CreateIndexSet(oDataSets.count + 1)
oColorIndex.Add 1, 1
oColorIndex.Add 2, 2
oColorIndex.Add 3, 1
oColorIndex.Add 4, 2
oColorIndex.Add 5, 1
' Create the index set for color
Dim oColorSet As GraphicsColorSet
Set oColorSet = oDataSets.CreateColorSet(oDataSets.count + 1)
Call oColorSet.Add(1, 255, 0, 0)
Call oColorSet.Add(2, 0, 255, 0)
oGraphic.CoordinateSet = oCoordSet
oGraphic.ColorIndexSet = oColorIndex
oGraphic.ColorSet = oColorSet
oGraphic.ColorBinding = kPerStripColors
Using Model Native Data
Most scenarios where Client Graphics are required are based on the models native geometry. It is quite easy to get the data using Inventor API objects. e.g. SurfaceBody, Face, Edge, Vertex in Part or Assembly Documents, and DrawingCurve in drawing documents. The code below creates and transforms a surface using an existing SurfaceBody from the model.
It is also possible to obtain a coordinate data set from the existing SurfaceBody, Edge or Face objects using the CalculateStrokes method. You determine the tolerance (the number of points you need) by first calling GetExistingStrokeTolerances. You may need to do this multiple times in order to assess the average tolerance for the model. Similarly, obtain triangular facets from a SurfaceBody or Face using CalculateFacets.
‘<code snippet: Using model native data>
Dim oPartDef As PartComponentDefinition
Set oPartDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim oTransientBRep As TransientBRep
Set oTransientBRep = ThisApplication.TransientBRep
‘by Transient Brep class to copy the surface body
Dim oBody As SurfaceBody
Set oBody = oTransientBRep.Copy(oCompDef.SurfaceBodies.Item(1))
' Create client graphics based on the transient body
Dim oSurfaceGraphics As SurfaceGraphics
Set oSurfaceGraphics = oSurfacesNode.AddSurfaceGraphics(oBody)
‘move the graphics to a new location
Dim oMatrix As Matrix
Set oMatrix = ThisApplication.TransientGeometry.CreateMatrix
oMatrix.SetTranslation ThisApplication.TransientGeometry.CreateVector(0, 0, 100)
Basic Properties
Graphics has some properties to control the basic behavior.
Render Style
By default, the linetype, lineweight and color will use the settings on RenderStyle until they are overridden by LineType, LineWeight, Color (for Curve and Surface objects), and ColorSet (for Line, Triangle and TriangleFan objects).
Point Style
Specific to Point objects only, and controls the point style.
Visibility
Controls whether or not the graphics are visible.
Selectable
Specifies whether client graphics can be selected when the Select command is running.
Burn Through
This specifies whether or not graphics are always visible even if they are blocked by other objects.
Transformation
This property is used to transform a graphics node.
Transform Behavior
Two special transform behaviors: front facing and pixel scaling.
• Front Facing
Client graphics with this property do not rotate as the view is rotated but maintain the same orientation on the screen. They are positioned at a specified location within model space and their position on the screen will change as the view is zoomed in and out and scrolled, but their orientation will not change.
• Pixel Scaling
Here client graphics maintain the same size and position relative to the screen. As the user zooms in and out in the graphic window, these objects remain static.
Any graphics object can also have no transform behavior (which means it's size, position, and orientation are maintained relative to model space), front facing, pixel scaling, or front facing & pixel scaling. By default an object has no transform behavior, with the exception of text. Text always has front facing behavior regardless of the behavior type set through this method.
Anchor Behavior
This will anchor the primitive in view space so that the graphics will display in one fixed position, no matter how the view changes.
End of Segment 3
- Wayne