Ilogic not deleting virtual parts correctly

Ilogic not deleting virtual parts correctly

Thomas.Long
Advocate Advocate
423 Views
2 Replies
Message 1 of 3

Ilogic not deleting virtual parts correctly

Thomas.Long
Advocate
Advocate

I have a program that cycles through an assembly, finds the parts I need to order, and creates as many virtual parts as I need to order. Each time I run the rule, it is supposed to delete all previous virtual components and add as many virtual components as it needs.

 

The problem is, if I go through the assembly and delete all instances of these parts, it will still leave one virtual component left over. Not a problem to delete manually, but I'd still like to understand why this is occurring. Can anyone help me understand why it is doing this?

 

Thank you in advance to everyone for helping out!

 

Function UpdateVirtParts (sVirtPart, Description, iQty)

	'define assembly
	Dim asmDoc As AssemblyDocument
	asmDoc = ThisApplication.ActiveDocument
	'define assembly Component Definition
	Dim oAsmCompDef As AssemblyComponentDefinition
	oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
	
	'Iterate through all of the occurrences in the assembly
	Dim asmOcc As ComponentOccurrence
	For Each asmOcc  In oAsmCompDef.Occurrences
	
		'get name of occurence only (sees only everything left of the colon)
		Dim oOcc As Object
		oOcc = asmOcc.Name.Split(":")(0)
		
		'look at only virtual components
		If TypeOf asmOcc.Definition Is VirtualComponentDefinition
			'compare name selected from list to the
			'existing virtual parts
			If oOcc = sVirtPart Then asmOcc.delete
		End If
	Next
	
	Dim occs As ComponentOccurrences
	occs = asmDoc.ComponentDefinition.Occurrences
	
	Dim identity As Matrix
	identity = ThisApplication.TransientGeometry.CreateMatrix
	
	'create first instance of the virtual part
	Dim virtOcc As ComponentOccurrence
	virtOcc = occs.AddVirtual(sVirtPart, identity)
	iProperties.Value(sVirtPart & ":1", "Project", "Description") = Description
	iProperties.Value(sVirtPart & ":1", "Project", "Part Number") = sVirtPart
	
	For index As Integer = 2 To iQTY
		occs.AddByComponentDefinition(virtOcc.Definition, identity)
	Next

End Function
0 Likes
424 Views
2 Replies
Replies (2)
Message 2 of 3

mkaercher
Explorer
Explorer

 Try this.

 

doc = ThisDoc.Document
Dim compOcc As ComponentOccurrence = Component.InventorComponent("V_Part_0:1")
compOcc = Component.InventorComponent("V_Part_A:1")
compOcc = Component.InventorComponent("V_Part_B:1")
compOcc = Component.InventorComponent("V_Part_C:1")
compOcc = Component.InventorComponent("V_Part_D:1")
compOcc = Component.InventorComponent("V_Part_E:1")
compOcc = Component.InventorComponent("V_Part_F:1")
compOcc.Delete()

0 Likes
Message 3 of 3

bradeneuropeArthur
Mentor
Mentor

try this and compare if it is correctly:

 

Function UpdateVirtParts (sVirtPart, Description, iQty)

	'define assembly
	Dim asmDoc As AssemblyDocument
	asmDoc = ThisApplication.ActiveDocument
	'define assembly Component Definition
	Dim oAsmCompDef As AssemblyComponentDefinition
	oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
	
	'Iterate through all of the occurrences in the assembly
	Dim asmOcc As ComponentOccurrence
	For Each asmOcc  In oAsmCompDef.Occurrences
	
		'get name of occurence only (sees only everything left of the colon)
		Dim oOcc As Object
		oOcc = asmOcc.Name.Split(":")(0)
		
		'look at only virtual components
		If TypeOf asmOcc.Definition Is VirtualComponentDefinition
			'compare name selected from list to the
			'existing virtual parts

msgbox(asmOcc.Name & "=" & oOcc & "=" & sVirtPart)

			If oOcc = sVirtPart Then asmOcc.delete
		End If
	Next
	
	Dim occs As ComponentOccurrences
	occs = asmDoc.ComponentDefinition.Occurrences
	
	Dim identity As Matrix
	identity = ThisApplication.TransientGeometry.CreateMatrix
	
	'create first instance of the virtual part
	Dim virtOcc As ComponentOccurrence
	virtOcc = occs.AddVirtual(sVirtPart, identity)
	iProperties.Value(sVirtPart & ":1", "Project", "Description") = Description
	iProperties.Value(sVirtPart & ":1", "Project", "Part Number") = sVirtPart
	
	For index As Integer = 2 To iQTY
		occs.AddByComponentDefinition(virtOcc.Definition, identity)
	Next

End Function

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes