I-Logic delete iproperties if they contain a text string

I-Logic delete iproperties if they contain a text string

william
Advocate Advocate
1,049 Views
4 Replies
Message 1 of 5

I-Logic delete iproperties if they contain a text string

william
Advocate
Advocate

Hello 

I am trying to write some code to look through the custom i-properties and if the name of the i-property contains the search term, then delete it. 

 

So far I have got to here...

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

Dim searchTerm As String 
searchTerm = "Item"

For Each oCustomPropertyName in oCustomPropertySet
	If InStr(1, oCustomPropertyName, searchTerm, CompareMethod.Text) >0 Then 
		MessageBox.Show("We found it", "Debug")

	Else
		MessageBox.Show("We didnt find it", "Debug")

	End If
	
Next

 

The error i am getting is "Conversion from type 'Property' to type 'String' is not valid."

 

What am I doing wrong?

 

Regards

0 Likes
Accepted solutions (1)
1,050 Views
4 Replies
Replies (4)
Message 2 of 5

johnsonshiue
Community Manager
Community Manager

Hi William,

 

I have to take a guess. Probably, you need to declare a String variable to capture "CustomPropertyName" value. It is because "CustomPropertyName" itself isn't a String variable.

Many thanks!



Johnson Shiue (johnson.shiue@autodesk.com)
Software Test Engineer
0 Likes
Message 3 of 5

william
Advocate
Advocate

Hello @johnsonshiue 

I have just tried that, I get the same error.

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

Dim oCustomPropertyName As String 
oCustomPropertyName = CStr(oCustomPropertySet.Name)

Dim searchTerm as String 
searchTerm = "Item"

For Each oCustomPropertyName In oCustomPropertySet
	If InStr(1, oCustomPropertyName, searchTerm, CompareMethod.Text) >0 Then 
		MessageBox.Show("We found it", "Debug")

	Else
		MessageBox.Show("We didnt find it", "Debug")

	End If
	
Next

Is the InStr command the best way of going about this? I originally took @Curtis_Waguespack code from an earlier post (https://forums.autodesk.com/t5/inventor-forum/how-to-remove-custom-iproperty-with-ilogic/td-p/436406...

but the ".contains" method doesnt seem to work if the search term is inside the string, eg. it will not pick up that "Item" is contained inside "Item8_Code" 

 

so I found another post that I though would be applicable (https://forums.autodesk.com/t5/inventor-customization/code-vb-for-if-quot-value-quot-contains-quot-t...

 

Any help would be appreciated. 

 

0 Likes
Message 4 of 5

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @william 

 

This should work for you.

 

Also recall that there is the Inventor Customization forum , where programming questions of this type are better suited:
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120

 

I'll ask the moderators to move this to that forum.

 

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

 

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

Dim searchTerm As String 
searchTerm = "Item"

For Each oProp In oCustomPropertySet
	If oProp.name.Contains(searchTerm) Then 
		MessageBox.Show("We found: " & oProp.name  _
		& vbLf & "Now we're going to delete it!", "iLogic")
		oProp.delete
		
	End If	
Next

EESignature

Message 5 of 5

william
Advocate
Advocate

many thanks. That works great