adding components to an existing finish definition

adding components to an existing finish definition

HermJan.Otterman
Advisor Advisor
298 Views
4 Replies
Message 1 of 5

adding components to an existing finish definition

HermJan.Otterman
Advisor
Advisor

Hello everyone,

 

I have an assembly with some parts (only first level). I created a finish, but because there is also a pattern I want to add all components / ocurrences / bodies /proxies... to this finish. but it does not work. can someone help me? thx.

my code:

 

Private Sub addComponentsToFinish(samenstelling As Inventor.AssemblyDocument)

Dim compAssyDef As Inventor.AssemblyComponentDefinition
compAssyDef = samenstelling.ComponentDefinition

Dim finishFeatures As FinishFeatures = compAssyDef.Features.FinishFeatures
Dim objCol As ObjectCollection = _inventorApplication.TransientObjects.CreateObjectCollection()

For Each finish As Inventor.FinishFeature In finishFeatures

finish.Definition.IncludedEntities.Clear()
'Controleer of het een FinishFeature is
If finish.Type = Inventor.ObjectTypeEnum.kFinishFeatureObject Then

For Each oCompOcc As Inventor.ComponentOccurrence In compAssyDef.Occurrences
Dim compDef As ComponentDefinition = CType(oCompOcc.Definition, ComponentDefinition)
For Each oBody As SurfaceBody In compDef.SurfaceBodies
Dim oBodyProxy As SurfaceBodyProxy = Nothing
oCompOcc.CreateGeometryProxy(oBody, oBodyProxy)
objCol.Add(oBody)
Next
Next
'finish.SetAffectedBodies(objCol) '??
finish.Definition.IncludedEntities.Add(objCol) '??
End If
Next
End Sub

 

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes
299 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

Hi @HermJan.Otterman.  Your code is using a property that became available in 2025.1, and I am still using 2024.4, so I could not test this, but have a look at how I modified your code example below.  Since the 'ObjectCollection' is 'transient', it does not persist or exist after transferring data to or from somewhere, so we can not just edit its contents, when we are getting it from a property value, but would need to set a changed collection back to that property, as its value.  Also, pay attention that the 'Definition' property of this feature is 'Read/Write', which usually indicates that we will need to set a modified definition as its value, not simply edit the definition 'in-line', so to speak.

Private Sub addComponentsToFinish(samenstelling As Inventor.AssemblyDocument)
	Dim compAssyDef As Inventor.AssemblyComponentDefinition = samenstelling.ComponentDefinition
	Dim finishFeatures As FinishFeatures = compAssyDef.Features.FinishFeatures
	For Each finish As Inventor.FinishFeature In finishFeatures
		Dim oFinishDef As Inventor.FinishDefinition = finish.Definition
		Dim oInclEntsColl As Inventor.ObjectCollection = oFinishDef.IncludedEntities
		oInclEntsColl.Clear()
		'Controleer of het een FinishFeature is
		If finish.Type = Inventor.ObjectTypeEnum.kFinishFeatureObject Then
			For Each oCompOcc As Inventor.ComponentOccurrence In compAssyDef.Occurrences
				If oCompOcc.Suppressed Then Continue For
				Dim compDef As Inventor.ComponentDefinition = oCompOcc.Definition
				If TypeOf compDef Is VirtualComponentDefinition Then Continue For
				If TypeOf compDef Is WeldsComponentDefinition Then Continue For
				For Each oBody As Inventor.SurfaceBody In compDef.SurfaceBodies
					oInclEntsColl.Add(oBody)
				Next 'oBody
			Next 'oCompOcc
			oFinishDef.IncludedEntities = oInclEntsColl
			finish.Definition = oFinishDef
		End If
	Next 'finish
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

HermJan.Otterman
Advisor
Advisor

Thank you @WCrihfield for your reply,

 

I tried your code and it gives an error ( System.Runtime.InteropServices.COMException: unknown) on line oFinishDef.IncludedEntities = oInclEntsColl, maybe this is what you say, that the oFinishDef.IncludedEntities can not be changed? 

in my code it did not crash on that line, but it did also not change the number of entities).

I also tried to create a new definition, but it did not work. the example form autodesk is in a part...

i will try some more

 

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor

In 2024, the FinishFeatures.CreateFinishDefinition method asked for a FaceCollection, then we had the FinishDefinition.InputFaces property, which was Read/Write, but I guess in 2025 they started allowing SurfaceBody objects also, and now using an ObjectCollection.  I assumed that since we are accessing the ComponentOccurrence.SurfaceBodies collection of top level components that those should already be 'in context' of the assembly (already proxies).  Whereas, if we were using ComponentOccurrence.Definition.SurfaceBodies collection, then we would definitely need to create 'proxies', because those would be the original bodies in the 'context' of the component's definition.  So I'm not sure context is the issue here.  I see the FinishFeature.RemoveParticipant method, which is meant for use in an assembly, but only accepts a whole ComponentOccurrence as input, not individual faces or bodies.  But then there is no 'AddParticipant(s)' method(s), which is a bit odd.  I just assumed that the FinishFeature.SetAffectedBodies was only for use in the context of a part, but the documentation does not say one way or the other, so maybe it will work in an assembly too, if getting the bodies from the ComponentOccurrence.SurfaceBodies collection.  Worth testing though.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 5

HermJan.Otterman
Advisor
Advisor

hi  @WCrihfield ,

 

when I take your code and put in the proxy part than it works but not as I would expect...

 

 Private Sub addComponentsToFinish2(samenstelling As Inventor.AssemblyDocument)
Dim compAssyDef As Inventor.AssemblyComponentDefinition = samenstelling.ComponentDefinition
Dim finishFeatures As FinishFeatures = compAssyDef.Features.FinishFeatures
For Each finish As Inventor.FinishFeature In finishFeatures
Dim oFinishDef As Inventor.FinishDefinition = finish.Definition
Dim oInclEntsColl As Inventor.ObjectCollection = oFinishDef.IncludedEntities
oInclEntsColl.Clear()
'Controleer of het een FinishFeature is
If finish.Type = Inventor.ObjectTypeEnum.kFinishFeatureObject Then
For Each oCompOcc As Inventor.ComponentOccurrence In compAssyDef.Occurrences
'If oInclEntsColl.Count >= 13 Then Exit For
If oCompOcc.Suppressed Then Continue For
Dim compDef As Inventor.ComponentDefinition = oCompOcc.Definition
If TypeOf compDef Is VirtualComponentDefinition Then Continue For
If TypeOf compDef Is WeldsComponentDefinition Then Continue For
For Each oBody As Inventor.SurfaceBody In oCompOcc.SurfaceBodies
Dim oBodyProxy As SurfaceBodyProxy = Nothing
oCompOcc.CreateGeometryProxy(oBody, oBodyProxy)
oInclEntsColl.Add(oBodyProxy)
Next 'oBody
Next 'oCompOcc
oFinishDef.IncludedEntities = oInclEntsColl
finish.Definition = oFinishDef
End If
Next 'finish
End Sub

 

als long as the ocuurrences are unique parts it works, BUT, if you add a second surfacebodyproxy from a different occurrence, of the same component, you get an error.

so 10 unique parts in an assembly , than this works.

one component copied ten times, in an assembly,  the first will be oke, the second will give an error.

if do it manualy, I select two ore more ocuurrences of the same part, in the finish-object under definition.IncludedEntities, only one surfacebodyproxy is listed?? I can not find the others!!??

Is this not supported yet? or what am I missing?

 

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan