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: 

Inventor iLogic Save As Event Trigger

3 REPLIES 3
Reply
Message 1 of 4
danmachen1990
1122 Views, 3 Replies

Inventor iLogic Save As Event Trigger

Hello guys,

 

I'm trying to create a part number generator through iLogic and I intend to add the iLogic code to the Standard Part.ipt template.

 

What I want to be able to do is ask the user once they have created their design from the template, after they select save, whether they want to create a part number (which opens the part number generator form) or whether they want to save their rubbish design in the "Useless designs" folder.

 

This I have managed to do. (see attached image)

 

However, in the event that a "useless design" becomes an "interesting design", I want the user to be asked the question on the 'save as' trigger event. But this isnt available. ... Or.. the user wants to save Useless design_1 to Useless design_2.

 

How can I get around it?

 

 

+ First Save - Does the user want to create a part Number?

 

+ Yes -- > Open User Form                          +No ---> Open Save As Dialog Box

 

+ Second Save - Does the User want to create a part number now?

 

+ Yes ---> Open user form                            + No --> Document.Save

 

+ User Selects Save As ..

 

----> User enters filename they require, presses save.

----> This triggers question box (Do you want to create a part number?)

 

Currently as the user presses No, it closes the part and doesnt save the file.

 

Here is the code I have so far:

 

question = MessageBox.Show("Would you like to Generate a Unique Part Number?"&vbLf _
&"Current Part Number: "&iProperties.Value("Project", "Part Number"), "iLogic Message Box", MessageBoxButtons.YesNo )

 

If question = vbYes Then
'open the user form
iLogicForm.Show("Part Number Generator")

 

Else If question = vbNo Then

'Do nothing

''Save the document

ThisDoc.Document.Save
MessageBox.Show("Saved.")

 

End If
'

 

 

 

3 REPLIES 3
Message 2 of 4

I thought I would post on here the code for the part number generator also..

 

The part number generator is supposed to write certain information to Excel such as the values selected from certain radio button groups and write these to columns in Excel.

 

Then, allow excel to calculate a sequential number and then use this in the inventor filename.

 

 

 

myXLS_File = "C:\Users\dmachen\Desktop\iLogic.xlsx"

'Set Document Variables

x = Parameter("STRUCTURE")
y = Parameter("SECTION")
PartNumber = iProperties.Value("Project","Part Number")
Revisionnumber = iProperties.Value("Project", "Revision Number")
Title = iProperties.Value("Summary", "Title")
Designer = iProperties.Value("Summary", "Author")

 

'define Excel Application object
excelApp = CreateObject("Excel.Application")
'set Excel to run visibly, change to false if you want to run it invisibly
ThisDoc.Launch(myXLS_File)
excelApp.Visible = False
'suppress prompts (such as the compatibility checker)
excelApp.DisplayAlerts = True


'check for existing file
If Dir(myXLS_File) <> "" Then
'workbook exists, open it
excelWorkbook = excelApp.Workbooks.Open(myXLS_File)
'set the first sheet active
excelSheet = excelWorkbook.Worksheets(1).activate
Else
'Open Message Box saying file was not selected or could not open
i = MessageBox.Show("The file could not open correctly", "iLogic Error Box", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)
End If
   
'Insert data into Excel.
With excelApp
'index row 2 through 10000
For rowPN = 2 To 10000
'find first empty cell in column A
 If (GoExcel.CellValue("A" & rowPN) = "") Then
'create a variable for the cell value that is one row less than the empty cell row
    CurRow =  rowPN
 .Range("A"& CurRow).Value = x
 .Range("B"& CurRow).Value = y
 .Range("C"& CurRow).Value = RevisionNumber
 FilenameCell = GoExcel.CellValue(myXLS_File,"Sheet1", "A" & CurRow)
Exit For
End If
Next
            '.Range("A1").Value = "Vantage Power Part Number Database"

End With  

'
'add a delay to allow excel to update
'
'

'SAVE AS DIALOG BOX
'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 as the value entered in Excel Spreadsheet
oFileDlg.FileName = FilenameCell


'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 imput
If Err.Number <> 0 Then
MessageBox.Show("No File Saved.", "iLogic: Dialog Canceled")
ElseIf oFileDlg.FileName <> "" Then
'save the file
oDoc.SaveAs(FilenameCell, False) 'True = Save As Copy & False = Save As
End If


'set all of the columns to autofit
excelApp.Columns.AutoFit  
'save the file
excelWorkbook.SaveAs (myXLS_File)
'close the workbook and the Excel Application
excelWorkbook.Close
excelApp.Quit
excelApp = Nothing

 

'------ end of iLogic -------------------------
'

Message 3 of 4

Did you get a solution for this ?

Regards
Santosh
Message 4 of 4
DRLTKSE
in reply to: santoshr0114

If you are saving the document for the first time after creating the part from a template you can use something like I've shown here. Becuase the part has never been saved the file path won't have a value and will return "". 

 

SyntaxEditor Code Snippet

Dim oPath As String
Dim oDoc As Document

oDoc=ThisApplication.Activedocument

'Get Full File Path
oPath=oDoc.FullFileName

If oPath= "" Then 
Do your Part number code
Else
Do Something Else
End If

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

Post to forums  

Autodesk Design & Make Report