hmmmm...I'm not sure, but it was probably something related to toggling the color schemes... but there might be some hiccups with using the client graphics that I'm not familiar with, since I've not used that all that much
here's two other versions....
- a simpler version that just uses the tool tip and gets rid of all the color scheme and client graphics stuff
- and one that gets rid of all the color scheme stuff, and just writes the info to the tool tip and client graphics both
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
version that just uses tool tip
Sub main
'/////////// options
Dim oSelectionFilter As SelectionFilterEnum
'subassembly selection
oSelectionFilter = SelectionFilterEnum.kAssemblyOccurrenceFilter
'''uncomment this line to use part selection
'oSelectionFilter = SelectionFilterEnum.kAssemblyLeafOccurrenceFilter
oConversion = 1
oUnit = " kg"
'''uncomment these 2 lines to use lbs
' oConversion = 2.2046
' oUnit = " lbs mass"
'/////////// end options
Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oTotalMass As Double
Dim oList As New ArrayList
oSet = oDoc.CreateHighlightSet
Dim oCollection As ObjectCollection
oCollection = ThisApplication.TransientObjects.CreateObjectCollection
oMsg = "Select a component (press ESC to end selection)"
While True
Dim oOcc As ComponentOccurrence
oOcc = ThisApplication.CommandManager.Pick(
oSelectionFilter, oMsg)
' If nothing gets selected then we're done
If IsNothing(oOcc) Then Exit While
Dim oMassProps As MassProperties
oMassProps = oOcc.Definition.Document.ComponentDefinition.MassProperties
'check against list to prevent
'selecting same component twice
If oList.Contains(oOcc.Name) = False Then
oList.Add(oOcc.Name)
oCollection.Add(oOcc)
oTotalMass = oTotalMass + oMassProps.Mass
Else
oList.Remove(oOcc.Name)
oCollection.RemoveByObject(oOcc)
oTotalMass = oTotalMass - oMassProps.Mass
End If
oMsg = Round(oTotalMass * oConversion, 3) & oUnit _
& " ; " & oCollection.Count & " items selected"
oSet.AddMultipleItems(oCollection)
End While
InputBox("Total mass in " & oUnit, "ilogic", Round(oTotalMass * oConversion, 3))
oSet.Clear
End Sub
version that uses client graphics
Sub main
'/////////// options
Dim oSelectionFilter As SelectionFilterEnum
'subassembly selection
oSelectionFilter = SelectionFilterEnum.kAssemblyOccurrenceFilter
'''uncomment this line to use part selection
'oSelectionFilter = SelectionFilterEnum.kAssemblyLeafOccurrenceFilter
oConversion = 1
oUnit = " kg"
'''uncomment these 2 lines to use lbs
' oConversion = 2.2046
' oUnit = " lbs mass"
'/////////// end options
Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oTotalMass As Double
Dim oList As New ArrayList
oSet = oDoc.CreateHighlightSet
Dim oCollection As ObjectCollection
oCollection = ThisApplication.TransientObjects.CreateObjectCollection
oMsg = "Select a component (press ESC to end selection)"
While True
Dim oOcc As ComponentOccurrence
oOcc = ThisApplication.CommandManager.Pick(
oSelectionFilter, oMsg)
' If nothing gets selected then we're done
If IsNothing(oOcc) Then Exit While
Dim oMassProps As MassProperties
oMassProps = oOcc.Definition.Document.ComponentDefinition.MassProperties
'check against list to prevent
'selecting same component twice
If oList.Contains(oOcc.Name) = False Then
oList.Add(oOcc.Name)
oCollection.Add(oOcc)
oTotalMass = oTotalMass + oMassProps.Mass
Else
oList.Remove(oOcc.Name)
oCollection.RemoveByObject(oOcc)
oTotalMass = oTotalMass - oMassProps.Mass
End If
oMsg = Round(oTotalMass * oConversion, 3) & oUnit _
& " ; " & oCollection.Count & " items selected"
Call WriteClientGraphics(oMsg)
oSet.AddMultipleItems(oCollection)
End While
Call ClearGraphics
End Sub
Sub WriteClientGraphics(oLine1 As String)
oFont = "Stylus BT"
oFontSize = 35
Dim oDoc As Document = ThisApplication.ActiveDocument
' a reference to the component definition.
Dim oCompDef As ComponentDefinition
oCompDef = oDoc.ComponentDefinition
Call ClearGraphics
oClientGraphics = oCompDef.ClientGraphicsCollection.Add("Text Test")
Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry
Dim oAnchorPoint As Point
oAnchorPoint = oTG.CreatePoint(0, 1, 1)
' Create a graphics node.
Dim oNode As GraphicsNode
oNode = oClientGraphics.AddNode(1)
'[ Text1
Dim oTextGraphics1 As TextGraphics
oTextGraphics1 = oNode.AddTextGraphics
oTextGraphics1.Text = oLine1
' Set the text's anchor in model space.
oTextGraphics1.Anchor = oAnchorPoint
' Anchor the text graphics in the view.
Call oTextGraphics1.SetViewSpaceAnchor( _
oAnchorPoint, oTG.CreatePoint2d(40, 40), kTopLeftViewCorner)
oTextGraphics1.Font = oFont
oTextGraphics1.FontSize = oFontSize
'oTextGraphics1.PutTextColor(0, 0, 0) 'black
'oTextGraphics1.PutTextColor(255, 0, 0) 'red
'oTextGraphics1.PutTextColor(0, 255, 0) 'green
oTextGraphics1.PutTextColor(0, 0, 255) 'blue
ThisApplication.ActiveView.Update
']
End Sub
Function ClearGraphics
' a reference to the component definition.
Dim oCompDef As ComponentDefinition
oCompDef = ThisApplication.ActiveDocument.ComponentDefinition
' Attempt to get the existing client graphics object. If it exists
' delete it so the rest of the code can continue as if it never existed.
Dim oClientGraphics As ClientGraphics
On Error Resume Next
oClientGraphics = oCompDef.ClientGraphicsCollection.Item("Text Test")
If Err.Number = 0 Then
oClientGraphics.Delete
End If
On Error GoTo 0
ThisApplication.ActiveView.Update
End Function
