Selecting body's in a IPT

Selecting body's in a IPT

vanwees
Enthusiast Enthusiast
544 Views
6 Replies
Message 1 of 7

Selecting body's in a IPT

vanwees
Enthusiast
Enthusiast

Hello,

 

I am new to ilogic but I now have an ipt file in which I have 23000 body. Now I want to make it smaller by selecting the body's which are smaller than a certain volume and then combining them by the combine function. Does anyone know if this is possible in ilogic?
It would save me a lot of clicking

Thanks in advance for the reactions.

0 Likes
Accepted solutions (1)
545 Views
6 Replies
Replies (6)
Message 2 of 7

Andrii_Humeniuk
Advisor
Advisor

Hi @vanwees . Try this code. In line 8, you need to write down the minimum volume in cm3.

Private Sub Main()
	Dim oDoc As PartDocument = ThisApplication.ActiveDocument
	Dim oColl As ObjectCollection
	Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition
	Dim oCombines As CombineFeatures = oDef.Features.CombineFeatures
	Dim oCombine As CombineFeature
	Dim firstBodies As SurfaceBody
	Dim dMinVol As Double = 1000 '"cm3"
    oColl = ThisApplication.TransientObjects.CreateObjectCollection
	Dim oProgressBar As Inventor.ProgressBar
	Dim i As Integer = 1
	oMessage = "CombineFeatures... " 
	oProgressBar = ThisApplication.CreateProgressBar(False, oDef.SurfaceBodies.Count, oMessage)
    oProgressBar.Message = ("CombineFeatures... ")
	For Each oBody As SurfaceBody In oDef.SurfaceBodies
		If oBody.Volume(1) < dMinVol Then
			If firstBodies Is Nothing Then
				firstBodies = oBody
			Else
				oColl.Add(oBody)
			End If
		End If
        oProgressBar.Message = ("Search for bodies. Progress " & i & " of " & oDef.SurfaceBodies.Count & ".")
        oProgressBar.UpdateProgress
		i += 1
	Next
	oProgressBar.Close()	
	If firstBodies Is Nothing  Or oColl.Count = 0 Then Exit Sub
	oCombine = oCombines.Add(firstBodies, oColl, PartFeatureOperationEnum.kJoinOperation, True)
	oCombine.name = "My_Combine"
End Sub

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 3 of 7

vanwees
Enthusiast
Enthusiast

Thank you very much for the quick response it does work in part only it does something different than I expected.
See images is this also an option in ilogic. My goal is to have an ilogic where I specify a certain volume and then it does all the small body's combine and when I make a derived body from this file that I don't take all the small body's with me.

I hope my explanation is a bit clear.

0 Likes
Message 4 of 7

Andrii_Humeniuk
Advisor
Advisor

No problem, you need to put False in line 29.

oCombine = oCombines.Add(firstBodies, oColl, PartFeatureOperationEnum.kJoinOperation, False)

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 5 of 7

vanwees
Enthusiast
Enthusiast
Thank you very much, I am going to try it on a big multibody on a small one it works perfect
0 Likes
Message 6 of 7

vanwees
Enthusiast
Enthusiast

Hello  Andrii,

 

It doesn't work on a big multbody part (23000 body's). Maybe we can make the code not to combine but hide the body's smaller than a ...cm^3. Then make a new model state and make of this model state a derevid body. 

 

What do you think or somebody else has a solution for this. 

 

Thanks in advance for any help

0 Likes
Message 7 of 7

vanwees
Enthusiast
Enthusiast
Accepted solution

Hello, 

 

I have made this ilogic rule does any one now if it can be easier or an other way

 

'Define the document as a component definition
Dim oCompDef As ComponentDefinition
oCompDef = ThisDoc.Document.ComponentDefinition

'Prompt the user to enter the volume threshold in mm^3
Dim input As String = InputBox("Enter the volume threshold in mm^3:", "Volume Threshold")
Dim dMinVol As Double

'Convert the input to a double value
If Not Double.TryParse(input, dMinVol) Then
    MsgBox("Invalid input. Please enter a valid number.", MsgBoxStyle.Critical, "Error")
    Exit Sub
End If

'Step through each solid body and set visibility based on volume
Dim hiddenCount As Integer = 0 ' Initialize a counter for hidden bodies

For Each oBody As SurfaceBody In oCompDef.SurfaceBodies
    Dim bodyVolume As Double = oBody.Volume(0.1) * 1000 ' Calculate the volume of the body in mm^3

    If bodyVolume < dMinVol Then
        oBody.Visible = False ' Set visibility to False (hidden)
        hiddenCount += 1 ' Increment the counter for hidden bodies
    Else
        oBody.Visible = True ' Set visibility to True (visible)
    End If
Next

'Message box displaying the count of hidden bodies
MsgBox("Number of bodies set to hidden: " & hiddenCount, MsgBoxStyle.Information, "Hidden Bodies")

 

0 Likes