ilogic rule to save idw, iam & ipt

ilogic rule to save idw, iam & ipt

DJFore
Advocate Advocate
2,059 Views
1 Reply
Message 1 of 2

ilogic rule to save idw, iam & ipt

DJFore
Advocate
Advocate
'define the active document
oDoc = ThisDoc.Document
'create a file dialog box
Dim oFileDlg As inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)

'check file type and set dialog filter
If oDoc.DocumentType = kPartDocumentObject Then
oFileDlg.Filter = "Autodesk Inventor Part Files (*.ipt)|*.ipt"
Else If oDoc.DocumentType = kAssemblyDocumentObject Then
oFileDlg.Filter = "Autodesk Inventor Assembly Files (*.iam)|*.iam"
Else If oDoc.DocumentType = kDrawingDocumentObject Then
oFileDlg.Filter = "Autodesk Inventor Drawing Files (*.idw)|*.idw"
End If

'set the directory to open the dialog at
oFileDlg.InitialDirectory = ThisDoc.WorkspacePath()
'set the file name string to use in the input box
oFileDlg.FileName = iProperties.Value("Project", "Part Number")

'work with an error created by the user backing out of the save
oFileDlg.CancelError = True
On Error Resume Next
'specify the file dialog as a save dialog (rather than a open dialog)
oFileDlg.ShowSave()

'catch an empty string in the input
If Err.Number <> 0 Then
MessageBox.Show("No File Saved.", "iLogic: Dialog Canceled")
ElseIf oFileDlg.FileName <> "" Then
MyFile = oFileDlg.FileName
'save the file
oDoc.SaveAs(MyFile, False) 'True = Save As Copy & False = Save As
End If

I have a drawing (idw) that I built a ilogic form to drive my assembly (iam). I would like to add a to my ilogic form a option to save. What I really want it to do is to preform a save as of the drawing and then subsequentially save the assembly and one of the parts in the assembly as the same name.

I found peices of code online (and modified to fit) that allows me to get a dialog box and save the drawing but i cannot find a way to drive the save down to the iam and ipt files. I have attached that code to show where I am starting from.

My currect template assembly (iam) file name is 14221214-01 and my part (ipt) is 14221214-02. 

 

0 Likes
2,060 Views
1 Reply
Reply (1)
Message 2 of 2

Vladimir.Ananyev
Alumni
Alumni

When your rule is executed in the context of the drawing document you are able to get access to all documents that are referenced by your drawing directly or indirectly.  Here is the VBA sample that uses ReferencedDocuments and AllReferencedDocuments collections to illustrate the workflow:

Sub Drawing_ReferencedDocs()
    'reference to the active drawing document
    Dim ThisDoc As Inventor.Document
    Set ThisDoc = ThisApplication.ActiveDocument
    
    Dim oDoc As Inventor.Document
    
    Debug.Print "Drawing document: " & ThisDoc.FullFileName
    
    'print all the documents directly referenced by this drawing.
    Debug.Print "Referenced documents: (full document names)"
    For Each oDoc In ThisDoc.ReferencedDocuments
        'Debug.Print oDoc.FullFileName
        Debug.Print oDoc.FullDocumentName
    Next
    Debug.Print
    'print all the document references of this drawing
    'along with all of the recursively nested references.
    Debug.Print "All Referenced documents:"
    For Each oDoc In ThisDoc.AllReferencedDocuments
        Debug.Print oDoc.FullFileName
    Next
    Debug.Print " ----------------- "
    Beep
End Sub

 

You may iterate these collections and save any documents you need. This code should work for assembly document as well. 

BTW you may access an assembly or a part document referenced by the specific DrawingView object:

Dim oView As DrawingView
Set oView = ThisDoc.Sheets.Item(1).DrawingViews.Item(1)

Dim oDiscr As DocumentDescriptor
Set oDiscr = oView.ReferencedDocumentDescriptor

Debug.Print "Displayname:      " & oDiscr.DisplayName
Debug.Print "FullDocumentName: " & oDiscr.FullDocumentName

Set oDoc = oDiscr.ReferencedDocument
Debug.Print "FullFileName:     " & oDoc.FullFileName

Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

0 Likes