Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

wrong reading of Desity. why and how to fix it ?

Darkforce_the_ilogic_guy
Advisor

wrong reading of Desity. why and how to fix it ?

Darkforce_the_ilogic_guy
Advisor
Advisor

I have a code that read the Density.  but some times it read it wrong ... is there a way to fix it ?

 

My current code look somthing close to this,  but if I run it on the files I send it say densit is = 1 but it is 3,141 .  normaly I can just make small change in the file... and it will fix it .. but I would like to have the right number always.. is that possible ?.. My real code run on an assambly 

Dim rDoc As Document
rDoc = ThisDoc.Document
Dim docPropertySet As PropertySet
docPropertySet = rDoc.PropertySets.Item("Design Tracking Properties")
Dim test

test = docPropertySet.Item("Density").Value

MsgBox(test)

 

 

Darkforce_the_ilogic_guy_0-1688638470195.png

 

Darkforce_the_ilogic_guy_1-1688638482824.png

 

 

0 Likes
Reply
410 Views
6 Replies
Replies (6)

FINET_Laurent
Advisor
Advisor

Hi @Darkforce_the_ilogic_guy,

 

I would probably update all the physical properties of the document by adding this line : 

 

Dim rDoc As Document
rDoc = ThisDoc.Document
Dim docPropertySet As PropertySet
docPropertySet = rDoc.PropertySets.Item("Design Tracking Properties")
Dim test As Double

ThisApplication.CommandManager.ControlDefinitions.Item("AppUpdateMassPropertiesCmd").Execute

test = docPropertySet.Item("Density").Value
MsgBox(test)

 

 

Maybe you can find what you are looking for here  : 

Résolu : how to update physical mass, area and volume...for an assembly by API - Autodesk Community ...

 

Kind regards,

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

0 Likes

Frederick_Law
Mentor
Mentor

I use this for mass in iLogic:

Dim NewMass As Double
NewMass = Round(iProperties.Mass, 2)
0 Likes

Darkforce_the_ilogic_guy
Advisor
Advisor

It did not work .. Still say 1 isted of the right density

0 Likes

FINET_Laurent
Advisor
Advisor

@Darkforce_the_ilogic_guy,

 

FINET_Laurent_0-1688651511654.png

It's working like a charm on my end. How are you updating the density of the part ? 

 

Kind regards,

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

0 Likes

WCrihfield
Mentor
Mentor

When dealing with things like Mass, Volume, & Density, it is almost always best to go the API route, and access the MassProperties object.  Then, if you need to make sure the value is up to date, you may need to adjust the 'Accuracy' setting.  Adjusting the accuracy will force an update and recalculation before retrieving the new value at that accuracy level.  There was a thread about this somewhere here on this forum a couple\few years ago in which an Autodesk employee pointed this out.  And the one API sample VBA macro shows an example of this type of thing too, but goes into too much other detail for most folks.  However, values obtained through the API route will usually need to have the units converted from 'database units' (g/cm^3) to 'document units'.  The simplistic iLogic snippet iProperties.Mass will return the Mass value in document units directly, but the online documentation for that property does not say anything about causing an update.

Edit:  By the way, I know the MassProperties object does not have a direct property for Density, but getting that value is as simple as Mass/Volume, so it is fairly simple to obtain that way.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Frederick_Law
Mentor
Mentor

Density 1 is from Material "Generic".

Mass is override, density is calculated.

0 Likes