Any chance fill iproperties for multiple files from excel file

Any chance fill iproperties for multiple files from excel file

t.cankurtaran
Participant Participant
512 Views
4 Replies
Message 1 of 5

Any chance fill iproperties for multiple files from excel file

t.cankurtaran
Participant
Participant

Hi 

I'm using to update iproperties from excel for each part open and this codes.

 

PartNumber = InputBox("Please enter the number","Get data")
Dim Excel As String  = "E:\Library2\ARGE �ALI�MALARI\TOLGA CANKURTARAN\ARGE �ALI�MALARI �� L�STES�\PROJELER\DENEME PAR�ALAR\��YER� �ALI�MALARI\KARA KALEM KODLAR.xlsx"
Dim Sheet As String  = "Sayfa1"

If PartNumber = ThisDoc.FileName(False) 'without extensionThen



 GoExcel.FindRow( Excel , Sheet , "RESIM KODU", "=", PartNumber)
strDesc = GoExcel.CurrentRowValue("PARCA ADI")
strGRUP = GoExcel.CurrentRowValue("GRUP")
strMALZEME = GoExcel.CurrentRowValue("MALZEME")
strKAL = GoExcel.CurrentRowValue("KALINLIK")
strNOT = GoExcel.CurrentRowValue("ACIKLAMA")
strMODEL = GoExcel.CurrentRowValue("MODEL")

iProperties.Value("Project", "Part Number") = PartNumber
iProperties.Value("Project", "Description") = strDesc
iProperties.Value("Project", "Vendor") = strGRUP
iProperties.Value("Project", "AUTHORITY") = strMALZEME
iProperties.Value("Project", "Status") = strKAL
iProperties.Value("Summary", "Comments") = strNOT
iProperties.Value("Summary", "SUBJECT") = strMODEL

MessageBox.Show("G�ncelleme Tamam " &  PartNumber ) 
Else
MessageBox.Show("Par�a Numaras� yanl��" )
End If

 is there Any chance to update iproperties from excel for multiple files.

0 Likes
Accepted solutions (1)
513 Views
4 Replies
Replies (4)
Message 2 of 5

A.Acheson
Mentor
Mentor

This should be possible. Where are the files stored and how do you want to open them? Are they in a  folder, assembly or open as eperately as visible files? 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 5

t.cankurtaran
Participant
Participant

Would be perfect in folder files if its possible

0 Likes
Message 4 of 5

A.Acheson
Mentor
Mentor
Accepted solution

You can find the folder dialogue in the API Help file Sample Programs>User Interaction>User Interface>File Dialog

 

Here is a rule that should work for you. There is an option to process a whole folder or multiselect individual files.  The API property set method is more stable and is quicker than the ilogic iproperty snippets. 

 

Adjust the two paths as you need

Path1

oFileDlg.InitialDirectory = "C:\Users\Enter Name Here"

 

Path2

'Dim Excel As String = 

 

Sub Main
	TestFileDialog()
End Sub
	
Dim iPropFiles As New ArrayList
	
Public Sub TestFileDialog()
    ' Create a new FileDialog object.
    Dim oFileDlg As Inventor.FileDialog
    Call ThisApplication.CreateFileDialog(oFileDlg)

    ' Define the filter to select part and assembly files or any file.
    oFileDlg.Filter = "Inventor Files (*.iam;*.ipt)|*.iam;*.ipt|All Files (*.*)|*.*"

    ' Define the part and assembly files filter to be the default filter.
    oFileDlg.FilterIndex = 1

    ' Set the title for the dialog.
    oFileDlg.DialogTitle = "Open File Test"

    ' Set the initial directory that will be displayed in the dialog.
    oFileDlg.InitialDirectory = "C:\Users\Enter Name Here"
	oFileDlg.MultiSelectEnabled = True
'    oFileDlg.ShowSave
	 Check = InputRadioBox("Prompt", "Process Files", "Process a Folder", Check, Title := "Choose what to Process")
	  ' Show the open dialog.  The same procedure is also used for the Save dialog.
 	
	 Dim mylist As List(Of String)
	 If Check = True Then 
		 oFileDlg.ShowOpen
		If oFileDlg.FileName = Nothing Then
	    ElseIf oFileDlg.FileName <> "" Then
			'Process the multi selected files which form a  pipe like "C\123.ipt|C\124.ipt"
			mylist = oFileDlg.FileName.Split("|").ToList
			For Each item In mylist
				iPropFiles.add(item.ToString)
			Next
		 End If
	 ElseIf Check = False Then
		   MessageBox.Show("Choose any file to process the folders content", "iLogic")
		   oFileDlg.ShowOpen
			Dim sPath As String
			Try	
			sPath = IO.Path.GetDirectoryName(oFileDlg.FileName)
			Call CheckFolder(sPath)
			Catch
			End Try
	 End If

	d0 = InputListBox("Prompt", iPropFiles, d0, Title := "AssyFileList", ListName := "AssyFileList")

	For Each iPropFile As String In iPropFiles
		oDoc = ThisApplication.Documents.Open(iPropFile, False)
		Call ImportiProps(oDoc)
	Next
	'Clear the list
	iPropFiles.clear
End Sub

Sub CheckFolder(sPath As String)

Dim oFiles As String() = System.IO.Directory.GetFiles(sPath) 

For Each oFile As String In oFiles 
	'Logger.Info("FilesInFolder" & oFile)
	'Get Extension
	Ext = System.IO.Path.GetExtension(oFile)
	'Target only these extensions
	If Ext = ".ipt" Or Ext = ".iam" Then
		oFileName = System.IO.Path.GetFullPath(oFile)
		iPropFiles.add(oFileName)
	End If
Next
End Sub


Sub ImportiProps(oDoc As Document)
	
'Gain Access to properties using API Property Sets
Dim DesignProp As PropertySet = oDoc.PropertySets.Item("Design Tracking Properties")
Dim oPn As [Property] = DesignProp.Item("Part Number")
Dim oDesc As [Property] = DesignProp.Item("Description")
Dim oVen As [Property] = DesignProp.Item("Vendor")
Dim oAut As [Property] = DesignProp.Item("Authority")
Dim oStat As [Property] = DesignProp.Item("User Status")
Dim SumProp As PropertySet = oDoc.PropertySets.Item("Inventor Summary Information")
Dim oCom As [Property] = SumProp.Item("Comments")
Dim oSub As [Property] = SumProp.Item("Subject")

PartNumber = InputBox("Please enter the number", "Get data",oPn.Value)
If PartNumber = Nothing Then Exit Sub

'Dim Excel As String  = "E:\Library2\ARGE �ALI�MALARI\TOLGA CANKURTARAN\ARGE �ALI�MALARI �� L�STES�\PROJELER\DENEME PAR�ALAR\��YER� �ALI�MALARI\KARA KALEM KODLAR.xlsx"
Dim sSheet As String  = "Sayfa1"

If PartNumber = System.IO.Path.GetFileNameWithoutExtension(oDoc.FullFileName)'ThisDoc.FileName(False) 'without extensionThen

GoExcel.FindRow( Excel , sSheet , "RESIM KODU", "=", PartNumber)
strDesc = GoExcel.CurrentRowValue("PARCA ADI")
strGRUP = GoExcel.CurrentRowValue("GRUP")
strMALZEME = GoExcel.CurrentRowValue("MALZEME")
strKAL = GoExcel.CurrentRowValue("KALINLIK")
strNOT = GoExcel.CurrentRowValue("ACIKLAMA")
strMODEL = GoExcel.CurrentRowValue("MODEL")

oPn.Value = PartNumber 
oDesc.Value = strDesc 
oVen.Value = strGRUP
oAut.Value = strMALZEME 
oStat.Value = strKAL
oCom.Value = strNOT
oSub.Value = strMODEL

MessageBox.Show("G�ncelleme Tamam " &  PartNumber ) 
Else
MessageBox.Show("Par�a Numaras� yanl��" )
End If

oDoc.Save
oDoc.Close
End Sub

In addition if you run the Property set List rule you can access the property sets and there properties for correct translation.

oDrawDoc.PropertySets("Design Tracking Properties")("Engr Approved By").Value

Property set List rule

  Dim doc As Document
 doc = ThisApplication.ActiveDocument
  
  Dim ps As PropertySet
  For Each ps In doc.PropertySets
   Logger.Info( ps.Name + " / " + ps.InternalName)

    Dim p As [Property]
    For Each p In ps
      Logger.Info( "  " + p.Name + " /" + Str(p.PropId))
    Next
  Next
  

 

AAcheson_0-1651964536240.png

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 5 of 5

t.cankurtaran
Participant
Participant

this is awsome thank you very much