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

I'm just assuming this is a global iLogic form with for the following attempt at a solution.

I have written an iLogic code that I'm hoping will do what you want it to.

Because an iLogic form is always acting on whatever document is "Active" at the time it is launched, I couldn't identify the assembly as ThisDoc.Document or ThisApplication.ActiveDocument, because we want the 'active' document to be one of the documents referenced within the assembly, when it is launched (at least for the second time it is launched).

As you said before, this is likely new ground I'm attempting to cover here, so bare with me.

 

The first section of the code attempts to make sure it is referencing the correct assembly file.

If it is the first time you run the rule, it will likely ask you about the assembly file, but after the first run, it should have saved the assembly's file name to a SharedVariable, for use the next time.

If the shared variable isn't found, it will first ask you if the assembly document is the active document.

If so, it sets oADoc to the active document, but if not, it proceeds to show you the Open file dialog box for you to select it.

Once the assembly file if found and the oADoc variable's value is set correctly, it proceeds to the Cycle portion.

 

The cycle portion attempts to activate the next referenced document within the assembly, using another SharedVariable to store & retrieve an Integer which specifies which document it worked with last time.

 

The last section of the code launches the form.

It should wait for you to do what you want to do within that form.

Then, when the form is closed, the code attempts to determine how the form was closed.

If it was closed due to you clicking on the specific rule button, it will proceed with the rest of the rule, to cycle to the next reference document within the assembly.

If it wasn't closed by that rule button, it simply exits the code.

 

It's the end of the day here, and it's still untested, but go ahead and give it a try:

 

'[ Get the main assembly
GetAssembly :
Dim oADoc As AssemblyDocument
Dim oAsmName As String
Dim oFileDlg As Inventor.FileDialog = Nothing
If SharedVariable.Exists("FullDocumentName") Then
	oAsmName = SharedVariable.Value("FullDocumentName")
	Try
		oADoc = ThisApplication.Documents.ItemByName(oAsmName)
	Catch
		MsgBox("Main assembly was not open." & vbCrLf & _
		"Attempting to open it now.",vbOKOnly,"ASSEMBLY NOT OPEN")
		oADoc = ThisApplication.Documents.Open(oAsmName)
	End Try
Else
	oActive = MsgBox("Is the assembly the active document?", vbYesNo + vbQuestion, "ACTIVE ASSEMBLY?")
	If oActive = vbYes Then
		oADoc = ThisApplication.ActiveDocument
		GoTo Cycle
	Else
		GoTo FileDialog
	End If
End If

FileDialog :
Try
	'Set value for oAsmName
	'This can be left manual, or as an InputBox, or you can create a FileOpen dialog box here.
	iLogicVb.Application.CreateFileDialog(oFileDlg)
	oFileDlg.Filter = "Autodesk Inventor Assembly Files (*.iam)|*.iam"
	oFileDlg.DialogTitle = "Select the assembly file"
	oFileDlg.InitialDirectory = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath
	oFileDlg.CancelError = True
	oFileDlg.ShowOpen()
	If Err.Number <> 0 Then
		MsgBox("File not chosen.", vbOKOnly, "Dialog Cancellation")
	ElseIf oFileDlg.FileName <> "" Then
		oAsmName = oFileDlg.FileName
		Try
			oADoc = ThisApplication.Documents.ItemByName(oAsmName)
		Catch
			MsgBox("Main assembly was not open." & vbCrLf & _
			"Attempting to open it now.",vbOKOnly,"ASSEMBLY NOT OPEN")
			oADoc = ThisApplication.Documents.Open(oAsmName)
		End Try
	End If
Catch oEx As Exception
	MsgBox("Could not find file name of the main assembly. Exiting.", vbOKOnly, "NO ASSEMBLY FILE NAME")
End Try
']

'[ Cycle to the next referenced document within the assembly and activate it
Cycle :
SharedVariable.Value("FullDocumentName") = oADoc.FullDocumentName
Dim oRefDocs As DocumentsEnumerator = oADoc.AllReferencedDocuments
Dim oIndex As Integer
Dim oLastOne As Integer
'Check SharedVariable for Index from last time
If SharedVariable.Exists("Index") Then
	oLastOne = SharedVariable.Value("Index")
	oIndex = oLastOne + 1
Else
	oIndex = 1
End If
Try
	Dim oRefDoc As Document = oRefDocs.Item(oIndex)
	If oRefDoc.Open = False Then
		ThisApplication.Documents.Open(oRefDoc.FullDocumentName, False)
	End If
	oRefDoc.Activate
	SharedVariable.Value("Index") = oIndex
	GoTo ShowForm
Catch oEx As Exception
	MsgBox("You've reached the end of the referenced documents. Exiting.", vbOKOnly, "NO NEXT PART")
	Return
End Try
']

'[  Show the form, hopefully using the activated referenced document
ShowForm :
Dim oFRV As FormReturnValue = iLogicForm.ShowGlobal("Check iProperties")
Select Case oFRV.Result
	Case FormResult.Cancel
		Return
	Case FormResult.Close
		Return
	Case FormResult.Done
		Return
	Case FormResult.None
		Return
	Case FormResult.OK
		Return
	Case FormResult.RuleButtonApplyAndClose
		If oFRV.RuleName = iLogicVb.RuleName Then
			'The button that closed the form was the one to run this rule
			GoTo Cycle
		End If
	Case FormResult.RuleButtonClose
		If oFRV.RuleName = iLogicVb.RuleName Then
			'The button that closed the form was the one to run this rule
			GoTo Cycle
		End If
End Select
']

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE" :thumbs_up:.

Also, when you have time, please review & vote for these 'Ideas' I'd like to get implemented.

  • Add more capabilities to the 'Customize' dialog box (exe. Add Tab & Add Panel) Click Here
  • Constrain & Dimension Images In Assembly Sketches & Drawing Sketches (TitleBlocks & SketchedSymbols) Click Here
  • Save Section View Status In DesignViewRepresentation (So It Can Be Used In The Drawing) Click Here
  • Add SolidBodies Folder In iLogic Rule Editor Model Tab Click Here
  • Convert All Views To Raster Before Autosave Stores To 'OldVersions' Folder Click Here
  • SetDesignViewRepresentation - Fix limitations for DrawingView of a Part Click Here
  • Create DocumentSubTypeEnum Click Here
  • Add kRevisionTag or kDrawingRevisionTag to ObjectTypeEnum Click Here

Inventor 2020 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum

Wesley Crihfield

EESignature

(Not an Autodesk Employee)