Open document while saving

Open document while saving

Anonymous
Not applicable
501 Views
3 Replies
Message 1 of 4

Open document while saving

Anonymous
Not applicable

Hello,

 

I have an iLogic script that checks some properties on save, and if those ar enot filled in it opens up a form and asks the user to fill in the data.

 

Its all working fine, but if I run it on an assembly, it shows for the assembly and then again for each subpart that is beeing saved.

 

At this point I do not know for what part it is beeing displayed. therfor I would like to open up that particular IPT in the background (behind the form) so the user knows what he is doing, once done the part should be closed again.

 

but it is not working.. I have no idea on how to open that particular document on its own.

 

 

Basically all I want is that if the user sees the form, he should also see the part open in background so he knows what part the form is referenced to.

can this be done?

 

thanks!

 

 

 

Sub Main()
Dim IPJ as String
Dim IPJ_Name As String
Dim IPJ_Path As String
Dim FNamePos As Long
'set a reference to the FileLocations object.
IPJ = ThisApplication.FileLocations.FileLocationsFile
   

If IPJ = "C:\VLT_Wrk\Konstruktion2.ipj" Or IPJ = "C:\Users\cad-13\Desktop\TEST\Konstruktion2.ipj" Then

 Dim odoc As Document = ThisDoc.Document
Dim eDocumentType As DocumentTypeEnum = oDoc.DocumentType

     Select Case eDocumentType
            Case DocumentTypeEnum.kAssemblyDocumentObject '''IAM
                 Vaultpropwriteback()
				 Propcheckdes(odoc)
                
            Case DocumentTypeEnum.kPartDocumentObject '''IPT
				
                Propcheckdes(odoc)
				
    
      End Select
	  
	  End If 
	  
End Sub
    
    ''''--------------------------------------''''


Sub Propcheckdes(oDoc As Inventor.Document)
Dim Desc as String
Dim opened As Boolean = False
Desc = iProperties.Value(“Project”, “Description”)
Dim odoc2 As Document



If String.IsNullOrWhiteSpace(Desc) = True Then
	odoc2 = ThisApplication.Documents.Open(oDoc.FullFileName, True)
	opened = True
End If
	

Do Until String.IsNullOrWhiteSpace(Desc) = False

iLogicForm.ShowGlobal("Pflichtfelder",FormMode.Modal)

Desc = iProperties.Value(“Project”, “Description”)

Loop

If opened Then
	odoc2.Close	
End If
	


End Sub
0 Likes
Accepted solutions (1)
502 Views
3 Replies
Replies (3)
Message 2 of 4

HermJan.Otterman
Advisor
Advisor

Hello Sharky,

 

Look at this example from the API help from Inventor:

 

Traverse an Assembly

 

 

 

Public Sub AssemblyCount()
    ' Set reference to active document.
    ' This assumes the active document is an assembly
    Dim oDoc As Inventor.AssemblyDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    ' Get assembly component definition
    Dim oCompDef As Inventor.ComponentDefinition
    Set oCompDef = oDoc.ComponentDefinition

    Dim sMsg As String
    Dim iLeafNodes As Long
    Dim iSubAssemblies As Long
    
    ' Get all occurrences from component definition for Assembly document
    Dim oCompOcc As ComponentOccurrence
    For Each oCompOcc In oCompDef.Occurrences
        ' Check if it's child occurrence (leaf node)
        If oCompOcc.SubOccurrences.Count = 0 Then
            Debug.Print oCompOcc.Name
            iLeafNodes = iLeafNodes + 1
        Else
            Debug.Print oCompOcc.Name
            iSubAssemblies = iSubAssemblies + 1
            Call processAllSubOcc(oCompOcc, _
                                sMsg, _
                                iLeafNodes, _
                                iSubAssemblies) ' subassembly
        End If
    Next
    
    Debug.Print "No of leaf nodes    : " + CStr(iLeafNodes)
    Debug.Print "No of sub assemblies: " + CStr(iSubAssemblies)
End Sub

' This function is called for processing sub assembly.  It is called recursively
' to iterate through the entire assembly tree.
Private Sub processAllSubOcc(ByVal oCompOcc As ComponentOccurrence, _
                             ByRef sMsg As String, _
                             ByRef iLeafNodes As Long, _
                             ByRef iSubAssemblies As Long)
    
    Dim oSubCompOcc As ComponentOccurrence
    For Each oSubCompOcc In oCompOcc.SubOccurrences
        ' Check if it's child occurrence (leaf node)
        If oSubCompOcc.SubOccurrences.Count = 0 Then
            Debug.Print oSubCompOcc.Name
            iLeafNodes = iLeafNodes + 1
        Else
            sMsg = sMsg + oSubCompOcc.Name + vbCr
            iSubAssemblies = iSubAssemblies + 1

            Call processAllSubOcc(oSubCompOcc, _
                                  sMsg, _
                                  iLeafNodes, _
                                  iSubAssemblies)
        End If
    Next
End Sub

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes
Message 3 of 4

bradeneuropeArthur
Mentor
Mentor
Put the filename in your userform heading. Now uou can see for what part or assembly the dialog is shown. Otherwise use document.acivate

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 4 of 4

Anonymous
Not applicable
Accepted solution

solved it this way:

 

 

 

 

SyntaxEditor Code Snippet

Sub Propcheckdes(oDoc As Inventor.Document, filetype As Integer)
Dim counter As Integer = 0
Dim Desc as String
Dim opened As Boolean = False
Dim alreadyopen As Boolean = False
Desc = iProperties.Value(“Project”, “Description”)
Dim odoc2 As Inventor.PartDocument
Dim odoc3 As Inventor.AssemblyDocument


''see if file is already open

	For Each d As Document In ThisApplication.Documents.VisibleDocuments
		If d.FullFileName = oDoc.FullFileName Then
			alreadyopen = True
		End If
	Next

	''restore active window
	Dim odocactive As Inventor.Document
	odocactive = ThisApplication.ActiveDocument

	If String.IsNullOrWhiteSpace(Desc) = True Then
		If filetype = 1 Then
			odoc3 = ThisApplication.Documents.Open(oDoc.FullFileName, True)
		Else
			odoc2 = ThisApplication.Documents.Open(oDoc.FullFileName, True)
		End If
		opened = True
	End If

	Do Until String.IsNullOrWhiteSpace(Desc) = False Or counter > 0
		iLogicForm.ShowGlobal("Pflichtfelder",FormMode.Modal)
		Desc = iProperties.Value(“Project”, “Description”)
		counter = counter + 1
	Loop

	If opened And Not alreadyopen Then
		If filetype = 1 Then
			odoc3.Close(True)
		Else
			odoc2.Close(True)
		End If	
	End If

	odocactive.Activate
	
End Sub
0 Likes