Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Use external rule to apply iproperties to all open drawings

Luke.NashWU9MY
Participant

Use external rule to apply iproperties to all open drawings

Luke.NashWU9MY
Participant
Participant

Hi, I am looking to open 10-20 drawings, then update a few iproperties for each drawing, I'll either increase the rev, change the date, or change the author.  I have the code working for individual drawings and have found code that will cycle through each open document but the code only updates the active open document.  Here is the basic loop that I'm trying before I get more complex.  

    Dim oDoc As Document

    For Each oDoc In ThisApplication.Documents.VisibleDocuments
        If oDoc.DocumentType = kDrawingDocumentObject Then
            iProperties.Value("custom", "RevNum") = "E"

        End If
    Next oDoc

I have tried a simple line of code to modify the iproperties on a drawing that is open but is not the current active document and it doesn't seem to work as it can't find the file (file is called test.idw and is open but not active)

iProperties.Value("test.idw", "custom", "RevNum") = "E"

 

0 Likes
Reply
Accepted solutions (1)
1,143 Views
12 Replies
Replies (12)

WCrihfield
Mentor
Mentor

Here are a couple other ways to do it that may work for you:

This version continues to use the iLogic snippet line, but first 'Activate's' the document it is to target, so that it will become the 'active' document.

 

For Each oDoc As Document In ThisApplication.Documents.VisibleDocuments
	If oDoc.DocumentType = kDrawingDocumentObject Then
		oDoc.Activate
		iProperties.Value("custom", "RevNum") = "E"
	End If
Next

 

This version eliminates that iLogic snippet, can uses the API way to access the iProperty.  You don't need to 'activate' the documents when done this way, as long as they are all open or loaded into memory.

 

For Each oDoc As Document In ThisApplication.Documents.VisibleDocuments
	If oDoc.DocumentType = kDrawingDocumentObject Then
		oDoc.PropertySets.Item("Inventor User Defined Properties").Item("RevNum").Value = "E"
	End If
Next

However, the iLogic snippet will automatically create that iProperty if it is not found though, while the API example shown will not (as it is right now), but we could add a little bit more code that will cause it to create the iProperty if it is not found.

 

 

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

If you want and have time, I would appreciate your Vote(s) for My IDEAS ๐Ÿ’ก or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

WCrihfield
Mentor
Mentor
Accepted solution

Here are a couple more examples using the API route, that will create that iProperty if it is not found.  There are other ways to do this too.

This version requires less code, but is also potentially less efficient.

 

For Each oDoc As Document In ThisApplication.Documents.VisibleDocuments
	If oDoc.DocumentType <> kDrawingDocumentObject Then Continue For
	Try
		oDoc.PropertySets.Item("Inventor User Defined Properties").Item("RevNum").Value = "E"
	Catch
		oDoc.PropertySets.Item("Inventor User Defined Properties").Add("E", "RevNum")
	End Try
Next

 

This version is more code, but also more efficient and proper.

 

For Each oDoc As Document In ThisApplication.Documents.VisibleDocuments
	If oDoc.DocumentType <> kDrawingDocumentObject Then Continue For
	oCProps = oDoc.PropertySets.Item("Inventor User Defined Properties")
	Dim oCProp As Inventor.Property
	If oCProps.Count > 0 Then
		For Each oProp As Inventor.Property In oCProps
			If oProp.Name = "RevNum" Then
				oProp.Value = "E"
				oCProp = oProp
				Exit For 'exit loop, and maintain value of oCProp
			End If
		Next
	End If
	If oCProp Is Nothing Then
		oCProp = oCProps.Add("E", "RevNum")
	End If
Next

 

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Luke.NashWU9MY
Participant
Participant

You sir are my hero.  Thank you so much.  

0 Likes

Luke.NashWU9MY
Participant
Participant

FYI, i tried this first line of code previous and even though it activates each doc, it doesn't update the revnum other than the first one

0 Likes

Luke.NashWU9MY
Participant
Participant

I'm trying to add a little more complication now but not too much, when we issue our drawings for construction, we delete the preliminary stamp from each drawing, this stamp is a sketch symbol called PRELIMINARY.  This is code I use to delete the symbol in each drawing and it works well but I'm having trouble again applying it to all open documents.

 

Dim myDate As String = Now().ToString("M/d/yyyy")
myDate = myDate.Replace(":", "")  ' & " - " & TypeString
Dim oDrawDoc As DrawingDocument

userChoice = InputRadioBox("Defined the scope", "This Document", "All Open Documents", True, Title := "Defined the scope")
 If userChoice Then
iProperties.Value("Custom", "DRAWING STATUS") = "ISSUED FOR CONSTRUCTION"
iProperties.Value("Custom", "REV LINE 1") = "ISSUED FOR CONSTRUCTION"
iProperties.Value("Custom", "REV LINE 2") = ""
iProperties.Value("Custom", "REV LINE 3") = ""
iProperties.Value("Custom", "REV LINE 4") = ""
iProperties.Value("Custom", "REV LINE 5") = ""
iProperties.Value("Custom", "REV LINE 6") = ""
iProperties.Value("Custom", "REV LINE 7") = ""
iProperties.Value("Custom", "REVNUM") = "A"
iProperties.Value("Custom", "CHECKED BY") = iProperties.Value("Custom", "CURRENT USER")
iProperties.Value("Custom", "CHECKED DATE") = myDate
iProperties.Value("Custom", "REV BY") = iProperties.Value("Custom", "CURRENT USER")
iProperties.Value("Custom", "REV DATE") = myDate
'Define the drawing document

oDrawDoc = ThisDoc.Document

'Iterate through each symbol in the active sheet
For Each oSymbol In oDrawDoc.ActiveSheet.SketchedSymbols
	'look for the symbol by name
	If oSymbol.Name = "PRELIMINARY" Then
		oSymbol.Delete
	End If
Next 
  Else
	  For Each oDoc As Document In ThisApplication.Documents.VisibleDocuments
	If oDoc.DocumentType = kDrawingDocumentObject Then
		oDoc.PropertySets.Item("Inventor User Defined Properties").Item("DRAWING STATUS").Value = "ISSUED FOR CONSTRUCTION"
		oDoc.PropertySets.Item("Inventor User Defined Properties").Item("REV LINE 1").Value = "ISSUED FOR CONSTRUCTION"
		oDoc.PropertySets.Item("Inventor User Defined Properties").Item("REV LINE 2").Value = ""
		oDoc.PropertySets.Item("Inventor User Defined Properties").Item("REV LINE 3").Value = ""
		oDoc.PropertySets.Item("Inventor User Defined Properties").Item("REV LINE 4").Value = ""
		oDoc.PropertySets.Item("Inventor User Defined Properties").Item("REV LINE 5").Value = ""
		oDoc.PropertySets.Item("Inventor User Defined Properties").Item("REV LINE 6").Value = ""
		oDoc.PropertySets.Item("Inventor User Defined Properties").Item("REV LINE 7").Value = ""
		oDoc.PropertySets.Item("Inventor User Defined Properties").Item("REVNUM").Value = "A"
		oDoc.PropertySets.Item("Inventor User Defined Properties").Item("CHECKED BY").Value = iProperties.Value("Custom", "CURRENT USER")
		oDoc.PropertySets.Item("Inventor User Defined Properties").Item("CHECKED DATE").Value = myDate
		oDoc.PropertySets.Item("Inventor User Defined Properties").Item("REV BY").Value = iProperties.Value("Custom", "CURRENT USER")
		oDoc.PropertySets.Item("Inventor User Defined Properties").Item("REV DATE").Value = myDate
oDrawDoc = ThisDoc.Document
'Iterate through each symbol in the active sheet
For Each oSymbol In oDrawDoc.ActiveSheet.SketchedSymbols
	'look for the symbol by name
	If oSymbol.Name = "PRELIMINARY" Then
		oSymbol.Delete
	End If
Next 

	End If
Next
   
  End If


0 Likes

Luke.NashWU9MY
Participant
Participant

The text in blue is my attempt but no 1, in only does the active sheet, 2, it only works for the first document.  

0 Likes

Luke.NashWU9MY
Participant
Participant

I hope this comes in useful for someone else but I managed to achieve both issues with an extra line.  I am by no means an experienced code writer so I'm sure this is very inefficient but it works:

 

Dim myDate As String = Now().ToString("M/d/yyyy")
myDate = myDate.Replace(":", "")  ' & " - " & TypeString
Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument

userChoice = InputRadioBox("Defined the scope", "This Document", "All Open Documents", True, Title := "Defined the scope")
 If userChoice Then
iProperties.Value("Custom", "DRAWING STATUS") = "ISSUED FOR CONSTRUCTION"
iProperties.Value("Custom", "REV LINE 1") = "ISSUED FOR CONSTRUCTION"
iProperties.Value("Custom", "REV LINE 2") = ""
iProperties.Value("Custom", "REV LINE 3") = ""
iProperties.Value("Custom", "REV LINE 4") = ""
iProperties.Value("Custom", "REV LINE 5") = ""
iProperties.Value("Custom", "REV LINE 6") = ""
iProperties.Value("Custom", "REV LINE 7") = ""
iProperties.Value("Custom", "REVNUM") = "A"
iProperties.Value("Custom", "CHECKED BY") = iProperties.Value("Custom", "CURRENT USER")
iProperties.Value("Custom", "CHECKED DATE") = myDate
iProperties.Value("Custom", "REV BY") = iProperties.Value("Custom", "CURRENT USER")
iProperties.Value("Custom", "REV DATE") = myDate
'Define the drawing document

oDrawDoc = ThisDoc.Document
'Define the drawing document

'Loop through sheets
For Each oSheet In oDrawDoc.Sheets 
	'Loop through each symbol
	For Each oSymbol In oSheet.SketchedSymbols
		'look for the symbol by name
		If oSymbol.Name = "PRELIMINARY" Then
			oSymbol.Delete
		End If
	Next
Next
  Else
	  For Each oDoc As Document In ThisApplication.Documents.VisibleDocuments
	If oDoc.DocumentType = kDrawingDocumentObject Then
		oDoc.PropertySets.Item("Inventor User Defined Properties").Item("DRAWING STATUS").Value = "ISSUED FOR CONSTRUCTION"
		oDoc.PropertySets.Item("Inventor User Defined Properties").Item("REV LINE 1").Value = "ISSUED FOR CONSTRUCTION"
		oDoc.PropertySets.Item("Inventor User Defined Properties").Item("REV LINE 2").Value = ""
		oDoc.PropertySets.Item("Inventor User Defined Properties").Item("REV LINE 3").Value = ""
		oDoc.PropertySets.Item("Inventor User Defined Properties").Item("REV LINE 4").Value = ""
		oDoc.PropertySets.Item("Inventor User Defined Properties").Item("REV LINE 5").Value = ""
		oDoc.PropertySets.Item("Inventor User Defined Properties").Item("REV LINE 6").Value = ""
		oDoc.PropertySets.Item("Inventor User Defined Properties").Item("REV LINE 7").Value = ""
		oDoc.PropertySets.Item("Inventor User Defined Properties").Item("REVNUM").Value = "A"
		oDoc.PropertySets.Item("Inventor User Defined Properties").Item("CHECKED BY").Value = iProperties.Value("Custom", "CURRENT USER")
		oDoc.PropertySets.Item("Inventor User Defined Properties").Item("CHECKED DATE").Value = myDate
		oDoc.PropertySets.Item("Inventor User Defined Properties").Item("REV BY").Value = iProperties.Value("Custom", "CURRENT USER")
		oDoc.PropertySets.Item("Inventor User Defined Properties").Item("REV DATE").Value = myDate
		oDrawDoc = oDoc
'Define the drawing document

'Loop through sheets
For Each oSheet In oDrawDoc.Sheets 
	'Loop through each symbol
	For Each oSymbol In oSheet.SketchedSymbols
		'look for the symbol by name
		If oSymbol.Name = "PRELIMINARY" Then
			oSymbol.Delete
		End If
	Next
Next

	End If
Next
   
  End If

0 Likes

contact
Advocate
Advocate

Hi, I have been trying to adapt the following ilogic (works for the active document) to the described concept for all open drawings (INV 2023), but I failed:

 

'Define the open document
Dim openDoc As Document
openDoc = ThisDoc.Document
Dim docFile As Document

oTime = Now.ToShortDateString 'aktelles Datum ermitteln

iProperties.Value("Project", "Creation Date") = oTime 'Creation Date

iLogicVb.UpdateWhenDone = True 'aktualisieren

i = MessageBox.Show("Erstellungsdatum aktualisiert!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1)
Dim doc = ThisDoc.Document


If MsgBox("รœberschreibt den Revisionsindex auf 00.", vbOKCancel, "Revision Number") = vbOK Then
iProperties.Value("Project", "Revision Number") = "00"
End If

 

But I could not get this to change the standard iproperty for the creation date.

Is there a difference, whether I want to change a standard iproperty or if I am using a user defined one?

 

Help is appreciated, Thanks, Jan.

0 Likes

WCrihfield
Mentor
Mentor

Hi @contact.  Below is a modified version of your code that should run on every 'open' document, as you seem to be wanting.  However, notice the first two lines of code.  There are two different levels of 'open', when it comes to Inventor documents.  There are the 'visible' open documents, which you can see the document tabs for on your screen, then there may often times be many more documents that are technically open, but just not visibly.  Any time you open an assembly or drawing, that also initializes/opens all of their referenced documents invisibly in the background.  Just so you know.  And you can not close those other invisibly open documents, while they are still being referenced by the assembly or drawing that you may have opened, that is still referencing them.

Dim oAllOpenDocuments As Documents = ThisApplication.Documents
Dim oAllVisiblyOpenDocuments As DocumentsEnumerator = oAllOpenDocuments.VisibleDocuments
'use whichever of these above that suits your needs better for the following loop
For Each oDoc As Document In oAllVisiblyOpenDocuments
	Dim oProjectPropSet As PropertySet = oDoc.PropertySets.Item(3)
	oProjectPropSet.Item("Creation Date").Value = Now
	i = MessageBox.Show("Erstellungsdatum aktualisiert!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1)
	If MsgBox("รœberschreibt den Revisionsindex auf 00.", vbOKCancel, "Revision Number") = vbOK Then
		oProjectPropSet.Item("Revision Number").Value = "00"
	End If
	oDoc.Update
	'oDoc.Save
Next

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)

contact
Advocate
Advocate
Thanks for the fast reply.
I will keep trying with this.
0 Likes

A.Acheson
Mentor
Mentor

The iproperty "Creation Date" doesn't exist. Use "Creation Time". See this post here and these two articles Article1 and Article2 confirming this. 

It can be the case that the display name in the iproperty dialogue does not match the built in property name. 

If this solved a problem, please click (accept) as solution.โ€Œโ€Œโ€Œโ€Œ
Or if this helped you, please, click (like)โ€Œโ€Œ
Regards
Alan

WCrihfield
Mentor
Mentor

Good catch @A.Acheson๐Ÿ‘  I did not notice that important detail.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes