Hi @jake_egley. Sure, I can help you with that. Keep in mind that there can be tons of 'edges' in a sheet metal part, and most will likely not be appropriate to use as the input edge for a corner round feature. So, because of that fact, I have included a Try...Catch...End Try block of code in this, which is being used to 'handle' the potential errors from trying to create one of those features with inappropriate edges, and allow the code continue past those errors, without stopping the whole code process. It would be more intuitive if you had a better way of specifying exactly which edges you wanted to work with in each part. One thing that comes to mind is assigning names to those specific few edges, but then again, if you took the time to assign names to edges, you might as well have just added the features to those parts when you created them, so it sort of defeats the purpose. Because of this awkward situation, the code is designed to create a separate corner round feature for each appropriate edge, instead of attempting to bundle multiple edges together in one (or fewer) feature(s).
This rule is designed so that it can be used from either a part, or an assembly, but not from a drawing (could be further developed for that also). If the 'current' document is a part, it will process that one part. If the current document is an assembly, it will iterate through all of its referenced documents, processing each one of those. Then at the end, it updates the current document.
Sub Main
Dim oDoc As Inventor.Document = ThisDoc.Document
'radius value can be specified as either a numerical value
'or as a String (text)
'if a numerical value is specified, it will be understood as being in centimeters
'if using a String, the units specifier can be incluced (after a space), and understood that way
'therefore, I recommend using a String
Dim Radius = "0.125 in"
'if this document is a part, then it will be 'processed' by the custom Sub routine
'if this is an assembly, it will iterate through all referenced documents and process those
If TypeOf oDoc Is PartDocument Then
AddCornerRoundsToAllCorners(oDoc, Radius)
ElseIf TypeOf oDoc Is AssemblyDocument Then
For Each oRefDoc As Inventor.Document In oDoc.AllReferencedDocuments
AddCornerRoundsToAllCorners(oRefDoc, Radius)
Next 'oRefDoc
Else 'maybe a drawing or presentation, can not use those
Return
End If
'update the current document, this will also usually update referenced documents
oDoc.Update2(True)
End Sub
Sub AddCornerRoundsToAllCorners(doc As Inventor.Document, _
radius As Object)
If (doc Is Nothing) OrElse (Not TypeOf doc Is PartDocument) Then Return
If radius Is Nothing Then Return
Dim oPDoc As PartDocument = doc
If Not TypeOf oPDoc.ComponentDefinition Is SheetMetalComponentDefinition Then Return
Dim oSMDef As SheetMetalComponentDefinition = oPDoc.ComponentDefinition
Dim oSMFeats As SheetMetalFeatures = oSMDef.Features
Dim oCRFeats As CornerRoundFeatures = oSMFeats.CornerRoundFeatures
Dim oEdgeColl As EdgeCollection = ThisApplication.TransientObjects.CreateEdgeCollection()
For Each oBody As SurfaceBody In oSMDef.SurfaceBodies
For Each oEdge In oBody.Edges
oEdgeColl.Clear()
oEdgeColl.Add(oEdge)
Dim oCRFeatDef As CornerRoundDefinition = Nothing
Dim oCRFeat As CornerRoundFeature = Nothing
'try to do something that might cause an error
'if it fails (causes an error), the code will continue, instead of stopping
Try
oCRFeatDef = oCRFeats.CreateCornerRoundDefinition(oEdgeColl, radius)
oCRFeat = oCRFeats.Add(oCRFeatDef)
Catch ex As Exception 'capturing the Exception object to a variable
'what to do if that failed (caused an error)
'in this case, we could just log the error to the iLogic Log window
'but I left this next line commented out for not, because not that useful
'Logger.Error(ex.ToString)
End Try
Next 'oEdge
Next 'oBody
'doc.Update2(True)
End Sub
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield

(Not an Autodesk Employee)