A few years ago I made sequential number generator with excel, it worked. Perhaps not very elegant ...
Keep in mind that this was purely sequential and wasn't designed to split up into projects.
But you can pick out of this what you will.
As you will see, this needs an excel file called "Drawing_register.xlsx"
And a sheet in that excel file called "number_generator"
I don't remember exactly, but I think you need to enter the first part manually, after that it's all go.
The purpose of cell B2 is simply a counter so that the code knows which cell was last used and read that cell, and then write into the next cell.
And the cell number of the first part number cell manually before you begin.
There's probably a more elegant way of doing this, but I'm not an ilogic or programming expert.
I always like to perform check in my iLogic rules, hence the checks at the start.
Especially good thing to do here to check for an active sketch or else this will fail.
I don't think this is the finished code - I seem to have misplaced the final code.
I the final code doing a few other checks as well. But hopefully this will help you on your way.
InventorVb.DocumentUpdate()
' Set document this rule is running from
Dim Doc = ThisDoc.Document
' Ensure the document is the active document
ThisDoc.Document.Activate
' Check for active sketch and exit if active. This will detect active sketches in Drawing, Part and Assembly documents.
If TypeOf ThisApplication.ActiveEditObject Is Sketch Then
MessageBox.Show("This document has an active sketch." & vbLf & _
"Exit the sketch and try again.", "iLogic Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
GoTo Terminate
End If
' Establish what document type we dealing with and set appropriate response
DocType = Split(Split(([Enum].GetName(GetType(Inventor.DocumentTypeEnum), Doc.DocumentType)), "k")(1), "DocumentObject")(0)
MessageBox.Show("This is a " &DocType, "iLogic Error")
Select DocType
Case "Assembly", "Part"
GoTo PartNumberAssign
Case "Drawing"
GoTo DrawingSaveProcedure
Case Else
MessageBox.Show("This document doesn't appear to be in conformance." & vbLf & _
"Assembly, Part Or Drawing documents only." & vbLf & _
"" & vbLf & _
"Document Type is = " &DocType, "iLogic Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
GoTo Terminate
End Select
' Has document been saved before?
' If yes, then check for conformity, compare file name and Part Number. Check against Drawing Register.
' If no, then proceed to save file and enter new document in Drawing Register.
'Add Part number check here first.
' 1 If Part Number exists does it conform? If not, then error.
' 2 Is Part Number the same as file name? If not, then error. Check both 1 & 2 beofre exiting.
' 3 If 1 & 2 conform then check against Drawing Register. If not found take next availible number.
' 4 And all that vs Drawing Register
'
'If all that checks out then we'll assume everything is hunky dory and there is nothing to do here. Exit.
'Otherwise we'll treat the document running this rule as yet to be saved.
PartNumberAssign :
'Has the document been saved before?
Dim DocFilNamChk = ThisDoc.FileName(True).ToString
If DocFilNamChk = Nothing Then 'If this returns nothing then we'll assume it's safe to say that this hasn't been saved before.
'And go ahead get new part number from drawing register and save the file for the first time.
GoExcel.Open("Drawing_register.xlsx", "number_generator")
PrevCelNum = GoExcel.CellValue("B2")
NextCelNum = PrevCelNum + 1
PrevParNum = GoExcel.CellValue("A"&PrevCelNum)
NextParNum = PrevParNum + 1
MessageBox.Show("Previous Cell = " &PrevCelNum & vbCrLf & "Next Cell = " &NextCelNum & vbCrLf & "Previous Part Number = " &PrevParNum & vbCrLf & "Next Part Number = " &NextParNum , "iLogic Information")
GoExcel.CellValue("A"&NextCelNum) = NextParNum
GoExcel.CellValue ("B2") = NextCelNum
iProperties.Value("Project", "Part Number") = GoExcel.CellValue("A" & NextCelNum)
GoExcel.CellValue("B" & NextCelNum) = iProperties.Value("Summary", "Title")
GoExcel.Save
GoExcel.Close
Else
MessageBox.Show("This file needs checking against the register." & vbLf & _
"iLogic to accomplish this is coming soon", "iLogic Error", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
GoTo Terminate
DrawingSaveProcedure :
MessageBox.Show("Now we're getting even further!")
GoTo Terminate
Terminate :
'create a file dialog box
Dim FileDlg As Inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(FileDlg)
'check file type and set dialog filter
If DocType = "Part" Then
FileDlg.Filter = "Autodesk Inventor Part Files (*.ipt)|*.ipt"
Else If DocType = "Assembly" Then
FileDlg.Filter = "Autodesk Inventor Assembly Files (*.iam)|*.iam"
Else If DocType = "Drawing" Then
FileDlg.Filter = "Autodesk Inventor Drawing Files (*.idw)|*.idw"
End If
''set the directory to open the dialog at
FileDlg.InitialDirectory = ThisDoc.WorkspacePath()
''set the file name string to use in the input box
FileDlg.FileName = iProperties.Value("Project", "Part Number")
''work with an error created by the user backing out of the save
FileDlg.CancelError = True
On Error Resume Next
''specify the file dialog as a save dialog (rather than a open dialog)
FileDlg.ShowSave()
''catch an empty string in the imput
If Err.Number <> 0 Then
MessageBox.Show("No File Saved.", "iLogic: Dialog Canceled")
ElseIf FileDlg.FileName <> "" Then
MyFile = FileDlg.FileName
''save the file
Doc.SaveAs(MyFile, False) 'True = Save As Copy & False = Save As
End If
Inventor user since 2009
Vault user since 2010