Both points mentioned above by the other helpful folks are valid and useful, but just in case you are not sure how to apply it all, here is a completed version of the code for you to look at.
Also, just so you know, there are multiple ways to get the surface area of documents and components. You've already pointed out one of them that isn't very well known, because its documentation isn't found in the usual places to look for such things. When using the iProperties iLogic snippet, there is also a property of that iProperties object called Area that can be used (may have been introduced in the 2022 version though). When using the longer API route, there is a standard iProperty in the third Set called "SurfaceArea", which is ReadOnly, and returns a value in database units. There is a so an Area property within the MassProperties object, under the ComponentDefinition of Parts & Assemblies.
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
MsgBox("An Assembly Document must be active for this rule to work. Exiting.",vbCritical, "WRONG DOCUMENT TYPE")
Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
oAsmArea = iProperties.Area 'retrieved from the 'active' document by default
oAsmArea = Round(oAsmArea / 10000, 3) & " m^2"
Dim oAsmSAProp As Inventor.Property
Try
oAsmSAProp = oADoc.PropertySets.Item(4).Item("SurfaceArea")
oAsmSAProp.Value = oAsmArea
Catch
oAsmSAProp = oADoc.PropertySets.Item(4).Add(oAsmArea, "SurfaceArea")
End Try
oADef = oADoc.ComponentDefinition
For Each oOcc As ComponentOccurrence In oADef.Occurrences.AllReferencedOccurrences(oADef)
If Not TypeOf oOcc.Definition Is VirtualComponentDefinition Then
oCompSA = iProperties.AreaOfComponent(oOcc.Name)
'oCompSA = iProperties.Area(oComp.Name)
Dim oOccDoc As Document = oOcc.Definition.Document
'a standard iProperty by this name already exists in all documents (ReadOnly, database units)
'oCompSA = oOccDoc.PropertySets.Item(3).Item("SurfaceArea").Value
oCompSA = Round(oCompSA / 10000, 3) & " m^2"
Dim oCSA As Inventor.Property
Try
oCSA = oOccDoc.PropertySets.Item(4).Item("SurfaceArea")
oCSA.Value = oCompSA
Catch
oCSA = oOccDoc.PropertySets.Item(4).Add(oCompSA, "SurfaceArea")
End Try
End If
Next
And just in case the iProperties.Area won't work for you, due to having an older version of Inventor, here are a couple of additional lines you can use to get the Area value.
oAsmArea = oADef.MassProperties.Area
oCompSA = oOcc.Definition.MassProperties.Area
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.
If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡 or you can Explore My CONTRIBUTIONS
Wesley Crihfield

(Not an Autodesk Employee)