Batch Updating iProperties from Excel Table

Batch Updating iProperties from Excel Table

chris.barrie
Enthusiast Enthusiast
246 Views
1 Reply
Message 1 of 2

Batch Updating iProperties from Excel Table

chris.barrie
Enthusiast
Enthusiast

Hi Everyone.

 

Not sure if this is the right forum or not, if not apologies, please let me know and I will move acordingly.

I am trying to update a number of .ipt files with a new part description based on a table of values in excel.

I have some VB code that I am using but its falling down on certain parts and Im not sure why.

 

Heres the situation.

I have a folder full of part files, all needing a desccription adding. There are around 1400 part files.

I have the list of these parts and their file locations populating an excel table. Just 2 columns, reading like this.

chrisbarrie_2-1669837742989.png

 

 

etc

 

 

Im then running this code, which I shamelessly stole.

 

Sub WriteData()
Dim appServer As Inventor.ApprenticeServerComponent
Set appServer = New ApprenticeServerComponent

Dim oSheet As Worksheet
Set oSheet = ThisWorkbook.ActiveSheet

For i = 2 To 15 '  DO NOT FORGET TO UPDATE!

Dim file As String
Dim Update As String


file = oSheet.Range("A" & i).Value ' columns A+B+C
Update = oSheet.Range("B" & i).Value


Dim invDoc As Inventor.ApprenticeServerDocument
Set invDoc = appServer.Open(file)

invDoc.PropertySets("{32853F0F-3444-11D1-9E93-0060B03C1CA6}")("Description").Value = Update


invDoc.PropertySets.FlushToFile
invDoc.Close

Next

End Sub

 

If I cycle the code through it works for all the parts up to row 10, whereby  I get the following error

chrisbarrie_3-1669837920874.png

 

There isnt anything special about the part in row 10, in terms of read-only access etc?

 

The only thing I could think is that some of the parts may already have descriptions in them? Im guessing a bit though.

 

Any thoughts are most welcome. Or If anyone has a better solution for what Im trying to do that would be great.

 

Many thanks

 

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

A.Acheson
Mentor
Mentor

Hi @chris.barrie  I am not sure if you got this solved but it was likely an error within the excel sheet when reading the cells. See this link.

 

For anyone else looking to implement this code. Here are the steps. 

This code needs to run in Excel VBA and not Inventor VBA. The code is using the apprentice server to perform the iProperties changes. For this reason it cannot use Inventor VBA. The benefits are that you can continue to use inventor while the code is running. Here is a link to an article showing more information. You will need to add reference to the Inventor Object Library within References.

AAcheson_0-1672080689139.png

 

'https://modthemachine.typepad.com/my_weblog/2010/03/iproperties-without-inventor-apprentice.html
'Add reference to Autodesk Inventor Object Library. In VBA editor Tools, Add Reference ....

Sub WriteData()
    Dim appServer As Inventor.ApprenticeServerComponent
    Set appServer = New ApprenticeServerComponent
    
    Dim oSheet As Worksheet
    Set oSheet = ThisWorkbook.ActiveSheet
    
    For i = 2 To 15
    
        Dim file As String
        Dim Update As String
        
        file = oSheet.Range("A" & i).Value
        Update = oSheet.Range("B" & i).Value
        
        If file = "" Then GoTo NextIteration
        
        Dim invDoc As Inventor.ApprenticeServerDocument
        Set invDoc = appServer.Open(file)
      
        invDoc.PropertySets("{32853F0F-3444-11D1-9E93-0060B03C1CA6}")("Description").Value = Update
        
        invDoc.PropertySets.FlushToFile
        invDoc.Close
        
NextIteration:
    Next
If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes