How to null all iproperties with ilogic?

How to null all iproperties with ilogic?

Anonymous
Not applicable
2,429 Views
9 Replies
Message 1 of 10

How to null all iproperties with ilogic?

Anonymous
Not applicable

I am looking for an easy way to clear iproperties, when I have copied an old part / assembly.

Any ideas for code on this?

0 Likes
Accepted solutions (2)
2,430 Views
9 Replies
Replies (9)
Message 2 of 10

Owner2229
Advisor
Advisor

Hi, if the iProperties' names are always the same (I assume you mean custom iProperties) then it is quite easy to do:

 

 

iProperties.Value("Custom", "PropertyName1") = ""
iProperties.Value("Custom", "PropertyName2") = ""

 

For Project iProperties:

 

iProperties.Value("Project", "Part Number") = ""

 

For assembly:

 

Dim oDoc As Document = ThisApplication.ActiveDocument
Dim aDoc As DocumentsEnumerator = oDoc.AllReferencedDocuments
Dim iDoc As Document
For Each iDoc In aDoc
    'Here we clean iProperties in each of the parts in assembly
Dim sTS As String = iDoc.FullFileName
Dim FNamePos As Long = InStrRev(sTS, "\", - 1) Dim docFName As String = Mid(sTS, FNamePos + 1, Len(sTS) - FNamePos) iProperties.Value(docFName, "Custom", "PropertyName1") = "" iProperties.Value(docFName, "Custom", "PropertyName2") = "" Next
'Here we clean the assembly's iProperties iProperties.Value("Custom", "PropertyName1") = "" iProperties.Value("Custom", "PropertyName2") = ""

 

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 3 of 10

Anonymous
Not applicable

Hi Mike, thanks for your reply, however your assumption is wrong. I already have a way of clearing custom properties, I want to clear/null "Inventor Summary Information", "Design Tracking Properties" and "Inventor Document Summary Information" or even better ALL iproperties at once.

0 Likes
Message 4 of 10

Curtis_Waguespack
Consultant
Consultant
Accepted solution

HI rki,

 

I just realized I had a rule to do this. In my case I use it to set "defaults" for each property (rather than clearing them). I do this for testing and then clear or set them using another rule. But the other rule has a lot of other stuff mixed in. So I've just made this rule clear/reset the iProperties for your needs.

 

So you can just change the test values at the beginning of the rule to modify this as needed. Note that it hits all of the iProperty collections including the custom iProperties.

 

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

 

 

'[ wrap in a transaction to allow single undo
oApp = ThisApplication
Call oApp.TransactionManager.StartTransaction(ThisDoc.Document, "Clear All iProperties")

	' test values
	' change these as needed
	oString = ""  
	oInteger = 1
	oBool = True
	oDate = Nothing
	
	oDoc = ThisDoc.Document
	
	'[ 'define custom property collection
	Dim oCustomPropertySet As PropertySet
	oCustomPropertySet = oDoc.PropertySets.Item("Inventor User Defined Properties")
		For Each oProp In oCustomPropertySet		
			If TypeOf oProp.Value Is Integer Then
				oProp.Value = oInteger
			Else If TypeOf oProp.Value Is Boolean Then
				oProp.Value = oBool
			Else If TypeOf oProp.Value Is String Then
				oProp.Value = oString
			Else If TypeOf oProp.Value Is Date Then
				iProperties.Value("Custom", oProp.Name) = oDate	
			Else
			End If
		Next
	']	
	
	'[ 'define Summary Information property collection
	Dim oSUMProperties As PropertySet
	oSUMProperties = oDoc.PropertySets.Item("Inventor Summary Information")
		For Each oProp In oSUMProperties		
			If TypeOf oProp.Value Is Integer Then
				oProp.Value = oInteger
			Else If TypeOf oProp.Value Is Boolean Then
				oProp.Value = oBool
			Else If TypeOf oProp.Value Is String Then
				oProp.Value = oString
			Else
			End If
		Next
	']
	
	'[ 'define Design Tracking property collection
	Dim oDTProperties As PropertySet		
	oDTProperties = oDoc.PropertySets.Item("Design Tracking Properties")	
		For Each oProp In oDTProperties		
			If TypeOf oProp.Value Is Integer Then
				oProp.Value = oInteger
			Else If TypeOf oProp.Value Is Date Then
				iProperties.Value("Status", oProp.Name) = oDate	
			Else If TypeOf oProp.Value Is Boolean Then
				oProp.Value = oBool
			Else If TypeOf oProp.Value Is String Then
				oProp.Value = oString
			Else
			End If
			
			'Set creation time and design status
			'Currently being reset the same as anything else
			'But at one point these were being "reset" differently 
			If oProp.Name = "Creation Time" Then
			iProperties.Value("Project", "Creation Time") = oDate
			ElseIf oProp.Name = "Design Status"
			iProperties.Value("Status", "Design Status") = oInteger
			End If				
		Next
	']
	
	'[ 'define Document Summary property collection
	Dim oDocSUMProperties As PropertySet
	oDocSUMProperties = oDoc.PropertySets.Item("Inventor Document Summary Information")	
		For Each oProp In oDocSUMProperties		
			If TypeOf oProp.Value Is Integer Then
				oProp.Value = oInteger
			Else If TypeOf oProp.Value Is Boolean Then
				oProp.Value = oBool
			Else If TypeOf oProp.Value Is String Then
				oProp.Value = oString
			Else
			End If
		Next	
	']
	
	iLogicVb.UpdateWhenDone = True
oApp.TransactionManager.EndTransaction
 ']

 

EESignature

Message 5 of 10

Owner2229
Advisor
Advisor
Accepted solution

Or simply this:

 

On Error Resume Next
Dim oDoc As Document
oDoc = ThisDoc.Document
Dim oPropSets As PropertySets
oPropSets = oDoc.PropertySets
Dim oPropSet As PropertySet
Dim iPro As Inventor.Property
For Each oPropSet In oPropSets
    For Each iPro In oPropSet
        iPro.Value = ""
    Next
Next

Or with ussage of Curtis' type selection:

 

On Error Resume Next
oString = ""  
oInteger = 1
oBool = True
oDate = Nothing
Dim oDoc As Document
oDoc = ThisDoc.Document
Dim oPropSets As PropertySets
oPropSets = oDoc.PropertySets
Dim oPropSet As PropertySet
Dim iPro As Inventor.Property
For Each oPropSet In oPropSets
    For Each iPro In oPropSet
        If TypeOf iPro.Value Is Integer Then
	    iPro.Value = oInteger
	Else If TypeOf iPro.Value Is Boolean Then
	    iPro.Value = oBool
	Else If TypeOf iPro.Value Is String Then
	    iPro.Value = oString
	Else If TypeOf iPro.Value Is Date Then
	    iPro.Value = oDate
	End If
    Next
Next
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 6 of 10

Anonymous
Not applicable

Hi Mike thanks again for your effort.

 

However the short version did not work (inventor crashed)

 

The longer version worked, but did not null the dates (uncheck)

 

The solution from curtis above does what I need, when I deleted his call in the beginning of the program.

 

Thanks again to you both.

 

Bset regards, Rasmus

 

0 Likes
Message 7 of 10

e_frissell
Advocate
Advocate

@Curtis_Waguespack 


I'm working on a rule to do the same thing - I have one rule that publishes a bunch of stuff to about 20 different iProperties and for testing need an iLogic rule to clear them and have been trying to write a rule but I don't really understand why this one throws errors.  It seems like it should work, every iProperty is set to text so there shouldn't be a type mismatch but rather it simply doesn't run


The intent here is pretty clear as well - that the script should figure out how many iproperties there are, access each one by index, then set that value to "" but... errors.

 

Any help on this would be appreciated

 

 

Sub Main()

Dim i As Integer
Dim oCustomPropertySet = ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties")

i = 0
For Each oProp In oCustomPropertySet
	oProp = oCustomPropertySet.Item(i)
	oProp.Value = "ST"
	i = i+1
Next

End Sub

 

 

0 Likes
Message 8 of 10

Curtis_Waguespack
Consultant
Consultant

@e_frissell 

I'm not sure what this issue would be, but maybe you can try catching the error and reporting it to the logger.

 

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

 

Sub Main()

'show ilogic logger
ThisApplication.UserInterfaceManager.DockableWindows.Item("ilogic.logwindow").Visible = True

Dim oCustomPropertySet = ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties")

For Each oProp as Inventor.Property In oCustomPropertySet
	Try
		oProp.Value = "ST"
	Catch ex As Exception
		Logger.Info("problem with: " & oProp.Name)
		Logger.Info(ex.Message)
	End Try
Next

End Sub

 

EESignature

0 Likes
Message 9 of 10

WCrihfield
Mentor
Mentor

Hi guys.  I think I see the small detail.  You are setting 'i' to zero, then you are trying to get a Property at the index of zero from the PropertySet.  Inventor based collections all start at index 1, not zero.  VB.NET collections usually start at index of zero though.  Plus, you are not checking the Count of the PropertySet first.  If it did not have any Properties in it, that might cause a problem.  Plus, if the document was ReadOnly for some reason, it might cause a problem.  Using the Try...Catch statement like Curtis suggested is a great idea when working with custom iProperties though.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 10 of 10

e_frissell
Advocate
Advocate

OHH!! Trying to access an index value that doesn't exist would do it!  I'm surprised it didn't throw an index error for the index not existing

 

You're right about the i also!  It was written as for i = 0 to oCustomPropertySet.Count which didn't work then re-tried with the for each loop

 

Just rewrote it using for i = 0 to .count and it runs

0 Likes