Inventor 2024 Finish

Inventor 2024 Finish

florescu.d95
Enthusiast Enthusiast
1,139 Views
4 Replies
Message 1 of 5

Inventor 2024 Finish

florescu.d95
Enthusiast
Enthusiast

Inventor 2024's Finish feature is definitely something useful, especially when you can create your custom processes ie. powder coating,  electroplating, etc.

Does anyone know a way to automate the creation process?

For example, I have an appearance category named "Powder Coating" and I would like to create a process for all the appearances in that category.

I managed to do 1 of them by manually editing the XML file but there are 100s of RAL Colours.

 

Screenshot 2023-03-30 220737.jpg

 

.

1,140 Views
4 Replies
Replies (4)
Message 2 of 5

AlexFielder
Advisor
Advisor

hi @florescu.d95 

 

As I mentioned on LinkedIn, there is an API sample that details adding an existing AppearanceAsset from the Autodesk Appearance Library and uses that to create a FinishDefinition in a PartDocument:

 

https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=FinishFeatureCreation_Sample

 

In theory you could point that code at the RAL Appearance Library instead and in your part template file, add a series of finishdefinitions for use by you/your team.

 

To save time, I had ChatGPT convert the VBA Sample above  to VB.NET:

 

Sub FinishFeatureSample()
' Create a new part document.
Dim oPartDoc As PartDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject)

' Set a reference to the component definition.
Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition

' Create a new sketch on the X-Y work plane.
Dim oSketch As PlanarSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes.Item(3))

' Set a reference to the transient geometry object.
Dim oTransGeom As TransientGeometry = ThisApplication.TransientGeometry

' Draw a 4cm x 3cm rectangle with the corner at (0,0)
Dim oRectangleLines As SketchEntitiesEnumerator = oSketch.SketchLines.AddAsTwoPointRectangle( _
oTransGeom.CreatePoint2d(0, 0), _
oTransGeom.CreatePoint2d(4, 3))

' Create a profile.
Dim oProfile As Profile = oSketch.Profiles.AddForSolid

' Create a base extrusion 1cm thick.
Dim oExtrudeDef As ExtrudeDefinition = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, PartFeatureOperationEnum.kJoinOperation)
oExtrudeDef.SetDistanceExtent(1, PartFeatureExtentDirectionEnum.kNegativeExtentDirection)
Dim oExtrude1 As ExtrudeFeature = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef)

' Get the top face of the extrusion to use for creating the new sketch.
Dim oFrontFace As Face = oExtrude1.StartFaces.Item(1)

Dim oGeometries As FaceCollection = ThisApplication.TransientObjects.CreateFaceCollection

oGeometries.Add(oFrontFace)

Dim oFinishFeatures As FinishFeatures = oCompDef.Features.FinishFeatures

Dim oAppearance As Asset
' Get an appearance asset from library: Autodesk Appearance Library
ThisApplication.AssetLibraries.Item("314DE259-5443-4621-BFBD-1730C6CC9AE9").AppearanceAssets.Item("Red").CopyTo(oPartDoc)
oAppearance = oPartDoc.AppearanceAssets.Item("Red")

' Create finish definition.
Dim oFinishDef As FinishDefinition = oFinishFeatures.CreateFinishDefinition(oGeometries, FinishTypeEnum.kAppearanceFinishType, Nothing, oAppearance)

' Create finish feature.
Dim oFinish As FinishFeature = oFinishFeatures.Add(oFinishDef)

End Sub

 

 

I then made short work of writing a function (with some help from ChatGPT because I am lazy 😉 ) that accepts two arguments; AppearanceLibraryName and AppearanceName, and an optional ProcessName:

 

 

Public Function CreateFinishFeature(ByVal AppearanceLibraryName As String, ByVal AppearanceName As String, ByVal oGeometries as FaceCollection, Optional ProcessName as String) As FinishFeature
    Dim oPartDoc As PartDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject)
    Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition
    
    ' Get an appearance asset from the specified library
    Dim oAppearance As Asset = ThisApplication.AssetLibraries(appearanceLibraryName).AppearanceAssets(appearanceName).CopyTo(oPartDoc)
    Dim oFinishFeatures As FinishFeatures = oCompDef.Features.FinishFeatures
    Dim oFinishDef As FinishDefinition 
    If ProcessName isNot Nothing Then
        oFinishDef = oFinishFeatures.CreateFinishDefinition(oGeometries, FinishTypeEnum.kAppearanceFinishType, ProcessName, oAppearance)
    Else
        oFinishDef = oFinishFeatures.CreateFinishDefinition(oGeometries, FinishTypeEnum.kAppearanceFinishType, , oAppearance)
    End If
    Dim myFinishFeature As FinishFeature = oFinishFeatures.Add(oFinishDef)
    
    Return myFinishFeature
End Function

 

 

EDIT: So I spent a bit of time editing the above to make it work:

 

Sub Main
	
	' Get a feature selection from the user
    Dim oObject As Object = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick a face")
	Dim oGeometries As FaceCollection = ThisApplication.TransientObjects.CreateFaceCollection
    
	oGeometries.Add(oObject)
	
	Dim AssetLibraryList As List(Of String) = (From AL As AssetLibrary In ThisApplication.AssetLibraries
											Select AL.DisplayName).ToList()
	
	Dim SelectedLibrary As String = InputListBox("Select an existing, connected Asset Library:", AssetLibraryList, Nothing, Title := "Inventor Asset Libraries", ListName := "Library List")
	
	If SelectedLibrary = "" Then Throw New Exception("You didn't pick anything!")
		
	Dim AssetList As List(Of String) = (From APP As Asset In ThisApplication.AssetLibraries(SelectedLibrary).AppearanceAssets
												Select APP.DisplayName).ToList()
	
	Dim SelectedAsset = InputListBox("Select an Appearance:", AssetList, Nothing, Title := SelectedLibrary & " Assets", ListName := "AssetList")

	If SelectedAsset = "" Then Throw New Exception("You didn't pick anything!")
	
	Dim myFinishFeature As FinishFeature = CreateFinishFeature(SelectedLibrary, SelectedAsset, oGeometries, "Powder Coating")

	'Or

'	myFinishFeature = CreateFinishFeature("RAL Library", "Red", oGeometries)
End Sub

Public Function CreateFinishFeature(ByVal AppearanceLibraryName As String, ByVal AppearanceName As String, ByVal oGeometries As FaceCollection, Optional ProcessName As String = "") As FinishFeature
    If Not TypeOf ThisApplication.ActiveDocument Is PartDocument Then Throw New Exception("NOt a part file!")
	
	Dim oPartDoc As PartDocument = ThisApplication.ActiveDocument
    Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition
    
    ' Get an appearance asset from the specified library
    Dim oAppearance As Asset = ThisApplication.AssetLibraries(AppearanceLibraryName).AppearanceAssets(AppearanceName).CopyTo(oPartDoc)
    Dim oFinishFeatures As FinishFeatures = oCompDef.Features.FinishFeatures
    Dim oFinishDef As FinishDefinition 
    If ProcessName IsNot Nothing Then
        oFinishDef = oFinishFeatures.CreateFinishDefinition(oGeometries, FinishTypeEnum.kAppearanceFinishType, ProcessName, oAppearance)
    Else
        oFinishDef = oFinishFeatures.CreateFinishDefinition(oGeometries, FinishTypeEnum.kAppearanceFinishType, , oAppearance)
    End If
    Dim myFinishFeature As FinishFeature = oFinishFeatures.Add(oFinishDef)
	
	myFinishFeature.Name = IIf(ProcessNAme = "", AppearanceName, AppearanceName & " - " & ProcessName)
    
    Return myFinishFeature
End Function

🙂

 

0 Likes
Message 3 of 5

AlexFielder
Advisor
Advisor

I realised on reading the above submission that it doesn't really answer OP's question. To that end, please hold...

0 Likes
Message 4 of 5

AlexFielder
Advisor
Advisor

EDIT: So this code is a guaranteed crash in Inventor 2024:

 

All you need to run it is a part file with a single body, pick a face, select the appearance library of your choice and watch the magic smoke escape:

 

Sub Main
	
	' Get a feature selection from the user
    Dim oObject As Object = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick a face")
	Dim oGeometries As FaceCollection = ThisApplication.TransientObjects.CreateFaceCollection
    
	oGeometries.Add(oObject)
	
	Dim AssetLibraryList As List(Of String) = (From AL As AssetLibrary In ThisApplication.AssetLibraries
											Select AL.DisplayName).ToList()
	
	Dim SelectedLibrary As String = InputListBox("Select an existing, connected Asset Library:", AssetLibraryList, Nothing, Title := "Inventor Asset Libraries", ListName := "Library List")
	
	If SelectedLibrary = "" Then Throw New Exception("You didn't pick anything!")
		
	CreateFinishFeaturesForLibrary(SelectedLibrary, oGeometries)
	
End Sub

Public Sub CreateFinishFeaturesForLibrary(ByVal libraryName As String, ByVal oGeometries As FaceCollection, Optional ProcessName As String = "")
    If Not TypeOf ThisApplication.ActiveDocument Is PartDocument Then Throw New Exception("NOt a part file!")
	
	Dim oPartDoc As PartDocument = ThisApplication.ActiveDocument
	
    Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition
    Dim oFinishFeatures As FinishFeatures = oCompDef.Features.FinishFeatures

    Dim oAppearanceLibrary As AssetLibrary = ThisApplication.AssetLibraries(libraryName)
	
	Dim i As Integer = 0
	
    For Each oAppearanceAsset As Asset In oAppearanceLibrary.AppearanceAssets
		if i = 10 then exit for 'crude attempt to prevent a hard-crash. Needless to say it doesn't work!
        Dim oAppearanceName As String = oAppearanceAsset.DisplayName
        Dim oAppearance As Asset = oAppearanceAsset.CopyTo(oPartDoc)
        Dim oFinishDef As FinishDefinition = oFinishFeatures.CreateFinishDefinition(oGeometries, FinishTypeEnum.kAppearanceFinishType, ProcessName, oAppearance)
        Dim myFinishFeature As FinishFeature = oFinishFeatures.Add(oFinishDef)
		myFinishFeature.Name = oAppearance.DisplayName
		i += 1
    Next

End Sub

 

With more time it may be possible to get this working seeing as you can manually add multiple FinishFeatures to the same face.

 

0 Likes
Message 5 of 5

florescu.d95
Enthusiast
Enthusiast

I've been thinking, it seems that the configuration for all the types is stored in an XML file except for the Appearance type. In my mind that would explain why when we replace " k.AppearanceFinishType" in the line below with "kPaintFinishType" we get an error.

 Dim oFinishDef As FinishDefinition = oFinishFeatures.CreateFinishDefinition(oGeometries, FinishTypeEnum.kAppearanceFinishType, ProcessName, oAppearance)

 

0 Likes