Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Finding feature name that created a DrawingCurve in IDW

2 REPLIES 2
Reply
Message 1 of 3
mitchELAHB
246 Views, 2 Replies

Finding feature name that created a DrawingCurve in IDW

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? 

2 REPLIES 2
Message 2 of 3

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 - Leading design engineer

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

Message 3 of 3

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.

Post to forums  

Autodesk Design & Make Report