By Wayne Brill
Issue
I need to create ClientGraphics that are transparent. I use the RenderStyle property of a ClientNode and set it to a render style that is transparent. In Inventor 2012 my ClientGraphics are not transparent. The same code running in Inventor 2011 was transparent. Is there a way to get the ClientGraphics to be transparent in 2012?
Solution
The solution in the 2012 release is to call RenderStyle soon after the ClientNode is created. This VBA example that is an update from the help file will help explain. Notice that RenderStyle() for the GraphicsNode is called right after it is created.
Note: Behavior does not occur in Inventor 2013.
Public Sub DrawCustomTriangles()
Dim oDoc As Document
Set oDoc = ThisApplication.ActiveDocument
' Set a reference to component definition of
' the active document. This assumes that a part
' or assembly document is active.
Dim oCompDef As ComponentDefinition
Set oCompDef = ThisApplication.ActiveDocument _
.ComponentDefinition
' Check to see if the test graphics data object
' already exists. If it does clean up by removing
' all associated of the client graphics from the
'document. If it doesn't create it and draw a line.
On Error Resume Next
Dim oGraphicsData As GraphicsDataSets
Set oGraphicsData = oDoc.GraphicsDataSetsCollection _
.Item ("SampleGraphicsID")
If Err.Number = 0 Then
On Error GoTo 0
' An existing client graphics object was
'successfully obtained so clean up.
oGraphicsData.Delete
oCompDef.ClientGraphicsCollection.Item _
("SampleGraphicsID").Delete
' update the display to see the results.
ThisApplication.ActiveView.Update
Else
Err.Clear
On Error GoTo 0
' Set a reference to the transient geometry
' object for user later.
Dim oTransGeom As TransientGeometry
Set oTransGeom = ThisApplication.TransientGeometry
' Create a graphics data set object. This object
' contains all of the
' information used to define the graphics.
Dim oDataSets As GraphicsDataSets
Set oDataSets = oDoc.GraphicsDataSetsCollection _
.Add ("SampleGraphicsID")
' Create a coordinate set.
Dim oCoordSet As GraphicsCoordinateSet
Set oCoordSet = oDataSets.CreateCoordinateSet(1)
' Get the number of sides for the cylinder.
Dim iSideCount As Long
iSideCount = InputBox _
("Enter number of sides for cylinder.(Must be greater than 2.)", _
"Cylinder Tolerance", 25)
Dim dRadius As Double
Dim dHeight As Double
dRadius = 3
dHeight = 7
' Create an array containing points to used
' in drawing the cylinder. The points could also
' be directly defined in a coordinate set, but
' defining them in array and then setting the
' coordinates using the
' array is more efficient for a large set of points.
Dim adPointCoords() As Double
ReDim adPointCoords _
(1 To ((iSideCount + 1) * 2) * 3) As Double
Dim i As Long
Dim dAngle As Double
' Define the points for the outline of
'the first end of the cylinder.
dAngle = 0
For i = 0 To iSideCount - 1
adPointCoords(i * 3 + 1) = dRadius * Cos(dAngle)
adPointCoords(i * 3 + 2) = dRadius * Sin(dAngle)
adPointCoords(i * 3 + 3) = 0
' Increment the angle for the next point
dAngle = dAngle + _
((2 * 3.14159265358979) / iSideCount)
Next
' Define the points for the outline of the other
' end of the cylinder.
dAngle = 0
For i = iSideCount To (iSideCount * 2) - 1
adPointCoords(i * 3 + 1) = dRadius * Cos(dAngle)
adPointCoords(i * 3 + 2) = dRadius * Sin(dAngle)
adPointCoords(i * 3 + 3) = dHeight
' Increment the angle for the next point
dAngle = dAngle + _
((2 * 3.14159265358979) / iSideCount)
Next
' Define coordinate at the center of the
'first end of the cylinder.
adPointCoords((iSideCount * 2) * 3 + 1) = 0
adPointCoords((iSideCount * 2) * 3 + 2) = 0
adPointCoords((iSideCount * 2) * 3 + 3) = 0
' Define coordinate at the center of the other
' end of the cylinder.
adPointCoords((iSideCount * 2) * 3 + 4) = 0
adPointCoords((iSideCount * 2) * 3 + 5) = 0
adPointCoords((iSideCount * 2) * 3 + 6) = dHeight
' Assign the points to the coordinate set.
Call oCoordSet.PutCoordinates(adPointCoords)
' Create an index set to use for the triangle fan for
' cap of the first end of the cylinder. This will
' serve as in index look-up into the coordinate set.
Dim oCap1Index As GraphicsIndexSet
Set oCap1Index = oDataSets.CreateIndexSet(1)
' Set the index values. This could also be done
' by setting the value in an array and then using
' the array to set the values of the index set.
' Using an array is more efficient, but this
' is used to here to demonstrate the IndexSet
' object's Add method.
Call oCap1Index.Add(1, iSideCount * 2 + 1)
Call oCap1Index.Add(2, 1)
Call oCap1Index.Add(3, 2)
For i = 4 To iSideCount + 1
Call oCap1Index.Add(i, i - 1)
Next
Call oCap1Index.Add(iSideCount + 2, 1)
' Create an index set to use for the
' triangle fan of the other cylinder cap.
Dim oCap2Index As GraphicsIndexSet
Set oCap2Index = oDataSets.CreateIndexSet(2)
' Set the index values.
Call oCap2Index.Add(1, iSideCount * 2 + 2)
Call oCap2Index.Add(2, iSideCount + 1)
Call oCap2Index.Add(3, iSideCount + 2)
For i = 4 To iSideCount + 1
Call oCap2Index.Add(i, i + iSideCount - 1)
Next
Call oCap2Index.Add(iSideCount + 2, _
iSideCount + 1)
' Create an index set to use for the triangle
' strip that will
' define the sides of the cylinder.
Dim oCylinderIndex As GraphicsIndexSet
Set oCylinderIndex = oDataSets.CreateIndexSet(3)
' Define the index values in an array.
Dim iIndexValues() As Long
ReDim iIndexValues _
(1 To (iSideCount + 1) * 2) As Long
For i = 0 To iSideCount - 1
iIndexValues(i * 2 + 1) = i + 1
iIndexValues(i * 2 + 2) = i + iSideCount + 1
Next
iIndexValues(((iSideCount + 1) * 2) - 1) = 1
iIndexValues((iSideCount + 1) * 2) = iSideCount + 1
' Define the index values in the index set
' using the array.
Call oCylinderIndex.PutIndices(iIndexValues)
' Create the ClientGraphics object.
Dim oClientGraphics As ClientGraphics
Set oClientGraphics = oCompDef. _
ClientGraphicsCollection.Add("SampleGraphicsID")
' Create a new graphics node within the client
' graphics objects.
Dim oCylinderNode As GraphicsNode
Set oCylinderNode = oClientGraphics.AddNode(1)
'WB added
oCylinderNode.Selectable = True
'WB transparency works if called here
oCylinderNode.RenderStyle = _
oDoc.RenderStyles.Item("Red (clear)")
' Create a triangle fan for cap 1 of the cylinder.
Dim oCap1TriangleFan As TriangleFanGraphics
Set oCap1TriangleFan = _
oCylinderNode.AddTriangleFanGraphics
'WB it works here
'oCylinderNode.RenderStyle = _
'oDoc.RenderStyles.Item("Red (clear)")
' Set the coordinates and index set for the cap.
oCap1TriangleFan.CoordinateSet = oCoordSet
oCap1TriangleFan.CoordinateIndexSet = oCap1Index
' Create a triangle fan for cap 2 of the cylinder.
Dim oCap2TriangleFan As TriangleFanGraphics
Set oCap2TriangleFan = oCylinderNode. _
AddTriangleFanGraphics
' Set the coordinates and index set for the cap.
oCap2TriangleFan.CoordinateSet = oCoordSet
oCap2TriangleFan.CoordinateIndexSet = oCap2Index
' WB it works here for the previously added graphics
'oCylinderNode.RenderStyle = _
' oDoc.RenderStyles.Item ("Red (clear)")
' Create a triangle string for the sides of the cylinder.
Dim oCylinderStrip As TriangleStripGraphics
Set oCylinderStrip = oCylinderNode. _
AddTriangleStripGraphics
'WB does not work here
' oCylinderNode.RenderStyle = _
' oDoc.RenderStyles.Item("Red (clear)")
' Set the coordinates and index set for the cap.
oCylinderStrip.CoordinateSet = oCoordSet
oCylinderStrip.CoordinateIndexSet = oCylinderIndex
'oCylinderNode.RenderStyle = oDoc.RenderStyles.Item("Purple")
'WB Added
'WB this is not working here
' oCylinderNode.RenderStyle =
'oDoc.RenderStyles.Item("Blue (clear)")
' update the display to see the results.
ThisApplication.ActiveView.Update
' Define a normal for cap 1.
Dim oCap1Normals As GraphicsNormalSet
Set oCap1Normals = oDataSets.CreateNormalSet(1)
Call oCap1Normals.Add _
(1, oTransGeom.CreateUnitVector(0, 0, -1))
' Assign the normals to the cap.
oCap1TriangleFan.NormalSet = oCap1Normals
' Define a normal for cap 2.
Dim oCap2Normals As GraphicsNormalSet
Set oCap2Normals = oDataSets.CreateNormalSet(2)
Call oCap2Normals.Add _
(1, oTransGeom.CreateUnitVector(0, 0, 1))
' Assign the normals to the cap.
oCap2TriangleFan.NormalSet = oCap2Normals
' Create an array that contains the normals
' for each vertex of the cylinder.
Dim adNormals() As Double
ReDim adNormals _
(1 To ((iSideCount + 1) * 2) * 3) As Double
dAngle = 0
For i = 0 To iSideCount
Dim dX As Double
Dim dY As Double
dX = Cos(dAngle)
dY = Sin(dAngle)
adNormals(i * 6 + 1) = dX
adNormals(i * 6 + 2) = dY
adNormals(i * 6 + 3) = 0
adNormals(i * 6 + 4) = dX
adNormals(i * 6 + 5) = dY
adNormals(i * 6 + 6) = 0
' Increment the angle for the next normal.
dAngle = dAngle + _
((2 * 3.14159265358979) / iSideCount)
Next
' Create and set the normal set for the cylinder.
Dim oCylinderNormals As GraphicsNormalSet
Set oCylinderNormals = oDataSets.CreateNormalSet(3)
Call oCylinderNormals.PutNormals(adNormals)
' Assign the normals to the cylinder.
oCylinderStrip.NormalSet = oCylinderNormals
' Does not work here
' oCylinderNode.RenderStyle = _
'oDoc.RenderStyles.Item("Blue (clear)")
' update the display to see the results.
ThisApplication.ActiveView.Update
End If
End Sub