I'm trying to cycle through bend lines on a flat pattern in an idw to find the feature that created them. I have been able to loop through all drawing curves to find the bend lines, but have been unable to get the name of the feature that created them. I have posted the code I have below, with some pusedo code in the middle:
Function GetBendFeature(oView As DrawingView, BendName As String) As DrawingCurve Dim oReturnCurve As DrawingCurve Dim oPDoc As PartDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument Dim oPDef As SheetMetalComponentDefinition = oPDoc.ComponentDefinition For Each oCurve In oView.DrawingCurves If oCurve.EdgeType = Inventor.DrawingEdgeTypeEnum.kBendDownEdge Or oCurve.EdgeType = Inventor.DrawingEdgeTypeEnum.kBendUpEdge Then 'start pusedo code If oCurve.parentfeature.name = FeatureName Then oReturnCurve = ocurve End If 'end pusedo code End If Next oCurve 'exit if not found If oReturnCurve Is Nothing Then MessageBox.Show("Cannot find a flange called '" & BendName & "' in '" & oPDoc.DisplayName & "'.", "Error") Exit Function End If Return oReturnCurve End Function
How can I get the reference of the feature that created these drawing curves?
I'm trying to cycle through bend lines on a flat pattern in an idw to find the feature that created them. I have been able to loop through all drawing curves to find the bend lines, but have been unable to get the name of the feature that created them. I have posted the code I have below, with some pusedo code in the middle:
Function GetBendFeature(oView As DrawingView, BendName As String) As DrawingCurve Dim oReturnCurve As DrawingCurve Dim oPDoc As PartDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument Dim oPDef As SheetMetalComponentDefinition = oPDoc.ComponentDefinition For Each oCurve In oView.DrawingCurves If oCurve.EdgeType = Inventor.DrawingEdgeTypeEnum.kBendDownEdge Or oCurve.EdgeType = Inventor.DrawingEdgeTypeEnum.kBendUpEdge Then 'start pusedo code If oCurve.parentfeature.name = FeatureName Then oReturnCurve = ocurve End If 'end pusedo code End If Next oCurve 'exit if not found If oReturnCurve Is Nothing Then MessageBox.Show("Cannot find a flange called '" & BendName & "' in '" & oPDoc.DisplayName & "'.", "Error") Exit Function End If Return oReturnCurve End Function
How can I get the reference of the feature that created these drawing curves?
Hi @mitchELAHB . This is a simple example of getting Featere from Curve:
Sub main
Dim oDDoc As DrawingDocument = ThisDoc.Document
For Each oSheet As Sheet In oDDoc.Sheets
For Each oView As DrawingView In oSheet.DrawingViews
For Each oCurve As DrawingCurve In oView.DrawingCurves
Dim oBody As SurfaceBody = oCurve.ModelGeometry.Parent
MessageBox.Show(oBody.CreatedByFeature.Type.ToString(), oBody.CreatedByFeature.Name)
Exit Sub
Next
Next
Next
End Sub
Here I made changes to your code, please check if everything works:
Function GetBendFeature(oView As DrawingView, BendName As String) As DrawingCurve
Dim oReturnCurve As DrawingCurve
Dim oPDoc As PartDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim oPDef As SheetMetalComponentDefinition = oPDoc.ComponentDefinition
For Each oCurve As DrawingCurve In oView.DrawingCurves
If oCurve.EdgeType = Inventor.DrawingEdgeTypeEnum.kBendDownEdge Or oCurve.EdgeType = Inventor.DrawingEdgeTypeEnum.kBendUpEdge Then
Dim oBody As SurfaceBody = oCurve.ModelGeometry.Parent
'start pusedo code
If oBody.CreatedByFeature.Name = FeatureName Then
oReturnCurve = oCurve
End If
'end pusedo code
End If
Next oCurve
'exit if not found
If oReturnCurve Is Nothing Then
MessageBox.Show("Cannot find a flange called '" & BendName & "' in '" & oPDoc.DisplayName & "'.", "Error")
Exit Function
End If
Return oReturnCurve
End Function
Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor
LinkedIn | My free Inventor Addin | My Repositories
Did you find this reply helpful ? If so please use the Accept as Solution/Like.
Hi @mitchELAHB . This is a simple example of getting Featere from Curve:
Sub main
Dim oDDoc As DrawingDocument = ThisDoc.Document
For Each oSheet As Sheet In oDDoc.Sheets
For Each oView As DrawingView In oSheet.DrawingViews
For Each oCurve As DrawingCurve In oView.DrawingCurves
Dim oBody As SurfaceBody = oCurve.ModelGeometry.Parent
MessageBox.Show(oBody.CreatedByFeature.Type.ToString(), oBody.CreatedByFeature.Name)
Exit Sub
Next
Next
Next
End Sub
Here I made changes to your code, please check if everything works:
Function GetBendFeature(oView As DrawingView, BendName As String) As DrawingCurve
Dim oReturnCurve As DrawingCurve
Dim oPDoc As PartDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim oPDef As SheetMetalComponentDefinition = oPDoc.ComponentDefinition
For Each oCurve As DrawingCurve In oView.DrawingCurves
If oCurve.EdgeType = Inventor.DrawingEdgeTypeEnum.kBendDownEdge Or oCurve.EdgeType = Inventor.DrawingEdgeTypeEnum.kBendUpEdge Then
Dim oBody As SurfaceBody = oCurve.ModelGeometry.Parent
'start pusedo code
If oBody.CreatedByFeature.Name = FeatureName Then
oReturnCurve = oCurve
End If
'end pusedo code
End If
Next oCurve
'exit if not found
If oReturnCurve Is Nothing Then
MessageBox.Show("Cannot find a flange called '" & BendName & "' in '" & oPDoc.DisplayName & "'.", "Error")
Exit Function
End If
Return oReturnCurve
End Function
Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor
LinkedIn | My free Inventor Addin | My Repositories
Did you find this reply helpful ? If so please use the Accept as Solution/Like.
Hi, thanks for the reply.
I get an "Object reference not set to an instance of an object." error when the code gets to the line:
If oBody.CreatedByFeature.Name = BendName Then
I tried running an edited version of the the sample code supplied:
Sub main Dim oDDoc As DrawingDocument = ThisDoc.Document For Each oSheet As Sheet In oDDoc.Sheets For Each oView As DrawingView In oSheet.DrawingViews For Each oCurve As DrawingCurve In oView.DrawingCurves Dim oBody As SurfaceBody = oCurve.ModelGeometry.Parent logger.trace(oBody.CreatedByFeature.Name & " " & oBody.CreatedByFeature.Type.ToString()) Next Next Next End Sub
but eventually would run into the error "No such interface supported" on the line:
logger.trace(oBody.CreatedByFeature.Name & " " & oBody.CreatedByFeature.Type.ToString())
I believe the issue stems from the fact that the view is a flat pattern, but the feature that created that bend line is part of the folded model. What should I try next?
Hi, thanks for the reply.
I get an "Object reference not set to an instance of an object." error when the code gets to the line:
If oBody.CreatedByFeature.Name = BendName Then
I tried running an edited version of the the sample code supplied:
Sub main Dim oDDoc As DrawingDocument = ThisDoc.Document For Each oSheet As Sheet In oDDoc.Sheets For Each oView As DrawingView In oSheet.DrawingViews For Each oCurve As DrawingCurve In oView.DrawingCurves Dim oBody As SurfaceBody = oCurve.ModelGeometry.Parent logger.trace(oBody.CreatedByFeature.Name & " " & oBody.CreatedByFeature.Type.ToString()) Next Next Next End Sub
but eventually would run into the error "No such interface supported" on the line:
logger.trace(oBody.CreatedByFeature.Name & " " & oBody.CreatedByFeature.Type.ToString())
I believe the issue stems from the fact that the view is a flat pattern, but the feature that created that bend line is part of the folded model. What should I try next?
Can't find what you're looking for? Ask the community or share your knowledge.