Chamfer to all edge on selected body

Chamfer to all edge on selected body

kresh.bell
Collaborator Collaborator
882 Views
13 Replies
Message 1 of 14

Chamfer to all edge on selected body

kresh.bell
Collaborator
Collaborator

Hi,

is it possible create iLogic for add chamfer to all edge on selected body?

 

 

0 Likes
Accepted solutions (2)
883 Views
13 Replies
Replies (13)
Message 2 of 14

Michael.Navara
Advisor
Advisor

This is the easiest way. This code adds chamfer to all edges, but be careful because you can't run it twice on body or it fails when the chamfer on some edge can't be created.

 

Sub Main
	Dim part As PartDocument = ThisDoc.Document
	Dim body As SurfaceBody = part.ComponentDefinition.SurfaceBodies(1)
	Dim distance As Double = 0.05

	Dim edges As EdgeCollection = ThisApplication.TransientObjects.CreateEdgeCollection()
	For Each edge As Edge In body.Edges
		edges.Add(Edge)
	Next

	part.ComponentDefinition.Features.ChamferFeatures.AddUsingDistance(edges, distance)
End Sub
0 Likes
Message 3 of 14

kresh.bell
Collaborator
Collaborator

Thanks,

I work with multibody part. Is it possible, when I run rule, that I need select body for chamfer and field for chamfer value?

0 Likes
Message 4 of 14

Michael.Navara
Advisor
Advisor

Yes, you can use Pick Method for selecting body and InputBox for input distance value.

 

Sub Main
	Dim part As PartDocument = ThisDoc.Document
	Dim body As SurfaceBody = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartBodyFilter, "Select part") ' part.ComponentDefinition.SurfaceBodies(1)
	Dim distance As Double =  Double.Parse(InputBox("Chamfer distance", "iLogic", 0.05)) ' 0.05

	Dim edges As EdgeCollection = ThisApplication.TransientObjects.CreateEdgeCollection()
	For Each edge As Edge In body.Edges
		edges.Add(Edge)
	Next

	part.ComponentDefinition.Features.ChamferFeatures.AddUsingDistance(edges, distance)
End Sub
0 Likes
Message 5 of 14

kresh.bell
Collaborator
Collaborator

Perfect,

but I think that iLogic have minor bug. If I want chamfer 2, in field must be 0,2

2023-07-31_07-11-45.jpg

 

0 Likes
Message 6 of 14

FINET_Laurent
Advisor
Advisor
Accepted solution

Hi @kresh.bell,

 

Inventor internaly uses centimeters. If you create a double with a value of 1, it will read 1cm what ever the document unit is. If you want your distance to be 1mm, you'll need to convert it by dividing the input value by 10 :

Dim distance As Double =  (Double.Parse(InputBox("Chamfer distance", "iLogic", 0.05))) /10 ' 0.05

 

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
Message 7 of 14

Michael.Navara
Advisor
Advisor

This is because Inventor's internal units are [cm]. You need to convert input string to appropriate numeric value in required units. 

0 Likes
Message 8 of 14

kresh.bell
Collaborator
Collaborator

Thanks, it works perfect

Message 9 of 14

kresh.bell
Collaborator
Collaborator

Is it big problem add option multibody select?

0 Likes
Message 10 of 14

FINET_Laurent
Advisor
Advisor

@kresh.bell,

I'm not sure to understand correctly your request ? What would be the workflow? 
To be able to select one or more solid bodies by click? 

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
Message 11 of 14

kresh.bell
Collaborator
Collaborator

yes

0 Likes
Message 12 of 14

FINET_Laurent
Advisor
Advisor
Accepted solution

Hi @kresh.bell,

Note you can mark multiple replies as solutions for your topic. Here is a code that let you pick multiples surfacebodies. When you are done selecting, simply press "esc" to create the chamfers : 

 

Sub Main
	Dim doc As Inventor.PartDocument = ThisApplication.ActiveDocument
	Dim partdef As Inventor.PartComponentDefinition = doc.ComponentDefinition
	Dim bodyCol As Inventor.ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
	
	For i As Integer = 1 To partdef.SurfaceBodies.Count
		Dim body As SurfaceBody = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartBodyFilter, "Select part")
		If body Is Nothing Then Exit For
		If check(body, bodyCol) = False Then  bodyCol.Add(body)
		
	Next

	Dim distance As Double = (Double.Parse(InputBox("Chamfer distance", "iLogic", 0.05))) / 10 ' 0.05
	Dim edges As EdgeCollection = ThisApplication.TransientObjects.CreateEdgeCollection()
	
	For Each body As Inventor.SurfaceBody In bodyCol
		For Each edge As Edge In body.Edges
			edges.Add(Edge)
			
		Next
	Next
	
	partdef.Features.ChamferFeatures.AddUsingDistance(Edges, distance)
End Sub

Private Function check(input As Object, col As Inventor.ObjectCollection)
	If col.Count = 0 Then Return False
		
	For Each obj As Object In col
		If obj is input Then Return True
		
	Next
	
	Return False
End Function

 

Does this suits your needs ?

 

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

kresh.bell
Collaborator
Collaborator

Perfect, thanks

Message 14 of 14

kresh.bell
Collaborator
Collaborator

iLogic works perfect. Is it possible, when I select bodies, that selected bodies be highlights

0 Likes