Why this rule does not to run?

Why this rule does not to run?

38620079
Contributor Contributor
1,026 Views
7 Replies
Message 1 of 8

Why this rule does not to run?

38620079
Contributor
Contributor

HI,I don't know how to make this rule work below the code, who can tell me what to do?

Thanks!

 

 

 

Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument
Dim osubdoc As Document
Dim opropset As Inventor.PropertySet
Dim icount As Long
For Each osubdoc In oDoc.AllReferencedDocuments
opropset = osubdoc.PropertySets.Item(4).Item 'User DefinedProperties
icount = opropset.Count
If icount>0 Then
For i = icount To 1 Step -1
On Error Resume Next
opropset.Item(i). Delete
Err.Clear
Next
End If
Next

0 Likes
Accepted solutions (2)
1,027 Views
7 Replies
Replies (7)
Message 2 of 8

A.Acheson
Mentor
Mentor
Accepted solution

Hi @38620079 

You have incorrectly set the Property Set.

AAcheson_0-1691865700583.png

Working code

Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument

Dim osubdoc As Document
Dim opropset As Inventor.PropertySet
Dim icount As Long

For Each osubdoc In oDoc.AllReferencedDocuments

	opropset = osubdoc.PropertySets.Item(4) 'User DefinedProperties
	icount = opropset.Count

	If icount>0 Then
	
		For i = icount To 1 Step -1
			On Error Resume Next
			opropset.Item(i).Delete
			Err.Clear
		Next
	End If
Next

and here is a shorter version of the same without indexing and with a check for modifiable files ( skip Read only files such as Content center and Library files)

Dim oDoc As Document = ThisApplication.ActiveDocument

For Each osubdoc As Document In oDoc.AllReferencedDocuments
	If osubdoc.IsModifiable Then
		Dim opropset As Inventor.PropertySet = osubdoc.PropertySets.Item(4)

		For Each prop As Inventor.Property In opropset
			prop.Delete
		Next
	End If
Next

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 8

38620079
Contributor
Contributor
Accepted solution

thank you! but i want to do that

mmexport1691928662756.png

 

0 Likes
Message 4 of 8

A.Acheson
Mentor
Mentor

This screenshot is from VBA object model editor.

AAcheson_0-1691939057566.png

 

 

Are you using VBA or ilogic\VB.Net launguage?

The code you provide originally is for ilogic\VB.Net launguage and the revised code is written for their also. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 5 of 8

38620079
Contributor
Contributor

is Ok thanks

 

mmexport1691939044106.png

 

0 Likes
Message 6 of 8

A.Acheson
Mentor
Mentor

Yes this code here will do exactly that, loop over all custom iproperties and delete. If it does not work please provide a screenshot of errorbmessages. 

Dim oDoc As Document = ThisApplication.ActiveDocument

For Each osubdoc As Document In oDoc.AllReferencedDocuments
	If osubdoc.IsModifiable Then
		Dim opropset As Inventor.PropertySet = osubdoc.PropertySets.Item(4)

		For Each prop As Inventor.Property In opropset
			prop.Delete
		Next
	End If
Next

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 7 of 8

38620079
Contributor
Contributor

I am wrong,I use rules to run in part, not in assembly.

0 Likes
Message 8 of 8

A.Acheson
Mentor
Mentor

Here it is to delete custom iprop per document, run as an external rule

Dim oDoc As Document = ThisApplication.ActiveDocument

Dim opropset As Inventor.PropertySet = oDoc.PropertySets.Item(4)
For Each prop As Inventor.Property In opropset
   prop.Delete
Next
If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes