Individual volumes in a part with multiple solids

Individual volumes in a part with multiple solids

stefan.unterste-wilms
Contributor Contributor
944 Views
18 Replies
Message 1 of 19

Individual volumes in a part with multiple solids

stefan.unterste-wilms
Contributor
Contributor

Hello,
I would like to look at the volumes of the single solids in a part with multiple solids and not go to it over the Iproperties. preferably, they should always be visible.

Is there a way to do this?

 

Greetings
Stefan

0 Likes
Accepted solutions (3)
945 Views
18 Replies
Replies (18)
Message 2 of 19

FINET_Laurent
Advisor
Advisor

Hi @stefan.unterste-wilms,

 

You could do as folowing :

Sub main
	Dim doc As Inventor.PartDocument = ThisApplication.ActiveDocument
	Dim pcd As Inventor.PartComponentDefinition = doc.ComponentDefinition

	Dim s As Inventor.SurfaceBody = pcd.SurfaceBodies.Item(1)
	MsgBox(s.Volume(5)) 'volume in cm^3
	
End Sub

This would give you the volume of the first surfacebody in the part, in cm³.

 

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

Message 3 of 19

Curtis_Waguespack
Consultant
Consultant

Hi @stefan.unterste-wilms 

 

I'm not sure how you would display this all the time, but here is an example to get the volume for each solid body.

 

For Each oSurfBody As SurfaceBody In ThisDoc.Document.ComponentDefinition.SurfaceBodies
	volume = Round( oSurfBody.Volume(0.001), 5)
	sMsg &= oSurfBody.Name & vbLf & "Volume = " & volume & vbLf & vbLf
Next

MsgBox(sMsg, , "iLogic")

 

EESignature

Message 4 of 19

Curtis_Waguespack
Consultant
Consultant

Hi @stefan.unterste-wilms 

 

Maybe this would work for displaying the volumes. 

 

sFontSize = "0.125"
sNotename = "Solids Volumes"

Dim oDef As ComponentDefinition = ThisDoc.Document.ComponentDefinition

Dim oUOM As UnitsOfMeasure = ThisDoc.Document.UnitsOfMeasure
Dim oMassUnits As String = oUOM.GetStringFromType(UnitsTypeEnum.kDatabaseMassUnits)

For Each oSurfBody As SurfaceBody In oDef.SurfaceBodies
	volume = Round(oSurfBody.Volume(0.001), 5)

	sMsg &= "<StyleOverride Font='Arial' FontSize='" & sFontSize & "'>" & _
	oSurfBody.Name & "</StyleOverride>" & _
	"<StyleOverride Font='Arial' FontSize='" & sFontSize & "'>" & _
	": " & volume & " " & oMassUnits & "</StyleOverride><Br/>"
Next

Try
	oDef.ModelAnnotations.ModelGeneralNotes.item(sNotename).delete
Catch
End Try

Dim oNoteDef As ModelGeneralNoteDefinition
oNoteDef = oDef.ModelAnnotations.ModelGeneralNotes.CreateDefinition _
(sMsg, True, ScreenQuadrantEnum.kUpperLeftQuadrant)
oNoteDef.Text.Size = dTextSize

'add to model
Dim oNote As ModelGeneralNote
oNote = oDef.ModelAnnotations.ModelGeneralNotes.Add(oNoteDef)
oNote.Name = sNotename

EESignature

Message 5 of 19

stefan.unterste-wilms
Contributor
Contributor

Hi,

I have an error and I don't know how to fix it.

 

"Error in line 30 in rule test, in document part1"

"The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))"

 

Info:

"System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
at Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
at ThisRule.Main() in Regel Test, in Dokument Bauteil1:line 30
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)"

 

Thx

Stefan

0 Likes
Message 6 of 19

Curtis_Waguespack
Consultant
Consultant

Hi @stefan.unterste-wilms 

 

What version of Inventor are you using?

Can you provide the file that you were using when running this rule?

As a test can you get the rule to run on a simple part file with just 2 solid bodies?

EESignature

Message 7 of 19

stefan.unterste-wilms
Contributor
Contributor

Hi

 

What version of Inventor are you using?

We are using 2022.

 

Can you provide the file that you were using when running this rule?

This is a template with 15 solids and unfortunately I am not allowed to give it out.

 

As a test can you get the rule to run on a simple part file with just 2 solid bodies?

I can run the rule if I don't have a volume in the model. As soon as I create a solid the error comes up.

 

 

0 Likes
Message 8 of 19

Curtis_Waguespack
Consultant
Consultant

Hi @stefan.unterste-wilms,

 

I can't think of anything that would cause the error. 

 

Here is an example file and a video in case that helps you spot something that is causing the issue.

 

 

EESignature

Message 9 of 19

FINET_Laurent
Advisor
Advisor
Accepted solution

Hi @stefan.unterste-wilms, @Curtis_Waguespack,

 

I had the same error than @stefan.unterste-wilms. I dug a bit and it came from the sMsg formatted text. 

The issue with it is the font size declared as a string. Unfortunately some people have the "," (comma) for decimals and others have the "." (dot) (region parameters on windows). This is dangerous to declare decimal numbers as strings. 

Declaring the sFontSize as a double fixed the error. I guess it would do the same on @stefan.unterste-wilms.  

 

Fixed code of @Curtis_Waguespack : 

Dim sFontSize As Double = 0.125
sNotename = "Solids Volumes"

Dim oDef As ComponentDefinition = ThisDoc.Document.ComponentDefinition

Dim oUOM As UnitsOfMeasure = ThisDoc.Document.UnitsOfMeasure
Dim oMassUnits As String = oUOM.GetStringFromType(UnitsTypeEnum.kDatabaseMassUnits)

For Each oSurfBody As SurfaceBody In oDef.SurfaceBodies
	volume = Round(oSurfBody.Volume(0.001), 5)

	sMsg &= "<StyleOverride Font='Arial' FontSize='" & sFontSize & "'>" & _
	oSurfBody.Name & "</StyleOverride>" & _
	"<StyleOverride Font='Arial' FontSize='" & sFontSize & "'>" & _
	": " & volume & " " & oMassUnits & "</StyleOverride><Br/>"
Next

Try
	oDef.ModelAnnotations.ModelGeneralNotes.item(sNotename).delete
Catch
End Try

Dim oNoteDef As ModelGeneralNoteDefinition
oNoteDef = oDef.ModelAnnotations.ModelGeneralNotes.CreateDefinition _
(sMsg, True, ScreenQuadrantEnum.kUpperLeftQuadrant)
oNoteDef.Text.Size = dTextSize

'add to model
Dim oNote As ModelGeneralNote
oNote = oDef.ModelAnnotations.ModelGeneralNotes.Add(oNoteDef)
oNote.Name = sNotename

 

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

Message 10 of 19

Curtis_Waguespack
Consultant
Consultant

 @FINET_Laurent, thank you for catching the issue! and posting the working example. 

EESignature

0 Likes
Message 11 of 19

sbalasubramanianJJDFU
Enthusiast
Enthusiast

Hi Curtis,

 

Need your help to modify this iLogic a little, the current volume is displaying volume as kg even when the units is set to lbsmass.  I would need the actual volume to be in^3  and the resulting volume to be multiplied by 0.267 .Kindly assist. Thanks in advance

 

 

 

Dim sFontSize As Double = 0.225
sNotename = "Solids Volumes"

Dim oDef As ComponentDefinition = ThisDoc.Document.ComponentDefinition

Dim oUOM As UnitsOfMeasure = ThisDoc.Document.UnitsOfMeasure
Dim oMassUnits As String = oUOM.GetStringFromType(UnitsTypeEnum.kDatabaseMassUnits)

For Each oSurfBody As SurfaceBody In oDef.SurfaceBodies
	volume = Round(oSurfBody.Volume(0.001), 5)

	sMsg &= "<StyleOverride Font='Arial' FontSize='" & sFontSize & "'>" & _
	oSurfBody.Name & "</StyleOverride>" & _
	"<StyleOverride Font='Arial' FontSize='" & sFontSize & "'>" & _
	": " & volume & " " & oMassUnits & "</StyleOverride><Br/>"
Next

Try
	oDef.ModelAnnotations.ModelGeneralNotes.item(sNotename).delete
Catch
End Try

Dim oNoteDef As ModelGeneralNoteDefinition
oNoteDef = oDef.ModelAnnotations.ModelGeneralNotes.CreateDefinition _
(sMsg, True, ScreenQuadrantEnum.kUpperLeftQuadrant)
oNoteDef.Text.Size = dTextSize

'add to model
Dim oNote As ModelGeneralNote
oNote = oDef.ModelAnnotations.ModelGeneralNotes.Add(oNoteDef)
oNote.Name = sNotename

 

0 Likes
Message 12 of 19

FINET_Laurent
Advisor
Advisor

@Curtis_Waguespack , can I also have you as my personal developer for free? 😄

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
Message 13 of 19

Curtis_Waguespack
Consultant
Consultant
Accepted solution

@sbalasubramanianJJDFU , see updated example. 

 

Hope that helps,

Curtis

 

Dim sFontSize As Double = 0.125
sNotename = "Solids Volumes"

Dim oDef As ComponentDefinition = ThisDoc.Document.ComponentDefinition

Dim oUOM As UnitsOfMeasure = ThisDoc.Document.UnitsOfMeasure
Dim oLengthUnits As String = oUOM.GetStringFromType(UnitsTypeEnum.kDefaultDisplayLengthUnits)

If oLengthUnits = "in" Then
	oConversionFactor = 0.061024
ElseIf oLengthUnits = "ft" Then
	oConversionFactor = 0.00003531
ElseIf oLengthUnits = "m" Then
	oConversionFactor = 1000000
ElseIf oLengthUnits = "cm" Then
	oConversionFactor = 1
ElseIf oLengthUnits = "mm" Then
	oConversionFactor = 1000
End If

oLengthUnits = oLengthUnits & "^3"

For Each oSurfBody As SurfaceBody In oDef.SurfaceBodies
	volume = Round(oSurfBody.Volume(0.001) * oConversionFactor, 3)

	sMsg &= "<StyleOverride Font='Arial' FontSize='" & sFontSize & "'>" & _
	oSurfBody.Name & "</StyleOverride>" & _
	"<StyleOverride Font='Arial' FontSize='" & sFontSize & "'>" & _
	": " & volume & " " & oLengthUnits & "</StyleOverride><Br/>"
Next

Try
	oDef.ModelAnnotations.ModelGeneralNotes.item(sNotename).delete
Catch
End Try

Dim oNoteDef As ModelGeneralNoteDefinition
oNoteDef = oDef.ModelAnnotations.ModelGeneralNotes.CreateDefinition _
(sMsg, True, ScreenQuadrantEnum.kUpperLeftQuadrant)
oNoteDef.Text.Size = dTextSize

'add to model
Dim oNote As ModelGeneralNote
oNote = oDef.ModelAnnotations.ModelGeneralNotes.Add(oNoteDef)
oNote.Name = sNotename

 

EESignature

0 Likes
Message 14 of 19

sbalasubramanianJJDFU
Enthusiast
Enthusiast

Thanks for quickly helping on this one. The code seems to work. I have few questions though.

I see that the unit conversion factors have been added which is fantastic. Is this to cater even if the unit settings are set different, it eventually provides result in inches? If so, that conversion doesnt seem to work if I change it to metric units for example.

0 Likes
Message 15 of 19

Curtis_Waguespack
Consultant
Consultant

@sbalasubramanianJJDFU 

 

I had an error in the version I posted above... I just edited it and fixed that error.

 

What it should be doing is looking at the unit set at Tools > Document Settings > Units > Length

 

And getting the unit string from that to use as the ^3 unit string and using that string to determine the conversion factor.

 

Please try the updated example, and let me know if you see any issues.

 

 

EESignature

Message 16 of 19

sbalasubramanianJJDFU
Enthusiast
Enthusiast

Hi Curtis,

 

This is what I get with updated code when metric unit is selected

sbalasubramanianJJDFU_0-1728395328331.png

 

Message 17 of 19

Curtis_Waguespack
Consultant
Consultant
Accepted solution

@sbalasubramanianJJDFU , that seems to be working as intended.


But if you are wanting it to always return cubic inches, then you can use this version, which converts the volume to cubic inches... keep in mind the API will always return centimeters...

 

so if we only ever want inches, then we don't need to worry about the document settings. 

 

Dim sFontSize As Double = 0.125
sNotename = "Solids Volumes"

Dim oDef As ComponentDefinition = ThisDoc.Document.ComponentDefinition

oLengthUnits = "in^3"
oConversionFactor = 0.061024

For Each oSurfBody As SurfaceBody In oDef.SurfaceBodies
	volume = Round(oSurfBody.Volume(0.001) * oConversionFactor, 3)

	sMsg &= "<StyleOverride Font='Arial' FontSize='" & sFontSize & "'>" & _
	oSurfBody.Name & "</StyleOverride>" & _
	"<StyleOverride Font='Arial' FontSize='" & sFontSize & "'>" & _
	": " & volume & " " & oLengthUnits & "</StyleOverride><Br/>"
Next

Try
	oDef.ModelAnnotations.ModelGeneralNotes.item(sNotename).delete
Catch
End Try

Dim oNoteDef As ModelGeneralNoteDefinition
oNoteDef = oDef.ModelAnnotations.ModelGeneralNotes.CreateDefinition _
(sMsg, True, ScreenQuadrantEnum.kUpperLeftQuadrant)
oNoteDef.Text.Size = dTextSize

'add to model
Dim oNote As ModelGeneralNote
oNote = oDef.ModelAnnotations.ModelGeneralNotes.Add(oNoteDef)
oNote.Name = sNotename

 

 

EESignature

0 Likes
Message 18 of 19

sbalasubramanianJJDFU
Enthusiast
Enthusiast

Perfect.. works like charm. I wanted it to get the result value in inches only.

Lastly how should I clear the solid volume values from screen.. looks like its permanently showing on part model screen.

0 Likes
Message 19 of 19

Curtis_Waguespack
Consultant
Consultant

just delete the annotation that the code is creating:

Curtis_Waguespack_0-1728397875080.png

 

EESignature