Notifications
Clear all

[Closed] how I get diference between to arrays?

well i explain easly.

what i want to get is the diference between to arrays, and create a third array with this diference. should be that the equals elements in the two arrays will be removed and create a third array.

Example:

ihave and array like

a = #(1,2,3,4 ,6)

b= #( 1,3)

what i would like is with some kind of funtion get something a -b = c

c=(2,4,6)

in maxcsript i can do easly a+b but not a-b . anyone have asolution

8 Replies

Looking the MAXScript reference, the only overloaded operators for arrays are the index and the addition operator so no trace of the subtract operator.

However, I’ve seen some scripts that made use of the subtract operator but I think they were made with previous versions of MAXScript and for some reason it’s no longer supported in recent versions.

So if you can’t overload operators in MAXScript just like C++ (and I think you can’t), you’ll have to create a function that takes two arrays where one of them will subtract values from the other.

Greets.

yep i looked on maxscript help to and i couldnt find anithing too.

I wilbe greta if someone had a function done already and can share it ;).

i start to think in a function if i finish it i wil put it hear

you could write your own function which compares each element of the arrays and only adds those elements to a new array which are different…

if you are working only with simple arrays like in you example, you could also convert the arrays to bitarrays and then multiplying them, this will give you a new bitarray with the difference which you can convert back to a normal array.

hope this helps!

 PEN

This has been covered twice here in the last month or two, do a search I’m sure you will find some good answers to your questions.

Hello
If the order of your elements does not have any importance you could use this:

a=#(1,2,3,4,6)
b=#(1,3)
theDifference=(a as bitarray - b as bitarray)as array
theIntersection=(a as bitarray * b as bitarray)as array

Cthulhu: like you say

well on my case they are arrays of objects so i should have to write a function to as
Cthulhu said.

thanks paul i wil do a search on the threads an see what i can find;).

thanks prettyPixel for the sample ;).

Maybe this function can help you:

fn diffArray a b =
(
retArray = #()
for element in a do
(
idx = finditem b element
if idx == 0 then
append retArray element
)
return retArray
)

hope this helps…

:buttrock: sweet it works .

thanks for taking the time to write me and example.
Luigi bit by bit im doing my script , missing to have someone near to me like you to ask questions .I have a few nice script already done i starting to love maxscript .
Say hi to all the people in the studio .