Inventor Engineer-to-Order

Inventor Engineer-to-Order

Reply
Mentor
bsee1
Posts: 212
Registered: ‎11-14-2011
Message 1 of 6 (379 Views)
Accepted Solution

How to remove a list from another list?

379 Views, 5 Replies
07-10-2012 05:44 AM

I have 2 lists.  Each may have multiple occurrances of the same item.  How can I remove one list from another list?

 

For example bigList = {b,b,c,a,c,c,a}

smallList = {b,b,a}

 

I'd like it to return something like {c,c,c,a}

I've tried setDifference, and it almost does what I need. But it removes ALL occurrences of an item, which is a problem.  Preserving order doesn't matter because I'm planning to sort after this.  Ideally it would be rather efficient because each list will have about 20 items, and I'll have to run it about 1000 times.

*****************************
Win7 x64 - 16gb ram
i7 3610qm
FirePro M4000

Inventor 2013
ETO 6.1

Edit: I found it was easier to do in ETO than make a whole new .NET function

 

For anyone else that has this problem, here's what I came up with.  If your goal is to remove a smaller list of items from a larger list, you can loop through each element of the small list and remove one item at a time from the bigger list.  

 

The code is attached as a text file. When it is done, the filteredItems rule will contain all elements from the big list, with the items in the small list removed.  It is built to accept multiples of values.  For example, if the big list contains 3 of an item, and the small list contains 2 of that item, only 2 of the 3 values will be removed from the bigger list.

 

 

Employee
JackGregory
Posts: 200
Registered: ‎03-06-2006
Message 2 of 6 (369 Views)

Re: How to remove a list from another list?

07-10-2012 10:37 AM in reply to: bsee1

We don't have a function for this that I can recall.  The "Set" functions operate essentially as if duplicates can be ignored; the focus is on whether something is in the set or not. 

 

The only solution I can think of is to write a function that iterates over the items in the to-be-removed set, and use position and sublist to find and extract matching items.  But this would not be very efficient.

 

If the lists are big enough, then writing a .Net function and calling it from Intent would be more efficient.

 

It seems like a function removeNth would be a big help here, but I don't recall anyone ever asking for it.

Mentor
bsee1
Posts: 212
Registered: ‎11-14-2011
Message 3 of 6 (367 Views)

Re: How to remove a list from another list?

07-10-2012 11:05 AM in reply to: JackGregory

Ah. I've been looking for a feature like removeNth() for a few months now (no, I haven't asked until now), but I've always found a workaround.

 

 In .NET what I need to do would be very simple, I'd just use linq.  I'm happy to write a .net function, but how involved is that?  Will the .net function work if I try using this project on ETO server?  I imagine I need a dll, where does it go?  

 

I'll have it working by the time ETO SP1 is released, but it would be really nice if someone would add a removeNth() function. In fact, it would be even nicer if it was introduced as a hotfix long before SP1.

*****************************
Win7 x64 - 16gb ram
i7 3610qm
FirePro M4000

Inventor 2013
ETO 6.1
Employee
JackGregory
Posts: 200
Registered: ‎03-06-2006
Message 4 of 6 (363 Views)

Re: How to remove a list from another list?

07-10-2012 11:38 AM in reply to: bsee1

.Net assemblies will get found if they are in the Intent search path.  Generally speaking, if you have an IKS file that references a .Net assembly, you should put the dll in the same place for it to find it when it is demanded.

 

There are a few quirks to directly calling .Net, the most immediately apparent is that you must fully-specify names.  There is no "using" statement.  If you have .Net questions, use a separate thread for them.

 

There is no SP1 or hot fix planned right now.  That doesn't mean there won't be any, just that we don't have any date or anything like that.  The next release is planned for later this year.

Mentor
bsee1
Posts: 212
Registered: ‎11-14-2011
Message 5 of 6 (348 Views)

Re: How to remove a list from another list?

07-12-2012 06:34 AM in reply to: JackGregory

Edit: I found it was easier to do in ETO than make a whole new .NET function

 

For anyone else that has this problem, here's what I came up with.  If your goal is to remove a smaller list of items from a larger list, you can loop through each element of the small list and remove one item at a time from the bigger list.  

 

The code is attached as a text file. When it is done, the filteredItems rule will contain all elements from the big list, with the items in the small list removed.  It is built to accept multiples of values.  For example, if the big list contains 3 of an item, and the small list contains 2 of that item, only 2 of the 3 values will be removed from the bigger list.

 

 

*****************************
Win7 x64 - 16gb ram
i7 3610qm
FirePro M4000

Inventor 2013
ETO 6.1
Employee
venkatt
Posts: 13
Registered: ‎10-31-2007
Message 6 of 6 (275 Views)

Re: How to remove a list from another list?

08-09-2012 09:09 AM in reply to: bsee1

I realize the topic of this discussion is not searching for patterns in a list, but if you'd like to do something like this:

 

Dim InputList As List={"d","a","b","c","a","b","c","a","b","c","a","b","c","a","c"}

Dim PatternList As List={"a","b","c"}

 

Then searching the InputList for PatternList gives these positions where a match occurs:2, 5, 8, 11.

 

A simple but inefficient way traverses all items in InputList and for each item, checks if a pattern match occurs starting from the position of that item - this takes length(InputList) * length(PatternList) time (please see attached PatternMatch_Inefficient.txt for example).

 

A more efficient way uses a failure function for each pattern position so that the search can happen in length(InputList) + length(PatternList) time (please see attached PatternMatch.txt for example).

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.

Announcements
Manufacturing Community
The Manufacturing Community provides additional access to tips, tutorials, blogs and networking with peers.