Open corner round and set radius to .125?

Open corner round and set radius to .125?

jake_egley
Advocate Advocate
369 Views
5 Replies
Message 1 of 6

Open corner round and set radius to .125?

jake_egley
Advocate
Advocate

Need some help using the control definition edit. What I want is to open the corner round feature on the sheet metal ribbon and have the radius set to .125. The default is .25. 

jake_egley_0-1747747743621.png

So far I have:

ThisApplication.CommandManager.ControlDefinitions("SheetMetalCornerRoundCmd").Execute()

to open the corner round feature. now I need ilogic to change the radius to .125. I see there is a control definition called "SheetMetalCornerRoundEditCtxCmd" but I dont know how to use it.

Thanks.

Jake Egley
Inventor 2022
0 Likes
Accepted solutions (2)
370 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor
Accepted solution

Hi @jake_egley.  I doubt you will be able to do that.  We usually do not have any way to interact with 'user interface' dialogs by code.  We either have to do it manually, or by code, but not both ways at the same time.  Executing commands is like simulating user interface actions, such as clicking a button in the ribbon.  Problem is that often shows a dialog that is meant to be manually interacted with by the user, through the mouse &/or keyboard.  Sometimes there may be a way to further simulate mouse actions or keyboard actions, but doing so can also be dangerous, because it can be difficult to direct those actions to just that specific area of that specific dialog, instead of elsewhere in your computer's user interface.  If keystrokes accidentally get sent to the wrong place, who knows what it could do.

We usually do things through Inventor's API, by accessing objects, then using their properties or methods to accomplish tasks by code.  For example, we can create a CornerRoundFeature object by code using the API.

Document.ComponentDefinition.Features.CornerRoundFeatures....

Just in case you want to persist down the 'simulation' route, you can look into the System.Windows.Forms.SendKeys.SendWait method to help you 'send' some keystrokes out and hope they get put into that small edit box, within that dialog.  And also if going that route, you may need to navigate that dialog to highlight that control within the dialog, before sending those keystrokes out there, by sending 'Tab' key stokes, which can simulate using your keyboard to 'tab around' the different controls within the dialog, instead of clicking it with your mouse.  It may take a lot of trial & error testing to get the pattern down though.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 6

jake_egley
Advocate
Advocate

Using the API is even better than what I was thinking. If I can make a rule that rounds all corners in a sheet metal part with a .125 radius it would be a huge time saver. Then run that rule from an assembly and have it round all the corners in every sheet metal part in the assembly. 

Jake Egley
Inventor 2022
0 Likes
Message 4 of 6

jake_egley
Advocate
Advocate
Dim oDoc As PartDocument = ThisDoc.Document

If oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then

  Dim oCD As SheetMetalComponentDefinition = oDoc.ComponentDefinition
  Dim oEdge As Edge
  
	For Each oEdge In oDoc.(?????????)
	oDoc.ComponentDefinition.Features.CornerRoundFeatures(.125) /guess
	Next
  
End If

 

This is where I'm at. Not sure how to index thru all edges in the part or exactly how to use the cornerRoundFeatures in the API. Any help is appreciated

Jake Egley
Inventor 2022
0 Likes
Message 5 of 6

WCrihfield
Mentor
Mentor
Accepted solution

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

EESignature

(Not an Autodesk Employee)

Message 6 of 6

jake_egley
Advocate
Advocate

Perfect

Jake Egley
Inventor 2022
0 Likes