• This forum is the machine-generated translation of www.cad3d.it/forum1 - the Italian design community. Several terms are not translated correctly.

weight calculation with ilogic

  • Thread starter Thread starter and
  • Start date Start date

and

Guest
Hi I have an ilogic for calculating the weight of assemblies and parts so as to insert it into a custom variable.

iproperties.value("custom", "peso_gr") = math.round(iproperties.mass*1000), 0)

I had speculated that the unit of measurement of the assembly and parts was always in kg for this I multiplied by 1000 the result.

But since I have different units of measurement, can I insert a control that goes to me to see the unit of measurement and then decide whether to multiply it by 1000 or not??

Thank you.
 
Yes, you can and not necessarily have to do calculation to "hand"
Code:
thisapplication.activedocument

messagebox.show(doc.unitsofmeasure.massunits)

'to convert da unità to unità
' valorenumericodouble = doc.unitsofmeasure.convertunits(10, doc.unitsofmeasure.massunits, unitstypeenum.kkilogrammassunits)
reference links> unitsofmeasure
 
Yes, you can and not necessarily have to do calculation to "hand"
Code:
thisapplication.activedocument

messagebox.show(doc.unitsofmeasure.massunits)

'to convert da unità to unità
' valorenumericodouble = doc.unitsofmeasure.convertunits(10, doc.unitsofmeasure.massunits, unitstypeenum.kkilogrammassunits)
reference links> unitsofmeasure
to integrate it into my setting with ifs??
 
should not be necessary to use a conditional operator (if/else/etc. )

the last line of code I wrote converts the weight from unit to unit so it should be fine to write so...
Code:
iproperties.value("custom", "peso_gr") = doc.unitsofmeasure.convertunits(iproperties.mass, doc.unitsofmeasure.massunits, unitstypeenum.kkilogrammassunits)
you must assign the active document to the variable "doc" and choose the target unit for weight.

to do a test it is best to use a "messagebox" as I wrote in the example code.
 
should not be necessary to use a conditional operator (if/else/etc. )

the last line of code I wrote converts the weight from unit to unit so it should be fine to write so...
Code:
iproperties.value("custom", "peso_gr") = doc.unitsofmeasure.convertunits(iproperties.mass, doc.unitsofmeasure.massunits, unitstypeenum.kkilogrammassunits)
you must assign the active document to the variable "doc" and choose the target unit for weight.

to do a test it is best to use a "messagebox" as I wrote in the example code.
Sorry ignorance...
what you mean by: "you must assign the active document to the variable "doc" and choose the target unit for weight. "
?
 
in my first example code you will find written the following line.. .
Code:
doc = thisapplication.activedocument
this line assigns the active document to the variable "doc".

the following code line uses a function of internal conversion part of the "document" of inventor.
Code:
iproperties.value("custom", "peso_gr") = doc.unitsofmeasure.convertunits(iproperties.mass, doc.unitsofmeasure.massunits, unitstypeenum.kkilogrammassunits)

"iproperties.value("custom", "peso_gr")" is the property to which the converted value is assigned

when I check the active document to the variable "doc" I have access to the following:
  • the conversion function "doc.unitsofmeasure.convertunits(value, avalore, umconversion)"
    • "value" = the original value to be converted
      • in my sample code I wrote "iproperties.mass" which is the mass recorded in the current document
    • "avalore" = the unit of measurement of the "value" da convertire
      • in my sample code I wrote "doc.unitsofmeasure.massunits" which is the unit of measurement recorded in the active document, in this way the conversion of the measuring unit is made without having to use conditional operators (if/else/etc. )
    • "umconversion" = the unit of measurement in which to convert the "value"
      • in my sample code I wrote "unitstypeenum.kkilogrammassunits" which corresponds to the kilogramme measurement unit
  • the unit of mass measurement "doc.unitsofmeasure.massunits" set in the active document
the example could generate errors if one of the returned values is "empty", if it happens, just add a few lines to make additional controls.
 

Forum statistics

Threads
44,997
Messages
339,767
Members
4
Latest member
ibt

Members online

No members online now.
Back
Top