Dear All,
I am looking for code that allows setting of the 'Requested Accuracy' in the 'Physical' tab of iProperties, using iLogic.
The requested accuracy defaults to low and I am unable to automate setting it to very high. I can run a rule, update, display the mass, then manually change the 'Requested Accuracy' to 'Very High' and obtain a new, different, mass and volume.
I am essentially looking for an iLogic version of the following VBA code:
Public Sub GetPartMassProps()
' Set a reference to the part document.
' This assumes a part document is active.
Dim oPartDoc As PartDocument
Set oPartDoc = ThisApplication.ActiveDocument
' Set a reference to the mass properties object.
Dim oMassProps As MassProperties
Set oMassProps = oPartDoc.ComponentDefinition.MassProperties
' Set the accuracy to medium.
oMassProps.Accuracy = k_VeryHigh
' Display the mass properties of the part.
MsgBox "Mass: " & oMassProps.Mass
End Sub
Alternatively, if anyone has the know how to convert this into VB.NET then I can run it in iLogic using the "Straight VB Code" option.
Another option would be to change the Document or Application defaults from Low to Very High, if anyone knows hoiw to do this.
After much googling, discussion with VAR and their communication with Autodesk so far I have been unable to solve this.
If it helps, the code that it will be part of is below. It essentially iterates the height if a cut plane until the mass is equal to (actually to within 0.1% of) a target mass (currently set at 151000kg).
'Ensure cut is unsuppressed
Feature.IsActive("Extrusion3") = True mt = 151000 h0 = 0 h1 = 9000 h3 = (h0 + h1) / 2 'First Cut
Parameter("Height") = h3 InventorVb.DocumentUpdate() Mass = iProperties.Mass m3 = iProperties.Mass 'Loop Cut Height Iteration
If Abs(1-(m3/mt)) > 0.001 Then While Abs(1-(m3/mt)) > 0.001 'Reference Parameter Update
If mt>m3 Then h0=h3 m0=m3 h3=(h0+h1)/2 ElseIf mt<m3 Then h1=h3 m1=m3 h3=(h0+h1)/2 End If 'Mid-Plane
Parameter("Height") = h3 InventorVb.DocumentUpdate() Mass = iProperties.Mass m3 = iProperties.Mass End While End If
The major problem is the
InventorVb.DocumentUpdate()
It only updates the mass using Low accuracy. The final mass is always given as 151000 +/- 0.1%. However if I go into iProperties, set 'Requested Accuracy' to 'Very High' and update the model again, the mass can change by over 1500kg (approx 1%).
I really need an automated 'Very High' accuracy, if anyone is able to help I will be forever appreciative.
Many thanks in advance, I am waiting eagerly 😃
Kind Regards
Nick
Solved! Go to Solution.
Solved by Yijiang.Cai. Go to Solution.
Hi Nick,
Please see iLogic version of VBA code you provided below, and hope it helpful for you.
Public Sub Main() ' Set a reference to the part document. ' This assumes a part document is active.
Dim oPartDoc As PartDocument oPartDoc = ThisApplication.ActiveDocument
' Set a reference to the mass properties object.
Dim oMassProps As MassProperties oMassProps = oPartDoc.ComponentDefinition.MassProperties
' Set the accuracy to medium.
oMassProps.Accuracy = 24580 'k_VeryHigh=24580 InventorVb.DocumentUpdate() ' Display the mass properties of the part.
MessageBox.Show("Mass: " & oMassProps.Mass, "GetPartMassProps") End Sub
You, Sir, are a gentleman and a scholar
Thank you so much for your help.
Kind Regards
Nick
Hello again,
I'm afraid I am reviving my previous thread as I am still having some issues.
So, the solution offered worked when I used it in a standalone test part, and subsequently has been seen working in various other models I work on.
However, it has always been a little unreliable, sometimes deciding not to work but not show anaything, and sometimes not work and produce an error.
It now seems that the code is not acheiving an accurate mass update. At the very best it is updating the part mass, but only to a low accuracy. I can then go into iProperties, Physical tab, and set accuracy to 'Very High' which gives me the correct values (with a difference of 5-10% from previous value).
To give a short background, I am using iLogic to iterate to find how an object floats on water. This object is 150 tonnes and is a non uniform shape, and therefore the error in mass and CoM values between 'low' and 'very high' accuracies is giving a mass discrepancy of around half a tonne and angle descrepencies of up to 15 degrees. For my calculations I am looking for masses to within 10kg and angles to within 0.1 degrees, which is entirely possible with 'very high' accuracy but currently my model (3 weeks work) is useless until I can solve this.
Any assistance you can give would be very much appreciated.
I am even open to solutions involving editing the software code so that it always defaults to 'very high', literally any solution will be greatly appreciated.
Many Thanks,
Nick
I'm afraid it's me again, still struggling with my mass properties.
I now have what is a relatively simple question:
- Can somebody please double check that for mass accuracy in iProperties, 'VeryHigh' is 24580?
I suspect that 24580 is actually medium.
The reason i ask is that running the rule as supplied by River Cai, and then going to iProperties and gradually increasing the accuracy, the update button is greyed out for low and medium. It is then available for high and very high, resulting in a mass change of 850kg (0.6%) and a CoG_x change of 27mm (5.5%).
Many Thanks,
Nick