• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    Autodesk Inventor

    Reply
    Valued Contributor
    Posts: 94
    Registered: ‎09-10-2012
    Accepted Solution

    ilogic - FOR every entry from a list

    349 Views, 3 Replies
    12-11-2012 06:45 AM

    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

     

    Wayne Helley
    Inventor 2013 Certified Professional

    Autodesk Inventor Professional 2011
    Windows 7 Enterprise, 64-bit
    Please use plain text.
    *Expert Elite*
    Curtis_Waguespack
    Posts: 1,933
    Registered: ‎03-08-2006

    Re: ilogic - FOR every entry from a list

    12-11-2012 11:56 AM in reply to: waynehelley

    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



      solution.png  Did you find this reply helpful ? If so please use the Accept as Solution or  Kudos button below.

    Please use plain text.
    Valued Contributor
    Posts: 94
    Registered: ‎09-10-2012

    Re: ilogic - FOR every entry from a list

    12-12-2012 12:47 AM in reply to: Curtis_Waguespack

    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/autodesk-ilogic-highlight-and-update.html)

     

    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... 

     

    ------------------------------------------------------------------------------------------------------------------------------------------

     

    Feature.Color("Hole1") = "Red"
    Dia1= InputBox("Enter Diameter of " & "Hole1", "iLogic Hole Diameter", Dia1)
    Feature.Color("Hole1") = "As Part"
    RuleParametersOutput()
    iLogicVb.UpdateWhenDone = True
     
    'set the feature color to red and then prompts the user for input
    'then pushes the parameter change to the part and updates before moving on
    Feature.Color("Hole2") = "Red"
    Dia2= InputBox("Enter Diameter of " & "Hole2", "iLogic Hole Diameter", Dia2)
    Feature.Color("Hole2") = "As Part"
    RuleParametersOutput()
    iLogicVb.UpdateWhenDone = True
     
    'set the feature color to red and then prompts the user for input
    'then pushes the parameter change to the part and updates before moving on
    Feature.Color("Hole3") = "Red"
    Dia3= InputBox("Enter Diameter of " & "Hole3", "iLogic Hole Diameter", Dia3)
    Feature.Color("Hole3") = "As Part"
    RuleParametersOutput()
    iLogicVb.UpdateWhenDone = True
     
    ---------------------------------------------------------------------------------------------------------------------------
     
    I want to replace this with something like...
     
    ---------------------------------------------------------------------------------------------------------------------------
     
    create a list called "feature" containing "HOLE1", "HOLE2" and "HOLE3"
     
    FOR each value within the list
     
    Feature.Color("feature") = "Red"
    Dia3= InputBox("Enter Diameter of " & "feature", "iLogic Hole Diameter", Dia3)
    Feature.Color("feature") = "As Part"
    RuleParametersOutput()
    iLogicVb.UpdateWhenDone = True
     
    Next
     
    ----------------------------------------------------------------------------------------------------------------------------
     
    I hope this makes a bit more sense. Your textbook and blog have been incredibly helpful in making the most out of Inventor so I would just like to say thankyou very much.
     
    Wayne
     
     
    Wayne Helley
    Inventor 2013 Certified Professional

    Autodesk Inventor Professional 2011
    Windows 7 Enterprise, 64-bit
    Please use plain text.
    Valued Contributor
    Posts: 94
    Registered: ‎09-10-2012

    Re: ilogic - FOR every entry from a list

    12-12-2012 02:43 AM in reply to: Curtis_Waguespack

    I think I have worked it out for myself using your second example.

     

    Thanks for your help.

     

    Wayne

    Wayne Helley
    Inventor 2013 Certified Professional

    Autodesk Inventor Professional 2011
    Windows 7 Enterprise, 64-bit
    Please use plain text.