Autodesk Inventor
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
ilogic - FOR every entry from a list
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi there, I have a section of code (see below) which runs a program which highlights a part/subassembly red, then gives the user a list dialgue box in order to easily replace the compent. At present, I have this code repeated for each part/subassembly in my main assemby (i.e. FRAME, POWER_RISER, BUSBAR_CHAMBER, BUSBAR_ASSEMBLY...).
Having the code repeated multiple times, means it is very time consuming to modify. I want to be able to generate a list then have the code below, run for each of the entries in the list. So I need something along the lines of
dim mylist as something
mylist = FRAME, POWER_RISER, BUSBAR_CHAMBER, BUSBAR_ASSEMBLY...
FOR each entry in mylist
run all the code below (with the words 'BUSBAR_ASSEMBLY' replaced with 'mylist'
END
Could someone give me some help with the code writting please?
Thanks,
Wayne
Component.Color("BUSBAR_ASSEMBLY")="Red(FLAT)"Parameter("busbar_assembly_partno")=InputListBox("Please select the part number of the busbar assembly you wish to use", MultiValue.List("busbar_assembly_partno"), MultiValue.List("busbar_assembly_partno"), Title :="Assembly Editor", ListName :="Busbar Assembly")Component.Color("BUSBAR_ASSEMBLY")="As Material"iPart.ChangeRow("BUSBAR_ASSEMBLY", Parameter("busbar_assembly_partno"))'Component.Replace("BUSBAR_ASSEMBLY","C:\ARTICULATE\09\090\09090GT0000023\" & Parameter("busbar_assembly_partno") & ".iam", True)iLogicVb.UpdateWhenDone=True
'Check to see if the part has changed. If it hasn't, check to see if it exists.IfParameter("busbar_assembly_partno")<>iProperties.Value("BUSBAR_ASSEMBLY", "Project", "Part Number")IfDir("C:\ARTICULATE\09\090\09090GT0000023\"&Parameter("busbar_assembly_partno")&".iam")=""ThenMessageBox.Show("The busbar assembly, "&Parameter("busbar_assembly_partno")&", does not exist locally. Please GET the part from Vault (you don't need to check it out) then click 'OK'", "Assembly Editor", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1)iPart.ChangeRow("BUSBAR_ASSEMBLY", Parameter("busbar_assembly_partno"))MessageBox.Show("Now please Check , "&Parameter("busbar_assembly_partno")&", back in", "Assembly Editor", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1)EndIfEndIf
'Check to see of the part has changed. If it hasn't, prompt to check it out of vault.IfParameter("busbar_assembly_partno")<>iProperties.Value("BUSBAR_ASSEMBLY", "Project", "Part Number")MessageBox.Show("The busbar assembly could not be changed to "&Parameter("busbar_assembly_partno")&". Make sure you have the latest version of the file and all it's children from Vault then click 'OK'", "Assembly Editor", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1)iPart.ChangeRow("BUSBAR_ASSEMBLY", Parameter("busbar_assembly_partno"))EndIf
'Check to see of the part has changed. IfParameter("busbar_assembly_partno")<>iProperties.Value("BUSBAR_ASSEMBLY", "Project", "Part Number")MessageBox.Show("The busbar assembly could still not be changed to "&Parameter("busbar_assembly_partno")&". iAssemblies are jerks", "Assembly Editor", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1)EndIf
Inventor 2013 Certified Professional
Autodesk Inventor Professional 2011
Windows 7 Enterprise, 64-bit
Solved! Go to Solution.
Re: ilogic - FOR every entry from a list
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi waynehelley,
I didn't follow your exact goal here (your code did not paste too well), but here are a couple of examples that might help.
Here's a quick example checking a list against a string:
testString = "Hello World I am a text string."
'create list
Dim myArrayList As New ArrayList
myArrayList.add("Hello")
myArrayList.add("World")
myArrayList.add("Roadrunner")
Dim oString as Object
i = 0
For Each oString in myArrayList
If testString.Contains(myArrayList.Item(i)) Then
MessageBox.Show(myArrayList.Item(i) & ": was found!", "iLogic")
Else
MessageBox.Show(myArrayList.Item(i) & ": was NOT found.", "iLogic")
End if
i= i+1
Next
Here's a quick example that creates a list from the assembly components and then presents them in a listbox:
' set a reference to the assembly component definintion.
' This assumes an assembly document is open.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
'create a list
Dim myArrayList As New ArrayList
'Iterate through all of the assembly occurrences
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences
'add the occurrence name to the list
myArrayList.add(oOccurrence.Name)
Next
'present the user with the list to choose from
myComponent = InputListBox("Select one.", myArrayList, myArrayList.item(0), "iLogic", "List")
'report the selection
MessageBox.Show("You selected: " & myComponent & vblf & " from the list.", "iLogic") I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
Re: ilogic - FOR every entry from a list
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi Curtis, thanks for the reply. I will explain a bit better.
I started with your blog post about using ilogic to highlight and Update Features During Changes (http://inventortrenches.blogspot.co.uk/2011/02/aut
I modified the code so that instead of highlighting features in a part and being given the option to alter the dimension, the code highlights subassemblies within an assembly then gives the user a list of subassemblies to replace the current subassembly. I have this code working fine (it is attached if you want to take a look, although i have shortened it so it only concentrates on one subassembly replace in my main assembly, whereas I want it to go through each of the sub-assemblies one by one).
If you look at your code below, you have just copied it 3 times replacing the feature name. My code is longer (as i want error messages to appear if the replace has not worked) and i want it to be repeated many times as there is going to be many sub assemblies going into my main assembly. This makes it very difficult to modify the code as every time I want to make a change, I have to change the code for each subassembly.
To overcome this i want to make a list then have a FOR function run a few lines of code for each of the entries in the list. Below is the code from your blog post...
--------------------------------------------------
Inventor 2013 Certified Professional
Autodesk Inventor Professional 2011
Windows 7 Enterprise, 64-bit
Re: ilogic - FOR every entry from a list
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
I think I have worked it out for myself using your second example.
Thanks for your help.
Wayne
Inventor 2013 Certified Professional
Autodesk Inventor Professional 2011
Windows 7 Enterprise, 64-bit

