Do selection from iLogic

<?xml encoding=”UTF-8″>By Adam Nagy

The only way you can do a selection from iLogic is using the Pick function. However, you can keep calling that in a loop to enable the user to select multiple components as well. Then you can do something with the selected components – in this specific case, we’ll delete them:

Dim comps As ObjectCollection
Dim comp As Object
comps = ThisApplication.TransientObjects.CreateObjectCollection
While True
comp = ThisApplication.CommandManager.Pick(
SelectionFilterEnum.kAssemblyOccurrenceFilter,
"Select a component")
' If nothing gets selected then we're done
If IsNothing(comp) Then Exit While
comps.Add(comp)
End While
' If there are selected components we can do something
For Each comp In comps
comp.Delete()
Next

Comments

13 responses to “Do selection from iLogic”

  1. So how do you escape the loop? Escape key?

  2. Hi Matt,
    Yes, escape key.
    Cheers,
    Adam

  3. Is there any way to use some other key or right mouse button to break from the loop? Many of my coworkers are Escape button mashers so: 1. Escape will seem like an odd button to press to continue the program and 2. they never press the escape button only once.
    By the way, thanks for this bit of code. I am slowly transitioning my code from iLogic to .NET, but I am not quite to the point of making the leap yet.

  4. That seems to be the only way. I think you cannot use the InteractionEvents from iLogic so pick would be the only one and that only seems to stop on ESC key press.
    Doing it from an AddIn will be the best way to do sophisticated selection. :)

  5. Sorry to bother you again, but any idea if, through iLogic, you can use some other key to escape the loop?
    Thanks!

  6. Sorry, posted that last reply before doing a hard refresh on this page. Thanks for the response!

  7. Adrie-Piet Avatar
    Adrie-Piet

    Can we also select items from subassemblies?
    With the rule above, we select the subassembly itself..

  8. If you check the possible SelectionFilterEnum values, one of them is kAssemblyLeafOccurrenceFilter, and I think that’s what you’d need.

  9. Andrew Starnes Avatar
    Andrew Starnes

    Exactly what I needed! Is there a way to leave the components that have been added to the list remain highlighted? I have a rule that creates/activates a view rep and overrides their color to my choosing and it would be nice to see the parts that have already been selected since I’m selecting 10-20 at a time.

  10. Hi Andrew,
    Not sure if I understood you correctly, but maybe this could help:
    http://adndevblog.typepad.com/manufacturing/2016/01/keep-selection-between-rule-executions.html
    Cheers,
    Adam

  11. Hello,
    thanks for the post, it is very helpful!
    I was wondering if it’s possible to check if there are two identical objects in the object collection or maybe avoid the selection of an already existing object.
    I am using this rule in an assembly and I was trying to avoid having two identical parts in the collection.
    Thank you again,

  12. Hi Claudia,
    You could just ignore those components from the selection. You could keep track of all the ComponentDefinition objects and if a ComponentOccurrence already had that Definition then you could ignore it.
    If you also want to unhighlight the component that might be tricky – as far as I remember iLogic was not good at updating the UI in that case. So for that using highlight set might be better: http://adndevblog.typepad.com/manufacturing/2016/01/keep-selection-between-rule-executions.html
    Cheers,

  13. Hi Adam,
    is it possible to use your code to select browsernodes in a drawing?
    What filter can I use?

Leave a Reply to ClaudiaCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading