Changing iProperties with iLogic

Changing iProperties with iLogic

Daan_M
Collaborator Collaborator
459 Views
7 Replies
Message 1 of 8

Changing iProperties with iLogic

Daan_M
Collaborator
Collaborator

Hi,

 

I'm making a code that allows me to fill existing and create new custom iProperties in batches of partfiles, this infomation comes from an Excel file. Unfortunatly the code does everything correctly except changing the actual properties

 

The code gives the correct iProperty types, names and values (line 52);

Daan_M_0-1699025269053.png

 

But the value of the properties do not change when it runs line 54, no errors occur either.

 

My code (not all of it is important, i think the problem lies in line 54);

 

 

Imports System.Windows.Forms
Sub main
	
Dim rDocs As Documents = ThisApplication.Documents

Dim oFD As Inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFD)
oFD.InitialDirectory = oOrigRefName
oFD.Filter = "Excel file (*.xlsx)|*.xlsx|"
oFD.CancelError = True
On Error Resume Next
oFD.ShowOpen()
If Err.Number <> 0 Then
Return

ElseIf oFD.FileName <> "" Then
selectedfile = oFD.FileName
End If

Dim oExcel As String = selectedfile

Dim i As Integer = 3

Dim PartFileLoc As String = GoExcel.CellValue(oExcel, "Blad1", "A" & i)

If PartFileLoc = "" Then
	MsgBox("Geen PartFileLoc gevonden in cell: A" & i)
Exit Sub
End If

Do While PartFileLoc <> ""

Dim oPartDoc As PartDocument = rDocs.Open(PartFileLoc, True)
oPartDoc.Activate
Dim n As Integer
Dim nRow As Integer = 2

For n = 1 To 26
	oLetter = Mid("ABCDEFGHIJKLMNOPQRSTUVWXYZ", n, 1)
	oCellAddress = oLetter & nRow
	oCellValue = GoExcel.CellValue(oCellAddress)
	GoExcel.TitleRow = nRow
	oColumnName = GoExcel.CellValue(oLetter & nRow)

If oColumnName <> ""

Dim oProperty As String = oColumnName
Dim oPropertyType As String = GoExcel.CellValue(oLetter & 1)
Dim oSetValue As String = GoExcel.CellValue(oExcel, "Blad1", oLetter & i)
	
	MsgBox(oPartDoc.DisplayName)
	MsgBox(oPropertyType & " & " & oProperty & " = " & oSetValue)
	
iProperties.Value(oPropertyType, oProperty) = oSetValue

End If
Next

i = i + 1
PartFileLoc = GoExcel.CellValue("A" & i)
oPartDoc.Save()
'oPartDoc.Close
Loop
End Sub

 

 

What am i doing wrong?

 

have a good weekend in advance

 

0 Likes
460 Views
7 Replies
Replies (7)
Message 2 of 8

Curtis_Waguespack
Consultant
Consultant

Hi @Daan_M,

 

I think the rule as written is running on all the documents that are referenced by other open documents in Inventor. I'm not sure if that's what you intend or not, it might be.

 

In any case, I think you just want to change line 54 ( or at least line 54 it is in your post) from :

 

 

iProperties.Value(oPropertyType, oProperty) = oSetValue

 

 

 

iProperties.Value(oPartDoc.fullfilename, oPropertyType, oProperty) = oSetValue

 

 

As you had it, it was changing the property in the document from which the rule was run.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

Message 3 of 8

Daan_M
Collaborator
Collaborator

Hi @Curtis_Waguespack,

 

That's correct, i only want to run the property change on oPartDoc.

 

Unfortunatly i also tested the line without succes

iProperties.Value(oPartDoc.fullfilename, oPropertyType, oProperty) = oSetValue

 

It opens the document, gives correct properties and value, but it remains empty;

 

Daan_M_0-1699028089073.png

 

Message 4 of 8

WCrihfield
Mentor
Mentor

I don't think FullFileName works for the first (of 3) inputs in the iProperties.Value() snippet.  It will usually only accept the Document.DisplayName there.  And even that is finicky, because sometimes that includes the file extension, and sometimes it does not.  And when using the iProperties.Value snippet, it can only reach stuff that is within the ActiveDocument's AllReferencedDocuments collection.

You might be able to use the new:

SOP = StandardObjectFactory.Create(oDoc)
SOP.iProperties.Value()

tools also, to make sure that the iProperties.Value snippet is working with the Document you input into that first line.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 8

Curtis_Waguespack
Consultant
Consultant

Hi @Daan_M 

 

Well, that's what I get for replying without testing my answer... @WCrihfield is correct, we need to use display name here.

 

I don't have your Excel data, but this stripped-down version of your rule works.

 

Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
For Each rDoc As Document In oDoc.AllReferencedDocuments
	oPartDoc = ThisApplication.Documents.Open(rDoc.FullFileName, True)
	oPartDoc.Activate

	Dim oProperty As String = "Description"
	Dim oSetValue As String = "Hello World"

	MsgBox(oPartDoc.DisplayName)
	MsgBox(oProperty & " = " & oSetValue)

	iProperties.Value(oPartDoc.displayname, "Project", oProperty) = oSetValue

	oPartDoc.Save()
	'oPartDoc.Close
Next

 

EESignature

Message 6 of 8

Daan_M
Collaborator
Collaborator

@WCrihfield @Curtis_Waguespack Thank you answering.

As i understand it, in order to use the 'iProperties.Value()' snippet i need:

 

  1. To use the 'Document.DisplayName'
  2. To have the partdocument be present in the referenced documents of the assembly i'm running my rule from

Point 2 remains a problem for me because there is no referenced documents present in my assembly file, the assembly file is simply an empty document with various iLogic codes i use.

 

How would i get oPartDoc to be referenced document of my assembly file, inside the code i already made?

Because the solution @Curtis_Waguespack offered already assumed that there's referenced documents present in my assembly (if i'm not wrong).

 

My Code;

Imports System.Windows.Forms
Sub main

Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument

Dim oFD As Inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFD)
oFD.InitialDirectory = oOrigRefName
oFD.Filter = "Excel file (*.xlsx)|*.xlsx|"
oFD.CancelError = True
On Error Resume Next
oFD.ShowOpen()
If Err.Number <> 0 Then
Return

ElseIf oFD.FileName <> "" Then
selectedfile = oFD.FileName
End If

Dim oExcel As String = selectedfile

Dim i As Integer = 3

Dim PartFileLoc As String = GoExcel.CellValue(oExcel, "Blad1", "A" & i)

If PartFileLoc = "" Then
	MsgBox("Geen PartFileLoc gevonden in cell: A" & i)
Exit Sub
End If

Do While PartFileLoc <> ""

Dim oPartDoc As PartDocument = ThisApplication.Documents.Open(PartFileLoc, True)
oPartDoc.Activate

For Each rDoc As Document In oDoc.AllReferencedDocuments
msgBox(rDoc.FullDocumentName)
Next

Dim n As Integer
Dim nRow As Integer = 2

For n = 1 To 26
	oLetter = Mid("ABCDEFGHIJKLMNOPQRSTUVWXYZ", n, 1)
	oCellAddress = oLetter & nRow
	oCellValue = GoExcel.CellValue(oCellAddress)
	GoExcel.TitleRow = nRow
	oColumnName = GoExcel.CellValue(oLetter & nRow)

If oColumnName <> ""

Dim oProperty As String = oColumnName
Dim oPropertyType As String = GoExcel.CellValue(oLetter & 1)
Dim oSetValue As String = GoExcel.CellValue(oExcel, "Blad1", oLetter & i)
	
iProperties.Value(oPartDoc.DisplayName, oPropertyType, oProperty) = oSetValue

End If
Next

i = i + 1
PartFileLoc = GoExcel.CellValue("A" & i)
oPartDoc.Save()
'oPartDoc.Close
Loop
End Sub

 

 

 

0 Likes
Message 7 of 8

WCrihfield
Mentor
Mentor

Hi @Daan_M.  If your main concern in this last post is how to access the iProperties of other documents that are not being referenced by the active document, then you could use one of two different routes.  All iProperties are stored within Document objects, and the Document object must be open before you can access its iProperties.  So if you follow the normal Inventor API path to access them, instead of that iLogic shortcut snippet, you will not have to worry about anything.

 

Each Document type object (including PartDocument, AssemblyDocument, DrawingDocument, and others) has a direct property named PropertySets, which returns a PropertySets type object.  That is a collection type that contains multiple PropertySet type objects accessed by its Item property.  Then each PropertySet is also a collection type object which contains multiple Property objects, accessed through its Item property.  The Property object is nicknamed as iProperty.  There are at least 4 PropertySet objects found in every Document type object.  The first 3 PropertySets are the standard ones in which all the Property names & ID's can not be changed, and many of their values can not be changed either, but there are also several of the most common ones that have Read/Write values.  The fourth PropertySet is the 'custom' one, and it does not contain any Properties by default, until you either add some, or expose some Parameters as custom iProperties.  It is also possible for there to be multiple other PropertySets for other purposes.  For instance, parts generated by Content Center will often have 1 or 2 other PropertySets present which may contain Content Center related information specific to that document.  And when we add rules to the 'This Document' tab of the Event Triggers dialog, that saves those settings to a special hidden PropertySet in the background also.

 

So, an example of accessing a specific iProperty (like "Part Number") of a specific document would be something like the following.

Dim oDoc As Document = ThisDoc.Document
Dim sPN As String = oDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
MessageBox.Show("Part Number = " & sPN, "Part Number", MessageBoxButtons.OK, MessageBoxIcon.Information)

And to familiarize your self with what the names and Index positions of the PropertySets and Properties is, you can create a rule that iterates over each PropertySet, captures its information, then iterates through each of its Properties, captures its information, then reports about all of it at the end.  That is partially how I created the attached PDF of an Excel spreadsheet about the iProperties, to make it easier to find the ones I want, and help others out too.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 8 of 8

Curtis_Waguespack
Consultant
Consultant

Hi @Daan_M 

 

As @WCrihfield indicated we can use the API calls to get the property set, and the property, since you are working with the application's referenced documents, and not the referenced documents of an assembly.

 

Here is an update to my previous example.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

Dim rDocs As Documents = ThisApplication.Documents
For Each rDoc As Document In rDocs
	oDoc = ThisApplication.Documents.Open(rDoc.FullFileName, True)
	oDoc.Activate
	
	'get the property set
	Dim oDTPropSet As PropertySet
	oDTPropSet = oDoc.PropertySets.Item("Design Tracking Properties")	
	
	'get the property by name
	Dim oProperty As Inventor.Property
	oProperty = oDTPropSet.Item("Description")

	'set the value
	 oProperty.Value = "Hello World"

	MsgBox(oDoc.DisplayName & vbLf & oProperty.DisplayName & " = " & oProperty.Value)	

	oDoc.Save()
	'oDoc.Close
Next

 

EESignature

0 Likes