Delete all instance properties

Delete all instance properties

AaronJoSmith
Participant Participant
294 Views
3 Replies
Message 1 of 4

Delete all instance properties

AaronJoSmith
Participant
Participant

I'm trying to figure out how to delete instance properties using iLogic. To be clear, I mean completely remove the property, not just set it equal to nothing. In my case, I need to cycle through every instance in an assembly and delete all of the existing instance properties that have the title "TAG". Is there a way to do this?

 

Thanks in advance.

0 Likes
295 Views
3 Replies
Replies (3)
Message 2 of 4

A.Acheson
Mentor
Mentor

Hi @AaronJoSmith 

This post here has an instance property called occurrence propertysets in the API help page shown here.

 

The below should work to delete the property. 

Sub Main
	oADoc = ThisAssembly.Document
	oADef = oADoc.ComponentDefinition
	oOccs = oADef.Occurrences
	oTrans = ThisApplication.TransactionManager.StartTransaction(oADoc, "Rename Components W/ SN")
	RecusivelyIterateComponents(oOccs)
	oTrans.End
End Sub

Sub RecusivelyIterateComponents(oComps As ComponentOccurrences)
	If IsNothing(oComps) OrElse oComps.Count = 0 Then Exit Sub
	For Each oComp As ComponentOccurrence In oComps
		Try
			If oComp.OccurrencePropertySetsEnabled Then
				Dim oInstPSet As PropertySet = oComp.OccurrencePropertySets.Item(1)
               For Each prop in oInstPSet
                 If prop.Name = "TAG" Then
                    prop.Delete
                 End If
               Next	
			End If
		Catch
		End Try
		If oComp.SubOccurrences.Count > 0 Then
			RecusivelyIterateComponents(oComp.SubOccurrences)
		End If
	Next
End Sub

 

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

AaronJoSmith
Participant
Participant

Looks like the code works well. Thanks!

In addition to clearing the instance properties, is it possible to delete the instance row, removing the blue highlighting from the BOM? The equivalent of clicking the button showed below. It seems that the blue highlighting is still there after the code deletes all the "TAG" instance properties.

AaronJoSmith_0-1698685340080.png

AaronJoSmith_1-1698685452676.png

 

0 Likes
Message 4 of 4

WCrihfield
Mentor
Mentor

Hi @AaronJoSmith.  I still have not had a chance to test either of the following two suggestions, but I just wanted to mention these two ideas here to see if they may work for that situation.  The first idea is...while looping through each component in the assembly, if that one instance property that is being deleted is the only one, then we may be able to set the ComponentOccurrence.OccurrencePropertySetsEnabled property, which is a Read/Write Boolean, to False, before moving on to the next component in the loop.  I am not sure yet if that would automatically eliminate those BOMRows and/or blue highlighting in the BOM dialog, but it seems like a step in that direction.  Of course, any time these types of edits/changes are made in an assembly, the assembly will most likely need to be updated before you will see the changes, so a line could be added to the code for updating the assembly after the process is done too.  The other idea is to use the BOM.SetPartNumberMergeSettings2 method, and specify True for the optional third input called 'MergeInstanceRows', which is a Boolean.  Not sure if that would work as intended either, but its worth testing.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes