Replace fillets with chamfers

Replace fillets with chamfers

sferrer4DQ8Y
Explorer Explorer
386 Views
3 Replies
Message 1 of 4

Replace fillets with chamfers

sferrer4DQ8Y
Explorer
Explorer

 

 

Tired of trying to convert fillets to chamfers on a part with Inventor Ilogic with the attached rule. It gives the following error:
"Public member 'Edges' cannot be found on type 'FilletFeature'"
In the line "oEdges = oFillet.Edges
" Any suggestions for this trouble?

 

I Used this rule:

' iLogic Rule: ReplaceFilletsWithChamfers
' Get the active part document
Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument

' Get the component definition
Dim oCompDef As PartComponentDefinition
oCompDef = oDoc.ComponentDefinition

' Create a transient object for collections
Dim oTransientObjects As TransientObjects
oTransientObjects = ThisApplication.TransientObjects

' List to store edges from fillets
Dim filletEdgesCollection As ObjectCollection
filletEdgesCollection = oTransientObjects.CreateObjectCollection

' Collect all fillet features first to avoid modification during iteration
Dim filletList As List(Of FilletFeature) = New List(Of FilletFeature)
Dim oFillet As FilletFeature
For Each oFillet In oCompDef.Features.FilletFeatures
filletList.Add(oFillet)
Next

' Iterate through all fillet features in the part
For Each oFillet In filletList
' Get the collection of edges from the fillet
Dim oEdges As ObjectCollection
oEdges = oFillet.Edges
For Each oEdge As Edge In oEdges
filletEdgesCollection.Add(oEdge)
Next

' Delete the fillet feature
oFillet.Delete()
Next

' Define the chamfer size
Dim chamferDistance As Double
chamferDistance = 0.1 ' Change this value to the desired chamfer size

' Create the chamfer feature using the collected edges
If filletEdgesCollection.Count > 0 Then
Dim oChamferDef As ChamferFeatureDefinition
oChamferDef = oCompDef.Features.ChamferFeatures.CreateChamferFeatureDefinition
oChamferDef.SetToEqualDistance(chamferDistance)
oChamferDef.Edges.Add(filletEdgesCollection)

Dim oChamferFeature As ChamferFeature
oChamferFeature = oCompDef.Features.ChamferFeatures.Add(oChamferDef)
End If

' Update the part document
oDoc.Update()

' Message to indicate the rule has run
MessageBox.Show("All fillets have been replaced with chamfers.", "iLogic Rule")

0 Likes
Accepted solutions (1)
387 Views
3 Replies
Replies (3)
Message 2 of 4

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @sferrer4DQ8Y 

Something like this might work.

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

Dim oDoc As PartDocument
oDoc = ThisDoc.Document

Dim oCompDef As PartComponentDefinition
oCompDef = oDoc.ComponentDefinition

Dim oEdgeCollection As EdgeCollection
oEdgeCollection = ThisApplication.TransientObjects.CreateEdgeCollection

Dim oFillet As FilletFeature
For Each oFillet In oCompDef.Features.FilletFeatures
	oFillet.SetEndOfPart(True)
	For i = 1 To oFillet.FilletDefinition.EdgeSetCount
		For Each oEdge As Edge In oFillet.FilletDefinition.EdgeSetItem(i).Edges
			oEdgeCollection.Add(oEdge)
		Next
	Next
Next

For Each oFillet In oCompDef.Features.FilletFeatures
	oFillet.Delete
Next

If oEdgeCollection.Count = 0 Then Exit Sub

' Define the chamfer size
Dim chamferDistance As Double
chamferDistance = 0.1 ' Change this value to the desired chamfer size

Dim oChamfer As ChamferFeature
oChamfer = oDoc.ComponentDefinition.Features.ChamferFeatures.AddUsingDistance(oEdgeCollection, chamferDistance, True)

'oChamfer.SetEndOfPart(False)
ThisDoc.Document.ComponentDefinition.SetEndOfPartToTopOrBottom(False)

 

EESignature

0 Likes
Message 3 of 4

sferrer4DQ8Y
Explorer
Explorer
Thank you very much Curtis. It has been comforting to wake up and find a solution that I have been looking for for several weeks.
I will follow your always erudite comments carefully.
Message 4 of 4

Curtis_Waguespack
Consultant
Consultant

Adding another version of this here. This converts from fillet to chamfer and chamfer to fillet.

Note: It's not that well tested, so you might encounter issues.

Sub Main
	Dim oDoc As PartDocument
	oDoc = ThisDoc.Document
	
	Dim oTransMgr As TransactionManager
	oTransMgr = ThisApplication.TransactionManager
	
	' Start transaction
	Dim oTransaction As Transaction
	oTransaction = oTransMgr.StartTransaction(oDoc, "Convert Features")
	
	Dim Success As Boolean
	Success = SelectFeatures()
	
	If Success = False Then 
		' Abort transaction
		oTransaction.Abort()
		MessageBox.Show("Operation canceled. No changes were made.", "Convert Features")
	Else
		' End (commit) transaction
		oTransaction.End()
	End If
End Sub


Function SelectFeatures As Boolean
	Dim oDoc As PartDocument
	oDoc = ThisDoc.Document

	Dim oCompDef As PartComponentDefinition
	oCompDef = oDoc.ComponentDefinition
	
	Dim anyConverted As Boolean 
	anyConverted = False

	Dim oSelectedFeature As Object

	' Allow user to select and convert features one at a time
	While True
		
		oSelectedFeature = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFeatureFilter, "Select a fillet or chamfer feature to convert (press ESC when done)")

		If oSelectedFeature Is Nothing Then Exit While
		' User pressed ESC or canceled selection

		Dim success As Boolean
		success = False
		
		' Check if it's a fillet feature
		If TypeOf oSelectedFeature Is FilletFeature Then
			success = ConvertFilletToChamfer(oSelectedFeature)
		' Check if it's a chamfer feature
		ElseIf TypeOf oSelectedFeature Is ChamferFeature Then
			success = ConvertChamferToFillet(oSelectedFeature)
		End If		

		If success Then
			anyConverted = True
		End If
	End While

	Return anyConverted
End Function


Function ConvertFilletToChamfer(oSelectedFillet As Object) As Boolean
	Dim oFillet As FilletFeature = CType(oSelectedFillet, FilletFeature)

	' Get the fillet radius from the first parameter
	Dim chamferDistance As Double
	If oFillet.Parameters.Count > 0 Then
		chamferDistance = oFillet.Parameters.Item(1).Value
	Else
		MessageBox.Show("Could not read fillet radius. Skipping this fillet.", "Warning")
		Return False
	End If

	' Collect edges from this fillet
	Dim oEdgeCollection As EdgeCollection
	oEdgeCollection = ThisApplication.TransientObjects.CreateEdgeCollection

	oFillet.SetEndOfPart(True)
	For i = 1 To oFillet.FilletDefinition.EdgeSetCount
		For Each oEdge As Edge In oFillet.FilletDefinition.EdgeSetItem(i).Edges
			oEdgeCollection.Add(oEdge)
		Next
	Next

	' Delete the fillet
	oFillet.Delete

	' Create chamfer feature with the fillet's radius
	If oEdgeCollection.Count > 0 Then
		Dim oChamfer As ChamferFeature
		oChamfer = ThisDoc.Document.ComponentDefinition.Features.ChamferFeatures.AddUsingDistance(oEdgeCollection, chamferDistance, True)
		ThisDoc.Document.ComponentDefinition.SetEndOfPartToTopOrBottom(False)
		Return True
	End If
	
	Return False
End Function


Function ConvertChamferToFillet(oSelectedChamfer As Object) As Boolean
	Dim oChamfer As ChamferFeature = CType(oSelectedChamfer, ChamferFeature)

	' Get the chamfer distance from the first parameter
	Dim filletRadius As Double
	If oChamfer.Parameters.Count > 0 Then
		filletRadius = oChamfer.Parameters.Item(1).Value
	Else
		MessageBox.Show("Could not read chamfer distance. Skipping this chamfer.", "Warning")
		Return False
	End If

	' Collect edges from the chamfer by getting edges from the chamfered faces
	Dim oEdgeCollection As EdgeCollection
	oEdgeCollection = ThisApplication.TransientObjects.CreateEdgeCollection

	oChamfer.SetEndOfPart(True)
	
	' Get edges from chamfer faces
	' The chamfer creates faces, and we need to find the original edges
	' We'll get the edges from the chamfer by looking at the boundary edges of chamfer faces
	For i = 1 To oChamfer.Definition.ChamferedEdges.Count
		For Each oEdge As Edge In oChamfer.Definition.ChamferedEdges
			oEdgeCollection.Add(oEdge)
		Next
	Next

	' Delete the chamfer
	oChamfer.Delete

	' Create fillet feature with the chamfer's distance
	If oEdgeCollection.Count > 0 Then
		Dim oFillet As FilletFeature
		oFillet = ThisDoc.Document.ComponentDefinition.Features.FilletFeatures.AddSimple(oEdgeCollection, filletRadius, False)
		ThisDoc.Document.ComponentDefinition.SetEndOfPartToTopOrBottom(False)
		Return True
	End If
	
	Return False
End Function

 

EESignature

0 Likes