iLogic to change drawing cutom iProperties

iLogic to change drawing cutom iProperties

IB55
Advocate Advocate
572 Views
6 Replies
Message 1 of 7

iLogic to change drawing cutom iProperties

IB55
Advocate
Advocate

Hi,

I am trying to create a rule to run on all open drawings and change Cusom iProperty values.

my code looks like this:

Dim oDoc As Document
For Each oDoc In ThisApplication.Documents.VisibleDocuments
	If oDoc.DocumentType = kDrawingDocumentObject Then
        oDoc.Activate
	If iProperties.Value("Custom", "Colour") Is "RAL 9006" Then iProperties.Value("Custom", "Class 2")="x"
	End If
Next oDoc

 Intention is to change value of custom property "Class 2" to "X" if custom property "Colour" has value "RAL 9006"

The code as it is does not work. Any suggestions or tips will be much appreciated.

0 Likes
Accepted solutions (1)
573 Views
6 Replies
Replies (6)
Message 2 of 7

mcgyvr
Consultant
Consultant

Change Is "RAL 9006" to = "RAL 9006"

 



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
0 Likes
Message 3 of 7

IB55
Advocate
Advocate

Thank you for your comment. I changed "Is" with "=" but code still does not work. It runs through the opened drawings but does not make any changes. 

Dim oDoc As Document
For Each oDoc In ThisApplication.Documents.VisibleDocuments
	If oDoc.DocumentType = kDrawingDocumentObject Then
        oDoc.Activate
	If iProperties.Value("Custom", "Colour") = "RAL 9006" Then iProperties.Value("Custom", "Class 2")="x"
	End If
Next oDoc

 

0 Likes
Message 4 of 7

IB55
Advocate
Advocate

I forgot to mention that I am running this rule externally

0 Likes
Message 5 of 7

WCrihfield
Mentor
Mentor
Accepted solution

When you use the iProperties.Value() shortcut, it targets the 'active' document, which doesn't seem like it would be a problem in this case, but just in case it is the (or a) problem here, I've decided to go through the process the longer (standard) route.  You could have looped through the custom iProperties to find these two when going the longer route, but I chose the Try...Catch...End Try path, because they will produce the same outcome, with maybe a slight difference in performance, one way or the other.

Give this a try.

Dim oDoc As Document
For Each oDoc In ThisApplication.Documents.VisibleDocuments
	'only process drawing documents
	If oDoc.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Continue For
	Dim oCProps As PropertySet = oDoc.PropertySets.Item(4) 'always the 'Custom' set
	Dim oColour, oClass2 As Inventor.Property
	Try
		oColour = oCProps.Item("Colour")
	Catch
		MsgBox("Couldn't find 'Colour' property in " & oDoc.FullDocumentName, , "")
		Continue For 'skip to next document in loop
	End Try
	Try
		oClass2 = oCProps.Item("Class 2")
	Catch
		oClass2 = oCProps.Add("", "Class 2")
	Catch
		MsgBox("Couldn't find or create 'Class 2' property in " & oDoc.FullDocumentName)
		Continue For 'skip to next document in loop
	End Try
	If oColour.Value = "RAL 9006" Then
		oClass2.Value = "x"
	End If
Next oDoc

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)

Message 6 of 7

IB55
Advocate
Advocate
 

Hi WCrihfield,

Thank you so much, it worked like a charm! 

I guess when code is for multiply documents it is essential to direct it to the documents (run through the loop) and define properties.

Once again, thank you very much for your help.

 
0 Likes
Message 7 of 7

Anonymous
Not applicable

Hello, There is an app on the app store which will make quick work of this. Its called Fyenite You can edit iproperties in a single file or multiple files at the same time. The user can also link and group the selections, so the properties all change with a single entry. I hope this helps. Good Luck.

0 Likes