Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Hello @robbeRtek,

 

I gave it a try and changed the code. The only problem is that not every overwrite is allowed to be reset to default. We also have colored areas that have to stay that way.

 

I tried to replace the highlight set with another collection in which the colors are stored. The part with the selection and deselection with CTRL works so far. However, inventor always stops when the areas are to be set to their original color while calculating the area. But that also seems to be a bug. If I display a message box beforehand, everything goes through as desired.

 

Edit: If I separate the calculation of the area and the recoloring and put the output of the calculation results in between, the problem is gone. However, this can only be implemented for individual parts and so the original problem remains because the highlight set would be the way to go for an assembly.

 

 

 

'Definition
Dim oApp As Inventor.Application = ThisApplication
Dim oDoc As PartDocument = ThisApplication.ActiveDocument
Dim oCompDef As ComponentDefinition
oCompDef = oDoc.ComponentDefinition

Dim oStartFace,oFace As Inventor.Face '= Nothing
Dim AreaCache As Double = 0
Dim FaceCol As New Collection
FaceCol.Clear
Dim ColorCol As New Collection
ColorCol.Clear
Dim oHSet As HighlightSet = oDoc.CreateHighlightSet()
oHSet.Clear

' Definition der transienten Geometrie
Dim oTransObj As TransientObjects
oTransObj = oApp.TransientObjects

Dim docAsset As Assets
docAsset = oDoc.Assets

Dim oAssetLib As AssetLibrary
oAssetLib = oApp.AssetLibraries.Item("Autodesk Darstellungs-Bibliothek") 'Autodesk Appearance Library

Dim oColor As String
oColor = "Markierung"

' Get an asset In the library
Dim oHighlightColor As Asset

Try 'Copy the asset locally.
	oHighlightColor = docAsset.Item(oColor)
Catch 'or just use it if it's already local
	oHighlightColor = docAsset.Add(AssetTypeEnum.kAssetTypeAppearance, "Generic", oColor, oColor)
	Dim generic_highlight_color As ColorAssetValue
	generic_highlight_color = oHighlightColor.Item("generic_diffuse")
	generic_highlight_color.Value = oHSet.Color

End Try

'wenn fertig, starte von vorn
TheStart:

While True
	Dim k As Integer
	k = 1
	Dim bNEW As Boolean
	bNEW = True
	
	oStartFace = oApp.CommandManager.Pick(Inventor.SelectionFilterEnum.kPartFaceFilter, "Fläche anwählen + ""Esc"" bestätigen.") 
	
	' If nothing gets selected then we're done	
	If oStartFace Is Nothing Then Exit While
	
	
	'wenn STRG gedrückt wird, sollen bereits selektierte Flächen wieder abgewählt werden
	If System.Windows.Forms.Control.ModifierKeys = System.Windows.Forms.Keys.Control Then 'STRG wird gedrückt beim Selektieren
		If FaceCol.Count>0 Then
			For k = 1 To FaceCol.Count
				oFace= FaceCol.Item(k)
				If oFace.InternalName = oStartFace.InternalName Then
					bNEW = False
					Exit For
				End If
			Next
			
		End If
		If bNEW = False
			FaceCol.Remove(k)
			oFace.Appearance = ColorCol.Item(k)
			ColorCol.Remove(k)
			'oHSet.Remove(oFace)
			oApp.ActiveView.Update
		End If
	Else 'STRG wird nicht gedrückt beim selektieren
		If FaceCol.Count>0 Then
			For k = 1 To FaceCol.Count
				oFace= FaceCol.Item(k)
				If oFace.InternalName = oStartFace.InternalName Then
					bNEW = False
					Exit For
				End If
			Next
		End If
		If bNEW = True Then
			FaceCol.Add(oStartFace)
			ColorCol.Add(oStartFace.Appearance)
			oStartFace.Appearance = oHighlightColor
			'oHSet.AddItem(oStartFace)
			oApp.ActiveView.Update
		End If
	End If
	
	oStartFace = Nothing

End While

MessageBox.Show("random message")

'Berechenen der Flächeninhalte der Selektion
Dim i As Integer
If FaceCol.Count > 0 Then
	For i = 1 To FaceCol.Count
		oFace = FaceCol.Item(i)
		AreaCache = AreaCache + oFace.Evaluator.Area
		oFace.Appearance = ColorCol.Item(i)
		oApp.ActiveView.Update
	Next
End If


If AreaCache = 0 Then Return

'Ausgabe Flächeninhalt
AreaCache = Math.Round(AreaCache*100,1)
MessageBox.Show(AreaCache & "mm²")
'oCompDef.ClearAppearanceOverrides() 'Alle farbig veränderten Flächen werden auf Standard gesetzt
oHSet.Clear
FaceCol.Clear
ColorCol.Clear
AreaCache = 0

'if done, go to the start
GoTo TheStart