Flat Pattern Disappears in darwing.

Flat Pattern Disappears in darwing.

AnthonyB7
Enthusiast Enthusiast
268 Views
2 Replies
Message 1 of 3

Flat Pattern Disappears in darwing.

AnthonyB7
Enthusiast
Enthusiast

Good day Everyone! 

 

I have a code here in iLogic that would create a flat pattern on a sheet metal part once it is saved. This works great and when I create a drawing for the part and I place the flat pattern view in the drawing it shows perfectly in the drawing. The problem now is that when I modify the part or just re-saving it again, it deletes the flat pattern view in the drawing. I don't know if my code is incorrect, do I have to specify base face all the time or is it an inventor issue. (See code below)

 

On Error Resume Next

Dim oDoc = ThisApplication.ActiveDocument

'CHECK FILE TYPE
If oDoc.DocumentType <> kPartDocumentObject Then
	Return
End If

Dim oCompDef As SheetMetalComponentDefinition
oCompDef = oDoc.ComponentDefinition

oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"
	'CREATE FLAT PATTERN IF DOESN'T EXIST
	If oCompDef.Type = 150995200
		ThisApplication.ScreenUpdating = False 
		oCompDef.Unfold()
		ThisApplication.ScreenUpdating = True
		'oDoc.ComponentDefinition.FlatPattern.Edit()
		oCompDef.FlatPattern.ExitEdit
	End If
Dim extents_length As String = Round(SheetMetal.FlatExtentsLength, 3)
Dim extents_width As String = Round(SheetMetal.FlatExtentsWidth, 3)

iProperties.Value("Custom", "Height") = extents_length
iProperties.Value("Custom", "Width") = extents_width

 

 

0 Likes
Accepted solutions (1)
269 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor
Accepted solution

Hi @AnthonyB7.  I am not 100% sure that this is the main problem, but after reviewing your code, it looks like it would be trying to set the document SubType and unfold the part each time around, even if it was not needed, because it is not checking those things beforehand.  I don't know if that would cause your view of the flat pattern to disappear or not though.  I created a very similar iLogic code for the same task, but included some extra checks in there, so it will not try to change the documents SubType if it is not necessary, and it will not try to re-create the FlatPattern, if it already exists.  I also included a couple Try...Catch blocks in there to help handle the potential error those actions might possibly cause.

Here is the modified code you can try:

If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then
	MsgBox("A Part Document must be active for this rule to work. Exiting.", vbCritical, "")
	Exit Sub
End If
Dim oPDoc As PartDocument = ThisDoc.Document
Dim oSMDef As SheetMetalComponentDefinition = Nothing
If TypeOf oPDoc.ComponentDefinition Is SheetMetalComponentDefinition Then
	oSMDef = oPDoc.ComponentDefinition
Else
	Try
		oPDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"
		oSMDef = oPDoc.ComponentDefinition
	Catch
		MsgBox("Error converting non-sheet metal part to sheet metal.", vbCritical, "")
		Exit Sub
	End Try
End If
Dim oFP As FlatPattern = Nothing
If oSMDef.HasFlatPattern Then
	oFP = oSMDef.FlatPattern
Else
	Try
		ThisApplication.ScreenUpdating = False
		oSMDef.Unfold
		oSMDef.FlatPattern.ExitEdit
		ThisApplication.ScreenUpdating = True
		oFP = oSMDef.FlatPattern
	Catch
		MsgBox("Error Unfolding part to craete FlatPattern.", vbCritical, "")
		Exit Sub
	End Try
End If
Dim extents_length As String = Round(SheetMetal.FlatExtentsLength, 3)
Dim extents_width As String = Round(SheetMetal.FlatExtentsWidth, 3)
iProperties.Value("Custom", "Height") = extents_length
iProperties.Value("Custom", "Width") = extents_width

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 3 of 3

AnthonyB7
Enthusiast
Enthusiast
@WCrihfield this code is not my original. It was given to me from one of the users here at the forum. Basically I want to auto create a flat pattern on sheet metal parts through iLogic and triggered to activate once the save button is clicked. Also with the code, I would like to link the bounding box dimensions to our parts list template which it does on this code, I think its the bottom end of it.

I have tried out the code you created/modified for me and it is working great. I changed the model and it updated the bounding box dimensions when I click on save and it automatically updates the drawing as well. The flat pattern do not disappear anymore on my drawing. Thank you.
0 Likes