Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
J-Camper
in reply to: bhavik4244

I think there is an easy solution to this if the duct work will always be created with a shell feature, and you work with single solidbody parts.  If this is not the case then let me know.

Dim pDef As PartComponentDefinition = ThisDoc.Document.ComponentDefinition
Dim sb As SurfaceBody = pDef.SurfaceBodies.Item(1)

Dim Volume1 As Double = sb.Volume(0.0001)
Dim Volume2 As Double
Dim Volume3 As Double

Dim oShellFeat As ShellFeature

For Each oFeat As PartFeature In sb.AffectedByFeatures
	If oFeat.Type = ObjectTypeEnum.kShellFeatureObject
		oShellFeat = oFeat
		Exit For
	End If
Next

If IsNothing(oShellFeat) Then MessageBox.Show("Solid not affected by a shell feature", "Custom Error 1") : Exit Sub

Dim EOPmarkerCurrent As Object
Dim eopBefore As Object
Dim eopAfter As Object
pDef.GetEndOfPartPosition(eopAfter, eopBefore)
If IsNothing(eopAfter)
	EOPmarkerCurrent = eopBefore
Else
	EOPmarkerCurrent = eopAfter
End If

oShellFeat.SetEndOfPart(True)'Before = True After = False

Dim Tempsb As SurfaceBody = pDef.SurfaceBodies.Item(1)
Volume2 = Tempsb.Volume(0.0001)

'MessageBox.Show("Shell Volume [cm^3]: " & Round(Volume1, 5) & vbCrLf & "Void Volume [cm^3]: " & Round(Volume2, 5), "Volume Comparison:")

EOPmarkerCurrent.SetEndOfPart(False)'Before = True After = False

If oShellFeat.Definition.Direction = ShellDirectionEnum.kOutsideShellDirection
	Volume3 = Volume2
Else If oShellFeat.Definition.Direction = ShellDirectionEnum.kInsideShellDirection
	Volume3 = Volume2-Volume1
Else If oShellFeat.Definition.Direction = ShellDirectionEnum.kBothSidesShellDirection
	MessageBox.Show("It's not as easy to determine BothSidesShellDirection without more work.  If you use this type let me know and we can adapt this code.", "Option Not Programed")
	Exit Sub
End If

MessageBox.Show("Volume using Internal Units [cm^3]: " & Round(Volume3, 5) & vbCrLf & _
				"Volume converted Units [in^3]: " & Round((Volume3/(2.54^3)), 5), "Volume:")

It works by moving Checking current Volume, then moves EOP above the Shell Feature to read the second volume.  Then depending on the type of Shell direction it determines the void volume, and returns EOP to it's original position.  I do not have anything worked out for a shell feature going both directions as that is much more involved. 

 

Let me know if you have any questions, or if this is not working as intended.