Define A-Side from Assembly

Define A-Side from Assembly

evan.wondra
Enthusiast Enthusiast
1,374 Views
7 Replies
Message 1 of 8

Define A-Side from Assembly

evan.wondra
Enthusiast
Enthusiast

Hello,
I am wanting to create some iLogic that will be run from an assembly file, and it will look at each part and see if A-Side has been defined. If it has not been defined, it will delete the flat pattern (if one exists) and then pause and allow users to define A-Side. The portion of the code I am having issues with is below. If I run that from an individual part file, it works. However when I run a different rule from an assembly file that opens up all parts and then runs this rule, it does not work. It acts the same, but it does not actually define the A-Side. 
Any help on this is much appreciated.

 

Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument
Dim oCompDef As SheetMetalComponentDefinition
oCompDef = oDoc.ComponentDefinition

If oCompDef.ASideFaceStatus.ToString <> "kASideUpToDate" Then
	MessageBox.Show("MUST DEFINE A-SIDE " & iProperties.Value("Project", "Part Number"), "DEFINE A-SIDE", MessageBoxButtons.OKCancel, MessageBoxIcon.Stop)
	End If
	
	'Delete Flat Pattern if no A-Side
	If oCompDef.ASideFaceStatus.ToString <> "kASideUpToDate" Then
		iLogicVb.RunExternalRule("DELETE FLAT PATTERNS")
		End If
		
	'Start Define A-Side Command
		If oCompDef.ASideFaceStatus.ToString <> "kASideUpToDate" Then
			Dim face As Inventor.Face
		face = ThisApplication.CommandManager.Pick(Inventor.SelectionFilterEnum.kPartFaceFilter, "Define A-Side")
		Call ThisApplication.CommandManager.ControlDefinitions.Item("SheetMetalCreateASideCmd").Execute		
End If

 

0 Likes
Accepted solutions (2)
1,375 Views
7 Replies
Replies (7)
Message 2 of 8

dalton98
Collaborator
Collaborator
Accepted solution

Add this. Also on your first if statement you would need to change it to 'If Not'

Dim oAss As AssemblyDocument
oAss = ThisApplication.ActiveDocument
Dim oOcc As ComponentOccurrence
'all parts in assembly For Each oOcc In oAss.ComponentDefinition.Occurrences.AllLeafOccurrences
If Not oOcc.Definition.ASideDefinitions.Count = 0 Then Continue For
Dim oDoc As PartDocument oDoc = ThisApplication.Documents.Open(oOcc.Definition.Document.FullFileName, True)

'your code

oDoc.Save
oDoc.Close
Next

 

0 Likes
Message 3 of 8

evan.wondra
Enthusiast
Enthusiast

Thanks  for the quick response! That additional code allows me to run it from an assembly file, however it is still not keeping the selected side as my A-Side. I attached an image of the part and the model tree. It opened up the part and allowed me to select a face, but it does not keep that selection to be used as my defined A-Side

0 Likes
Message 4 of 8

dalton98
Collaborator
Collaborator
Accepted solution

try selecting the face after picking it, then clearing the select after you define the a-side.

Dim oDoc As PartDocument = ThisApplication.ActiveDocument
Dim face As Inventor.Face
face = ThisApplication.CommandManager.Pick(Inventor.SelectionFilterEnum.kPartFaceFilter, "Define A-Side")

oDoc.SelectSet.Select(face)
ThisApplication.CommandManager.ControlDefinitions.Item("SheetMetalCreateASideCmd").Execute
oDoc.SelectSet.Clear

 Edit: I was wrong you dont need to change the if statement(not used to that notation). You could put them all under one if statement adding the extra 'If oCompDef.Aside...' isnt nessessary

 

0 Likes
Message 5 of 8

dalton98
Collaborator
Collaborator

I change the my first post so it checks if an A-side exists before it tries to open the part

0 Likes
Message 6 of 8

evan.wondra
Enthusiast
Enthusiast

Yes, that worked!! Thank you for all your help

0 Likes
Message 7 of 8

cadEY2BL
Explorer
Explorer

@evan.wondra 

 

Could you post your complete code? 

 

0 Likes
Message 8 of 8

evan.wondra
Enthusiast
Enthusiast

Yes, I had to split it into two different rules so I will post both below. 

If ThisApplication.ActiveDocumentType = "12290" Then

	Dim oDoc As PartDocument = ThisApplication.ActiveDocument
	Dim face As Inventor.Face
	Dim oCompDef As SheetMetalComponentDefinition
	oCompDef = oDoc.ComponentDefinition
	
	If oCompDef.ASideFaceStatus.ToString <> "kASideUpToDate" Then
		MessageBox.Show("MUST DEFINE A-SIDE " & iProperties.Value("Project", "Part Number"), "DEFINE A-SIDE", MessageBoxButtons.OK, MessageBoxIcon.Stop)

		iLogicVb.RunExternalRule("DELETE FLAT PATTERNS")

		face = ThisApplication.CommandManager.Pick(Inventor.SelectionFilterEnum.kPartFaceFilter, "Define A-Side")

		oDoc.SelectSet.Select(face)
		ThisApplication.CommandManager.ControlDefinitions.Item("SheetMetalCreateASideCmd").Execute2(True)
		oDoc.SelectSet.Clear
		oDoc.ComponentDefinition.Unfold
		oDoc.ComponentDefinition.FlatPattern.ExitEdit
	End If
End If
' Check the document type
If ThisApplication.ActiveDocument.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
	' Define the active assembly
	Dim oAssyDoc As AssemblyDocument
	oAssyDoc = ThisApplication.ActiveDocument
	' Check all referenced docs 
	For Each oDoc As Document In oAssyDoc.AllReferencedDocuments
		' Check if the part is sheet metal
		If oDoc.DocumentSubType.DocumentSubTypeID = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
			' Get sheet metal component definition
			Dim oSMCD As Inventor.SheetMetalComponentDefinition
			oSMCD = oDoc.ComponentDefinition
			' Check If it has flatpattern
			If oSMCD.HasFlatPattern = True Then
				' Atempt to delete it
				Try
					oSMCD.FlatPattern.Delete
				Catch
				End Try
			End If
		End If
	Next
ElseIf ThisApplication.ActiveDocument.DocumentSubType.DocumentSubTypeID = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
	' Get the sheetmetal component definition
	Dim oSMCD As Inventor.SheetMetalComponentDefinition
	oSMCD = ThisApplication.ActiveDocument.ComponentDefinition
	' Check If it has flatpattern
	If oSMCD.HasFlatPattern = True Then
		' Atempt to delete it
		Try
			oSMCD.FlatPattern.Delete
		Catch
		End Try
	End If
End If
' Update the files
InventorVb.DocumentUpdate()

 

0 Likes