Hi @Cosmin_V. It looks like you want to loop through all levels of your assembly and only process the part documents. Then within each part document, you want to check the value of its 'Description' iProperty, and if it equals "Bosch Profile" (I added the "e" at the end, I hope that's correct), you want to make sure that part's material is set to one named "AlMg3". Then when that is taken care of, you next want to set the density to 1. Does all that sound correct so far?
If so...
1) Is this material named "AlMg3" already accessible to each of those part files (either a local copy, or in their 'active' material library), or will we have to find it in some other material library, then make a local copy of it before we can use it in each part?
2) What units are we talking about when we're setting the Density to 1? I believe if you just type in a raw number for this in iLogic, it will be understood as the database default units, which I believe is 'grams per cubic centimeter' or 'g/cm^3'. Is that OK with you, or do you need it in different units.
3) If you want to change the actual material's density in all those different files. I'm thinking there must be a better way, like changing it in one place, then the 'Mass Properties' of all other documents that are referencing that material will be updated to the new values once their document's have been updated/rebuilt (gives them a chance to recalculate). These days the 'material' is an 'Asset' object, and any local edits to them in a document can be saved back to the material library where they were originally referenced from, as long as that material library isn't 'ReadOnly'. I believe this can still all be done by code, but it can get complicated. (By the way, the iProperty for Density is ReadOnly, and is in database units anyways.)
Here is one attempt at it you can play with though:
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
oOccs = oADoc.ComponentDefinition.Occurrences
For Each oOcc As ComponentOccurrence In oOccs.AllLeafOccurrences
If Not TypeOf oOcc.Definition Is PartComponentDefinition Then Continue For
Dim oPDef As PartComponentDefinition = oOcc.Definition
Dim oPDoc As PartDocument = oPDef.Document
If oPDoc.PropertySets(3).Item("Description").Value = "Bosh Profile" Then
If oPDoc.ActiveMaterial.DisplayName = "AlMg3" Then Continue For
'Find/Get the 'MaterialAsset' named "AlMg3"
Dim oMatl As MaterialAsset
Try
oMatl = oPDoc.MaterialAssets.Item("AlMg3")
Catch
oMatl = ThisApplication.ActiveMaterialLibrary.MaterialAssets.Item("AlMg3")
Catch
MsgBox("Couldn't find a 'MaterialAsset' named 'AlMg3'.", vbInformation, "iLogic")
Continue For
End Try
If IsNothing(oMatl) Then Continue For
oPhysAsset = oMatl.PhysicalPropertiesAsset
Dim oFloatVal As FloatAssetValue = oPhysAsset.Item("structural_Density")
oFloatVal.Value = 1
End If
oPDoc.Update2(True)
oPDoc.Save2(False)
Next
oADoc.Update2(True)
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)