Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Changing punch representation with ilogic

Wojciech.Lebkowski
Contributor

Changing punch representation with ilogic

Wojciech.Lebkowski
Contributor
Contributor

 

 

Hello,

 

I'm trying to write an iLogic that changes the punch representation of certain punches. For now it takes the punch representation and checks if it is 64517 (which is 2D Sketch and center mark type), if it is not, then it should change it to that one. When running the code I got and error "Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))". Do you know how to change representation type to make it work?

 

Dim oDoc As PartDocument = ThisDoc.Document
Dim oPropSets As PropertySets = oDoc.PropertySets
Dim oSheetmetalCompDef As Inventor.SheetMetalComponentDefinition = oDoc.ComponentDefinition
Dim oCD As SheetMetalComponentDefinition = oDoc.ComponentDefinition
Dim currCount As Integer = 0
Dim oPunches As New List(Of String)
If oSheetmetalCompDef.HasFlatPattern Then
	For Each oPunch As PunchToolFeature In oCD.Features.PunchToolFeatures
		If oPunch.Suppressed = False Then
			Dim PunchID As String = oPunch.iFeatureDefinition.PunchId
			For i = 1 To oPunch.PunchCenterPoints.Count
				If PunchID <> ""
					oPunch.PunchRepresentationType = 64517
				End If
			Next
		End If
	Next
End If

 

 

 

0 Likes
Reply
Accepted solutions (2)
218 Views
2 Replies
Replies (2)

WCrihfield
Mentor
Mentor
Accepted solution

Hi @Wojciech.Lebkowski.  I attempted to fix the code for you.  If I eliminate the check for flat pattern and PunchId, this code works just fine in a test part.

Dim oDoc As PartDocument = ThisDoc.Document
Dim oPropSets As PropertySets = oDoc.PropertySets
Dim oSMDef As SheetMetalComponentDefinition = oDoc.ComponentDefinition
Dim oSMFeats As SheetMetalFeatures = oSMDef.Features
For Each oPunch As PunchToolFeature In oSMFeats.PunchToolFeatures
	If oPunch.Suppressed Then Continue For
	If oPunch.PunchRepresentationType <> _
		PunchRepresentationTypeEnum.k2DSketchAndCenterMarkPunchRepresentation Then
		oPunch.PunchRepresentationType = _
		PunchRepresentationTypeEnum.k2DSketchAndCenterMarkPunchRepresentation
	End If
Next

However, I did not see the representation of the punches visually change on the model screen, but I did see the description in () brackets after the iFeature node in the browser change from showing "Default", to showing "2D Sketch Rep and Center Mark", so I know it worked in my tests.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

WCrihfield
Mentor
Mentor
Accepted solution

I found the setting preventing the model from showing the representation as we have set it by code, both manually, and by code.  Manually, when you right-click on the Flat Pattern browser node in the model tree, then choose 'Edit Flat Pattern Definition', it will open a dialog.  Go to the 'Punch Representation' tab in that dialog, and you can see where these settings are available.  Obviously, these effect the flat pattern only, not the regular folded part representation.  That's why it was not effecting how the regular folded part looked.

 

If oSMDef.HasFlatPattern Then
	Dim oFP As FlatPattern = oSMDef.FlatPattern
	oFP.IgnorePunchToolFeaturesRepresentationOverrides = False

 

Once I set that to False, then went to my flat pattern, it was showing the way I set it by code.

Then there is also code for accessing the sketch edges of the resulting punches in the flat pattern:

 

oFP.FlatPunchResults.Item(1).SketchRepresentationEdges

 

Also, if you want all of your punches to be represented a certain way, not just certain ones, then there is actually a setting in the sheet metal style for punch representation type.

oSMDef.ActiveSheetMetalStyle.PunchRepresentationType

Wesley Crihfield

EESignature

(Not an Autodesk Employee)