ilogic code seens to cause error in inventor on one computer but not the rest (over 10 computer ) any Idear why ?

ilogic code seens to cause error in inventor on one computer but not the rest (over 10 computer ) any Idear why ?

Darkforce_the_ilogic_guy
Advisor Advisor
165 Views
0 Replies
Message 1 of 1

ilogic code seens to cause error in inventor on one computer but not the rest (over 10 computer ) any Idear why ?

Darkforce_the_ilogic_guy
Advisor
Advisor

one of our computer at work, have a very unik problem. 

 

When it save an sheetmetal my code create an flatpattern if it missing.  but on one computer .. when it created an flatpattern.  it some how hidde the flatpattern feature.. and some of the buttom on the ribbon as well

 

 

it is inventor 2020

 

 

Option explicit On


' If sheetmetal part and no flatpattern exists then the part will be unfolded
'opdated by BT to always take the side with most upward bend
Sub Main
	Logger.Info("Start Ensure Flate pattern Script")

	Dim fName As String = "No filename"
	Dim sDocumentSubType As String = ThisDoc.Document.SubType 
	If Not sDocumentSubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Return	' Only run on sheetmetalparts
	Logger.Info("Ensure Flate pattern  : This is an Sheet Metal part")
	Dim doc As PartDocument
	Try
		doc = ThisDoc.Document
		Try
			fName = doc.FullFileName
		Catch
			Logger.Info("Ensure Flate pattern  : fail to find filename")
		End Try
		Dim smCompDef As SheetMetalComponentDefinition = doc.ComponentDefinition
		Dim fs As PartFeatures = smCompDef.Features
		If fs.count=0 then exit sub
		If Not smCompDef.HasFlatPattern Then 
			
			
			' cancel by bt Call smCompDef.Unfold
			CreateFlatpattern()
			
			'new code to exit flatpattern
			smCompDef.FlatPattern.ExitEdit	
			'new code to exit flatpattern ended here
			debug("Flatpattern created in '" & fName & "'")
		End If
	Catch ex As Exception
		Logger.Info("Ensure Flate pattern  : fail to Create flatpattern")
		'MessageBox.Show("Error creating flatpattern in" & vbCr & fName & vbCr & vbCr & ex.Message,"Error, iLogic rule 'EnsureFlatpattern'",MessageBoxButtons.OK,MessageBoxIcon.Exclamation)
	End Try
End Sub

Public Sub debug(txt As String)
	Trace.WriteLine("NTI : " & txt)
End Sub

'add by BT
Sub CreateFlatpattern()
	Logger.Info("Ensure Flate pattern  : Start to Create Flatpattern")
	'Get active document and its SheetMetalComponentDefinition
	'Otherwise exit method
	Dim doc As PartDocument
	Dim smCompDef As SheetMetalComponentDefinition
	Try
		doc = ThisDoc.Document
		smCompDef = doc.ComponentDefinition
	Catch
		MsgBox("Operation is valid only in sheetmetal part")
		Return
	End Try

	'Exit sub when part has flatpattern
	If (smCompDef.HasFlatPattern) Then Return

	'Begin transaction
	Dim t As Transaction = ThisApplication.TransactionManager.StartTransaction(doc, "CreateFlatpattern")
	Try

		'Create checkpoint for test unfold
		Dim checkPoint As CheckPoint = ThisApplication.TransactionManager.SetCheckPoint()
		smCompDef.Unfold()

		'Check how many bends is up or down
		Dim flatPattern As FlatPattern = smCompDef.FlatPattern
		Dim up, down As Integer
		For Each bendResult As FlatBendResult In flatPattern.FlatBendResults
			If bendResult.IsOnBottomFace Then Continue For
			If bendResult.IsDirectionUp Then
				up += 1
			Else
				down += 1
			End If
		Next

		'When current flatpattern has more down bends then up bends
		'create unfold for back side
		If down > up Then
			'Look for planar face on other side
			Dim baseFace As Face = NewBaseFace(flatPattern)

			'Undo previous unfold operation
			ThisApplication.TransactionManager.GoToCheckPoint(checkPoint)

			'Create new unfold
			smCompDef.Unfold2(baseFace)
		End If

		'Finish transaction
		t.End()
	Catch
		'Abort transaction (undo all steps)
		t.Abort()
	End Try

End Sub


'Add by bt
Private Function NewBaseFace(flatPattern As FlatPattern) As Face
	For Each bendResult As FlatBendResult In flatPattern.FlatBendResults
		If Not bendResult.IsOnBottomFace Then Continue For
		For Each backFace As Face In bendResult.Bend.BackFaces
			For Each face As Face In backFace.TangentiallyConnectedFaces
				If Face.SurfaceType = SurfaceTypeEnum.kPlaneSurface Then
					Return Face
				End If
			Next
		Next
	Next
	Return Nothing
End Function

sd

 

 

0 Likes
166 Views
0 Replies
Replies (0)