Altering Density in Component from Assembly (Ilogic)

Altering Density in Component from Assembly (Ilogic)

gcoombridge
Advisor Advisor
898 Views
1 Reply
Message 1 of 2

Altering Density in Component from Assembly (Ilogic)

gcoombridge
Advisor
Advisor

Hi All,

 

I am modelling a tank template and have an assembly parameter for the tank contents specific gravity. This is sent to a model of the tank contents to adjust the density (and thereby the mass).

 

This works fine in the part environment but errors when updated from the assembly.  I'm pretty sure it's to do with the oPartDoc = ThisApplication.ActiveDocument and trying to trigger it from a different file.  I do a lot of conditional statements, isactive functions etc... but the finer points of how and when rules are run is beyond me at this stage...

 

This is the code (taken from this post - thanks guys https://forums.autodesk.com/t5/inventor-forum/using-ilogic-to-set-material-properties/td-p/5278523😞

Sub Main()
    oPartDoc = ThisApplication.ActiveDocument
    Dim oMaterial As Material
    oMaterial = oPartDoc.Materials.Item("Water")
    oMaterial.Density = (1*ProductMaxSG)
End Sub

This is the error when the ProductMaxSG parameter is altered from the assembly form:

 image.png

 

 Cheers,

 

Glenn

Use iLogic Copy? Please consider voting for this long overdue idea (not mine):https://forums.autodesk.com/t5/inventor-ideas/string-replace-for-ilogic-design-copy/idi-p/3821399
0 Likes
Accepted solutions (1)
899 Views
1 Reply
Reply (1)
Message 2 of 2

gcoombridge
Advisor
Advisor
Accepted solution

Solved this myself - should have written ThisDoc.Document to explicitly refer to the part. 

 

    oPartDoc = ThisDoc.Document
    Dim oMaterial As Material
    oMaterial = oPartDoc.Materials.Item("Water")
    oMaterial.Density = (1*ProductMaxSG)

 Cheers,

Use iLogic Copy? Please consider voting for this long overdue idea (not mine):https://forums.autodesk.com/t5/inventor-ideas/string-replace-for-ilogic-design-copy/idi-p/3821399
0 Likes