Hi @isocam. Within the code sample you originally posted here, the 'oExtrude1' variable has not been 'declared', and no value has been assigned to it. So, it does not know what 'oExtrude1' is, and therefore does not recognize it as having a property named 'Appearance'. I can only assume from its name that it is supposed to be representing an Inventor.ExtrudeFeature type object. If that is the case, then your VBA macro will need to include more code that finds that specific ExtrudeFeature first, then declares that variable and sets the Type of that variable to ExtrudeFeature, then sets the value of that variable to that ExtrudeFeature that it finds...all before that line of code that is attempting to set its appearance. If I had to guess, I might assume that you are working on a PartDocument that only has one ExtrudeFeature present in it, then maybe you only want this VBA macro to effect that one ExtrudeFeature, and not any of the other objects in the whole part. Does that sound correct to you. If so, then that will give us a better idea of how to fix the code for you.
The code below is according to my unconfirmed assumptions.
Function ChangeColour()
Dim oDoc As PartDocument
Set oDoc = ThisApplication.ActiveDocument
Dim oAppearence As Asset
Set oAppearence = oDoc.Assets.Add(kAssetTypeAppearance, "Generic")
Dim oColor As ColorAssetValue
Set oColor = oAppearence.Item("generic_diffuse")
Red = 0
Green = 145
Blue = 255
oColor.Value = ThisApplication.TransientObjects.CreateColor(Red, Green, Blue)
Dim oExtFeats As ExtrudeFeatures
Set oExtFeats = oDoc.ComponentDefinition.Features.ExtrudeFeatures
If oExtFeats.Count = 0 Then Return
Dim oExtrude1 As ExtrudeFeature
Set oExtrude1 = oExtFeats.Item(1)
oExtrude1.Appearance = oAppearence
End Function
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Edit: I also corrected another think I saw later. The Assets.Add method's online documentation says that its third input is 'reserved for future use', so that one should not be specified (and it was in the original code here). However, we can specify the forth input, which would be the DisplayName of the new Asset. But I left that out for now, because if we do specify that, and that one already exists, that would likely just cause another error that we would need to work around somehow.
Edit 2: Also removed 'Public' from the definition line, and added the 'Set' keyword in there a few times were it was needed. Need to test these things before posting them. 😅
Wesley Crihfield

(Not an Autodesk Employee)