Inventor VBA accessing corner features of a flange

Inventor VBA accessing corner features of a flange

bradley_rinschen
Participant Participant
419 Views
5 Replies
Message 1 of 6

Inventor VBA accessing corner features of a flange

bradley_rinschen
Participant
Participant

I am trying to write a vba script to look at the flanges modeled within a sheet metal part and determine if they have a corner feature that is accessible. Essentially what I'm going for is whether the flange feature has more than 1 flange added and do they share a vertex, thus creating a corner feature. The flange feature creates a corner feature always, but unless there is a corner created within that flange, right-clicking on it to edit it results in an error message. I want VBA to essentially do that. However, it doesn't seem to matter how I try to access it following the object model map, I can't see anything useful. The sub here is as close as I think I've come, but it still just errors out on the 'for each ocornerfeature in oflangefeature' line and it doesn't seem to matter what i put after the 'oflangefeature'. Has anyone ever tried to do this? I'm not great at reading the object model map but I can gain access to flangedefinition-corneroptions and that doesn't seem to have anything useful in it either. Do I need to conduct a test? try to change a value and if I can't then it must not have a corner? I've been fighting this for a week now with no progress. Here's what I have so far, again this errors out. 

 

Sub sheetmetalfeaturedisplay()

Dim oPartDoc As PartDocument
Set oPartDoc = ThisApplication.ActiveDocument

Dim osheetmetalcompdef As SheetMetalComponentDefinition
Set osheetmetalcompdef = oPartDoc.ComponentDefinition

Dim oFlangeFeature As flangeFeature
Dim oFeature As PartFeature
Dim oCornerFeature As cornerFeature

For Each oFeature In osheetmetalcompdef.Features
If TypeOf oFeature Is flangeFeature Then
Set oFlangeFeature = oFeature

Debug.Print "Flange Feature: " & oFlangeFeature.name

' Accessing CornerFeatures directly from FlangeFeature
For Each oCornerFeature In oFlangeFeature
Debug.Print "Corner Feature: " & oCornerFeature.name
' You can access other properties of oCornerFeature here
Next oCornerFeature

End If
Next

End Sub

0 Likes
Accepted solutions (1)
420 Views
5 Replies
Replies (5)
Message 2 of 6

bradley_rinschen
Participant
Participant

As far as I can tell, the following code SHOULD expose the cornerfeature property per the API Object model, but it doesn't. At least looking thru the Locals window I don't see it or anything remotely related. I did find the property for 'automitercorners', but not whether the corner itself exists. I attached a screenshot of the Locals window where the cornerfeature property should show up. 

 

Sub sheetmetalfeaturedisplay1()

Dim opartdoc As PartDocument
Set opartdoc = ThisApplication.ActiveDocument

Dim oSheetMetalCompDef As SheetMetalComponentDefinition
Set oSheetMetalCompDef = opartdoc.ComponentDefinition

Dim oFlangeFeature As flangeFeature
Dim oFeature As PartFeature

Debug.Print oSheetMetalCompDef.Features.Count

For Each oFeature In oSheetMetalCompDef.Features
If TypeOf oFeature Is flangeFeature Then
Set oFlangeFeature = oFeature

Debug.Print "Flange Feature: " & oFlangeFeature.name
Debug.Print oFlangeFeature.Definition.ApplyAutoMitering ''''!!!!!So this is really important to have found


End If
Next

End Sub

0 Likes
Message 3 of 6

WCrihfield
Mentor
Mentor

Not sure if this helps any, but there is also the FlangeDefinition.CornerOptions property, which returns a CornerOptions object, which has the CornerOptions.IsTwoBend property, but it sounds like it may only distinguish between 2 or 3 bend situations.  If the FlangeDefinition.Edges collection has multiple items in it, then you may be able to test if any of them intersect each other, and if so, there should be a 'corner'.  Then there is the idea of approaching this from the main CornerFeatures collection, iterating each CornerFeature, and maybe inspecting their CornerDefinition and CornerDefinition.Edges collection, and trying to trace those edges back to the FlangeFeature.  That also sounds like a long road though.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 6

bradley_rinschen
Participant
Participant

thanks for the response. Here's what I've learned on this:

 

The istwobend property did not change in going between 1 and 2 flanges added in a single feature that intersected. (I couldn't find any given property that changed in a lot of testing)

 

I have learned that the CornerFeatures collection solely refers to features added in the model tree via the 'corner seam' feature, so there wasn't anything to be gained there, despite it being essentially the same feature, it isn't found in the same way anyway.

 

I haven't spent much time in the 'edges' collection but I didn't see anything in there the first time thru. I'll take another look. I'm mostly just confused why the 'cornerfeature' is on the API Object model map and yet it doesn't exist within FlangeFeature. 

0 Likes
Message 5 of 6

WCrihfield
Mentor
Mentor
Accepted solution

Hi @bradley_rinschen.  I explored into the Edges of the FlangeDefinition this morning, out of curiosity.  At first, I was surprised, because the Edges property returned 'Nothing'.  Then I thought about that a moment, and considered that those edges no longer exist, because the feature changed (or eliminated) them.  So, I looked into using the FlangeFeature.SetEndOfPart method, to rewind the modeling history to just before that feature was created, then try getting those edges from the definition, and that seemed to work OK.  Once I got past that roadblock, I was able to inspect the edges to see if there was more than one, and if so, do any of them intersect each other.  If so, then we know that there should have been a 'corner' made automatically by the feature.

I know you said you were working with VBA, but I stopped using that a few years ago, so my exploratory code is in the form of an iLogic rule instead.  That code is below.  I think most of that could be converted to VBA if necessary, but it would likely require 2 to 3 times as many lines of code to do so, due to VBA being an older coding system.

Sub Main
	Dim oPDoc As PartDocument = TryCast(ThisDoc.Document, Inventor.PartDocument)
	If oPDoc Is Nothing Then Return
	If Not TypeOf oPDoc.ComponentDefinition Is SheetMetalComponentDefinition Then Return
	Dim oSMDef As SheetMetalComponentDefinition = oPDoc.ComponentDefinition
	Dim oSMFeats As SheetMetalFeatures = oSMDef.Features
	Dim oFlFeatsWithCorners As New List(Of FlangeFeature)
	Dim oTrans As Inventor.Transaction = ThisApplication.TransactionManager.StartTransaction(oPDoc, "Find FlangeFeats With Corners")
	Try
		For Each oFlFeat As FlangeFeature In oSMFeats.FlangeFeatures
			oFlFeat.SetEndOfPart(True)
			Dim oFlDef As FlangeDefinition = oFlFeat.Definition
			Dim oDefEdges As EdgeCollection = oFlDef.Edges
			If oDefEdges Is Nothing Then
				Logger.Debug("FlangeDefinition.Edges Property Value Is Nothing.")
				Continue For
			ElseIf oDefEdges.Count = 0 Then
				Logger.Debug("FlangeDefinition.Edges Property Value's Count = 0.")
				Continue For
			End If
			Dim bIntersectionFound As Boolean = False
			Dim oVertices As New List(Of Inventor.Vertex)
			For Each oDefEdge As Edge In oDefEdges
				Dim oV1 As Inventor.Vertex = Nothing
				Dim oV2 As Inventor.Vertex = Nothing
				Try : oV1 = oDefEdge.StartVertex : Catch : End Try
				Try : oV2 = oDefEdge.StopVertex : Catch : End Try
				If oV1 IsNot Nothing Then
					For Each oVtx As Inventor.Vertex In oVertices
						If oVtx.Point.IsEqualTo(oV1.Point, 0.001) Then
							bIntersectionFound = True
							Exit For
						End If
					Next 'oVtx
					If Not bIntersectionFound Then oVertices.Add(oV1)
				End If
				If bIntersectionFound Then
					Exit For
				End If
				If oV2 IsNot Nothing Then
					For Each oVtx As Inventor.Vertex In oVertices
						If oVtx.Point.IsEqualTo(oV2.Point, 0.001) Then
							bIntersectionFound = True
							Exit For
						End If
					Next 'oVtx
					If Not bIntersectionFound Then oVertices.Add(oV2)
				End If
				If bIntersectionFound Then
					Exit For
				End If
				Next oDefEdge
			If bIntersectionFound Then
				oFlFeatsWithCorners.Add(oFlFeat)
			End If
			oFlFeat.SetEndOfPart(False)
		Next oFlFeat
		If oFlFeatsWithCorners.Count > 0 Then
			MsgBox(oFlFeatsWithCorners.Count & " FlangeFeatures were found with 'corners'.", , "")
		Else
			MsgBox("No FlangeFeatures were found with 'corners'.", , "")
		End If
	Finally
		oTrans.Abort()
	End Try
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

bradley_rinschen
Participant
Participant

dear...lord... So that absolutely works in trials. Seems like an absurd way to go about it when the property itself SHOULD simply exist per the API Object model from autodesk, but I'll take it. 

 

I actually need this running in both iLogic and VBA because some users don't like the vba interface that has been built and refuse to use it, so you just saved me a TON of work. While I've been tempted to FORCE them to use it, the path of least resistance for now is to operate in both locations. It's FAR easier for me to go from iLogic to VBA because I don't "speak" iLogic at all and just rely on chatgpt to turn my vba into ilogic. It should have no problem going the other way around. I just need to add to this a check to insure auto-mitering is activated on this flange and it should do exactly what I'm after. Essentially I'm looking for "did the designer take the time to make nice corners, then it probably needs the corners welded" as part of some auto-routing I'm doing for the factory. Finding corner features explicitly added was easy but this one was killing me and I wasted a solid week on it. 

 

Cannot thank you enough. 

 

 

0 Likes