Here is the last of four articles on Client Graphics. This was originally in a technical paper written by Autodesk Developer Network engineer Xiaodong Liang.
Note: Segment 3 is here.
This zip file has a VB.NET project with the examples discussed in this section.
Download ClientGraphics_Segment_4
Start of segment 4
Interaction Client Graphics
Interaction Client Graphics operate in a similar manner to regular ClientGraphics, except that it all happens in the context of InteractionEvents. ClientGraphics created via InteractionGraphics are optimized for this environment, and run much faster. They are well suited to real-time feedback during a command. As the client graphics are displayed in the context of an InteractionEvents object, they can take advantage of mouse movement information, selection information, in fact, any events supported by the InteractionEvents objects. These graphics are automatically removed once the associated InteractionEvents object stops.
The interaction graphics can be Preview or Overlay. Preview graphics are equivalent to regular Client Graphics. The only difference between Overlay and Preview graphics is that Overlay graphics can be drawn independently, in a single view (window), and then merged with the last full redraw of the scene by drawing the graphics in a special "overlay" plane. It doesn't mean that the graphics are always drawn on top. You can position them anywhere you want and you can toggle the "burn through" option. In short, anything you can do with preview graphics you can do with overlay graphics.
The creation of interaction graphics is not transacted. This is done for performance reasons, and to avoid some side effects, like clearing of the selection set. This also means that transacting operations cannot be mixed with preview graphics.
‘<code snippet: interaction events (Overlay)>
‘start interaction event and get the overlay graphics
Dim oIE As InteractionEvents
Set oIE = ThisApplication.CommandManager.CreateInteractionEvents
oIE.Start
Dim oClientGraphics As ClientGraphics
Set oClientGraphics = oIG.OverlayClientGraphics
‘create line strip graphics
Dim oLineStrip As LineStripGraphics
Set oLineStrip = oLineStripNode.AddLineStripGraphics
' Assign the same coordinate set to the line strip.
oLineStrip.CoordinateSet = oCoordSet
' Update the view to see the resulting spiral.
oIG.UpdateOverlayGraphics ThisApplication.ActiveView
Store Client Graphics
In general, ClientGraphics will be maintained and transformed by Inventor for the duration of the session only. Using the GraphicsDataSetsCollection.Add method will allow the data to be saved with the file. When the document is opened, the ClientGraphics are persisted, and are still available to be further manipulated.
In Part or Assembly documents, you can attach client graphics to ClientFeature objects, so the graphics will be stored with document. The presumption is the graphics data is created by GraphicsDataSetsCollection.Add. In Drawing documents only the data can be saved. A developer’s application has to redraw the graphics using the client graphics data after the Drawing document has been re-opened.
‘<code snippet: store client graphics with client feature>
Dim invCF As ClientFeature
‘get/create ClientFeature
Dim invCFD As ClientFeatureDefinition
invCFD = invCF.Definition
‘Create & store graphics data
Dim oGraphicsData As GraphicsDataSets
Set oGraphicsData = oDoc.GraphicsDataSetsCollection.Add2("TestCG_StoreData", True)
‘create graphics in the ClientFeature
Dim oClientGraphics As Inventor.ClientGraphics
Set oClientGraphics = invCFD.ClientGraphicsCollection("ClientFeatureTest")
‘create graphics node
Dim oGraphicsNode As GraphicsNode
Set oGraphicsNode = oClientGraphics.AddNode(oClientGraphics.count + 1)
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) = 2: oPointCoords(7) = 0: oPointCoords(8) = 0
oPointCoords(9) = 3: oPointCoords(10) = 1: oPointCoords(11) = 0
Call oCoordSet.PutCoordinates(oPointCoords)
'Lines: totally, 2 lines
Dim oGraphic As LineGraphics
Set oGraphic = oGraphicsNode.AddLineGraphics
oGraphic.CoordinateSet = oCoordSet
Advanced Functionality
Slice
This provides the functionality that slices the graphics based on the input planes and optionally caps the sliced end.
Texture mapping
Texture mapping provides the ability to more accurately define color mapping to the model. For example, with the previous functionality you were limited to assigning colors to vertices and then relying on Inventor to interpolate the color across the triangle. If you had a plane constructed of two triangles you would not be able to define any intermediate colors between the vertices.
This is the end of this series. These posts will also be of interest:
AU Session - Client Graphics API Exposed
MFG DevBlog post - Complete ClientFeature example in C#
The Manufacturing DevBlog has other posts on Client Graphics as well. Also don’t forget the help file. It has examples for ClientGraphics too.
- Wayne