Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ilogic rule to save idw, iam & ipt

1 REPLY 1
Reply
Message 1 of 2
DJFore
1793 Views, 1 Reply

ilogic rule to save idw, iam & ipt

'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. 

 

1 REPLY 1
Message 2 of 2
Vladimir.Ananyev
in reply to: DJFore

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report