Sequential file name scheme excel

Sequential file name scheme excel

morgan.isaksson
Explorer Explorer
612 Views
5 Replies
Message 1 of 6

Sequential file name scheme excel

morgan.isaksson
Explorer
Explorer

Hello,

I'd like to create a part number generator using iLogic and excel in inventor.  

 

File name(part number) is build by Project Number (4 digits)-Part type(1 digit), Sequential number(3 digits)

 

1234-1001

 

1. User should be asked for project Number and Part type.

2. Ilogic code should search for the first available number and populate a filename for the part.

 

No Vault

Any help is appreciated!

 

Morgan Isaksson

 

 

 

 



0 Likes
613 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor

Hi @morgan.isaksson.  I have the code for the first couple steps, but not the Excel part yet.  You will need to be much more specific about the Excel file, including its file location, its name, the name of the sheet (tab) you will be using in it, what data will be where within that sheet, and such.  Be as specific and detailed as possible.

Sub Main
	ReEnterProjectNumber :
	Dim sProjectNumber As String = InputBox("Enter Project Number (Must Be 4 Digits).", "Project Number", "")
	If sProjectNumber = "" Then Exit Sub
	If sProjectNumber.Length <> 4 Then
		MsgBox("The Project Number specified is not 4 digits.", vbCritical, "Project Number Wrong")
		GoTo ReEnterProjectNumber
	End If
	ReEnterPartType :
	Dim sPartType As String = InputBox("Enter Part Type (Must Be 1 Digit).", "Part Type", "")
	If sPartType = "" Then Exit Sub
	If sPartType.Length <> 1 Then
		MsgBox("The Part Type specified is not 1 digit.", vbCritical, "Part Type Wrong")
		GoTo ReEnterPartType
	End If
	Dim sFileName As String = sProjectNumber & "-" & sPartType
	MsgBox("sFileName = " & sFileName, vbInformation, "File Name (so far...)")
	'now get last 3 digits sequential value from Excel somehow
	'please specify how you want that Excel file laid out (be very specific & detailed)
	
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 6

morgan.isaksson
Explorer
Explorer

Thank you WCrihfield,

 

Wow. My plan is to have one excelfile; VPTpartnumber.xls stored on our file server ; r:\data. I don't think we need to write the final partnumber to a cell in the excel sheet. My thoughts was to create a sheet for each project with the corresponding name. Ex 1234.

 

Thank You

 

 

0 Likes
Message 4 of 6

mrB_Young
Advocate
Advocate

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
0 Likes
Message 5 of 6

morgan.isaksson
Explorer
Explorer

Thank you for your effort mrB_Young,

 

I will look in to this and see if I can use some of the code and develop it to meet the demands I have.

 

Thank You

 

0 Likes
Message 6 of 6

Sil_Inventor
Participant
Participant
Hello,
I have a few questions;
1. What is the file location it's looking for? I can't discern it from the text.
2. Can you show an example of an Excel file?

Thank you,
Sil
0 Likes