iLogic to Protected Excel

iLogic to Protected Excel

Anonymous
Not applicable
349 Views
1 Reply
Message 1 of 2

iLogic to Protected Excel

Anonymous
Not applicable

Hi Guys,

 

I am using an iLogic code which writes values of the iProperties into an excel sheet in order to keep part numbers in Inventor linked with those in our part number database.

 

I am currently using the GoExcel syntax in order to do this.

 

However, I want to be able to protect and unprotect the sheet via the code so that in can only be changed through the ilogic and users cant interfere with the data.

 

Is there a way to do this using the GoExcel.Open syntax for example or the GoExcel.Application syntax.

 

 

Section = Left(Parameter("SECTION"),1) 'Type (mechanical, Fluid)
Struct = Left(Parameter("STRUCTURE"),1) 'Assembly or Component

'define the file to create/open
Worksheet = "Z:\CAD\DESIGN ENVIRONMENT\iLogic\PN.xlsx"
Sheetno = ("Sheet1")

'check for existing file 
If Dir(Worksheet) <> "" Then
'workbook exists, open it
GoExcel.Open(Worksheet, Sheetno)


'Set the values to write into excel part number database

' Define Range
RowStart = 2
RowEnd = 10000

'Find the first empty cell
For count = RowStart To RowEnd
	' If it's blank count it
	If String.IsNullOrEmpty(GoExcel.CellValue("C" & count)) Then 
	' Row Number is equal to the current row
		rowN = count
		'Exit For loop
		Exit For
	End If
Next

GoExcel.CellValue("A1") = Section & Struct  
iProperties.Value("Project", "Revision Number") = "A"
OldPartNumber = iProperties.Value("Project", "Part Number")
	   
'Show user the next row number which is blank
MessageBox.Show("Inserting Data on Row " & rowN, "Updating Database...")
'Store Old part Number
NewPartNumber = GoExcel.CellValue("B1")
'Update iProperties
iProperties.Value("Project", "Part Number") = NewPartNumber
Filename = GoExcel.CellValue("B1") & iProperties.Value("Project", "Revision Number")& "_" & iProperties.Value("Project", "Description")
iProperties.Value("Summary", "Title") = Filename
GoExcel.CellValue("C" & RowN) = GoExcel.CellValue("B1")
GoExcel.CellValue("D" & RowN) = iProperties.Value("Project", "Revision Number")
GoExcel.CellValue("E" & RowN) = iProperties.Value("Project", "Description")
GoExcel.CellValue("F" & RowN) = Filename
iProperties.Value("Project", "Designer") = iProperties.Value("Summary", "Author")

MessageBox.Show("Your Unique Part Number is " & Filename, "Updating Database...")
GoExcel.Save


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


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


'set the directory to open the dialog at
oFileDlg2.InitialDirectory = ThisDoc.WorkspacePath()
'set the file name string to use in the input box
oFileDlg2.FileName = Filename


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


'Catch an empty String in the imput
If Err.Number <> 0 Then
MessageBox.Show("No File Saved.", "iLogic: Dialog Canceled")

'Enter Code which removes last entry from Spreadsheet
'GoExcel.Open(Worksheet, Sheetno)
For count = RowStart To RowEnd
	' If it's blank count it
	If String.IsNullOrEmpty(GoExcel.CellValue("C" & count)) Then 
	' Last entry was on bottom row minus 1
		rowN = count -1
		
		'Exit For loop
		Exit For
	End If
Next

iProperties.Value("Project", "Part Number") = OldPartNumber
iProperties.Value("Summary", "Title") = iProperties.Value("Project", "Description")
MessageBox.Show("No File Saved." &vbLf & "Removing Last Entry From Database...")
GoExcel.CellValue("C" & RowN) = ""
GoExcel.CellValue("D" & RowN) = ""
GoExcel.CellValue("E" & RowN) = ""
GoExcel.CellValue("F" & RowN) = ""


GoExcel.Save
ElseIf oFileDlg2.FileName <> "" Then
MyFile = oFileDlg2.FileName
'save the file 
oDoc.SaveAs(MyFile, False) 'True = Save As Copy & False = Save As
End If
           
Else 'Else statement for if excel dir(worksheet) = ""
MessageBox.Show("Excel Failed to Open." &vbLf & "Ensure Engineering Root is mapped to Z:/", "Error Handler")
End If


iLogicVb.UpdateWhenDone = True

 

Thanks

 

Dan

0 Likes
350 Views
1 Reply
Reply (1)
Message 2 of 2

adam.nagy
Autodesk Support
Autodesk Support

Hi Dan,

 

In case of iLogic the only event where you can intervene is on iProperty change, so if that's not how the user is trying to modify the drawing that you cannot prevent it. 

You also cannot abort a save operation.

 

From an addin you would have more options: e.g. listening to OnDocumentChange event.

 

Cheers,



Adam Nagy
Autodesk Platform Services
0 Likes