- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm trying to piece a rule together that would number my placed subassemblies correctly. I have a rule where, depending on a user parameter I can change, subassemblies get added or removed if I want less. The specifics about that are not all that important I assume because it works perfectly. It works but the problem is that the number it puts behind the placed components keeps adding up with each add/remove.
There are always three parts present on each side, no matter the parameter. So one of each: 1.1, 1.2 and 1.3. And its mirror too. The 1.2 part is the one that gets added depending on the user parameter.
So I've only been using iLogic since september. I was trying to write a rule that would correctly number the components but I keep getting an error and I can't help but think I'm really screwing up here. This the rule. Inventor 22/Windows. The error also doesn't say anything useful.
Dim oAsmDoc As AssemblyDocument oAsmDoc = ThisApplication.ActiveDocument Dim oAsmDef As AssemblyComponentDefinition oAsmDef = oAsmDoc.ComponentDefinition Dim oOcc As ComponentOccurrence Dim i As Integer = 1 For Each oOcc In oAsmDef.Occurrences If oOcc.Type = ObjectTypeEnum.kComponentOccurrenceObject oOcc.Name = "99991000 - CBC - Zijwang 1.2_Weld" & ":" & i i = i + 1 End If Next
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @alikhan.ganayev. Actually, that second error message is telling us that the error is happening at the point we are attempting to set a new name to a ComponentOccurrence, so that is at least something. The most likely reason that this is failing, is that the name you are attempting to assign to the component is already being used by another component, and it won't allow two components to be named identically. So basically, it starts processing those components at the start, but there may be a component later in the list that already has the name you are trying to assign to a component earlier in the list. Does that make sense to you?
Oh...and another thing that may help this process make more sense is that when using a For Each loop like that, it will most likely start processing those items within, starting with the ones which were first 'placed' into the assembly, not necessarily in alphabetical order by their names. It's the same as when using the For I = 1 To oCount, then using Item(I) within...the Item index is generally determined by which ones in the group existed first, to which ones came into existence last.
Wesley Crihfield
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
First of all I'd like to apologize for the late reply as I was already home and didn't have access to the computer I was working with. Thank you very much for the help. I did understand your explanation and the logic I used was flawed. My code would rename all components it found instead of just the necessary ones and this would conflict. Keeping your advice in mind I have altered my code and it seems to be working correctly now. This is the working version below, one for the original piece and the other one for the mirrored version.
Dim oAsmDoc As AssemblyDocument oAsmDoc = ThisApplication.ActiveDocument Dim oAsmDef As AssemblyComponentDefinition oAsmDef = oAsmDoc.ComponentDefinition Dim oOcc As ComponentOccurrence Dim i As Integer = 1 For Each oOcc In oAsmDef.Occurrences If oOcc.Type = ObjectTypeEnum.kComponentOccurrenceObject AndAlso oOcc.Name.StartsWith("99991000 - CBC - Zijwang 1.2_Weld:") oOcc.Name = "99991000 - CBC - Zijwang 1.2_Weld" & ":" & i i = i + 1 End If Next
And the MIR
Dim oAsmDoc As AssemblyDocument oAsmDoc = ThisApplication.ActiveDocument Dim oAsmDef As AssemblyComponentDefinition oAsmDef = oAsmDoc.ComponentDefinition Dim oOcc As ComponentOccurrence Dim i As Integer = 1 For Each oOcc In oAsmDef.Occurrences If oOcc.Type = ObjectTypeEnum.kComponentOccurrenceObject AndAlso oOcc.Name.StartsWith("99991000 - CBC - Zijwang 1.2_Weld_MIR") oOcc.Name = "99991000 - CBC - Zijwang 1.2_Weld_MIR" & ":" & i i = i + 1 End If Next
This numbers the components correctly.