[Closed] finding all elements of a polyObject
I searched for the solution, but all I found is that we have to use the polyop.getElementsUsingFace() function.
but how??
I tried to store all the elements into an array:
currentElement = #()
elementsArr = #(currentElement)
for i = 1 to $.getNumFaces() do(
currentElement = (polyop.getElementsUsingFace $ i as array)
-- print currentElement
for o = 1 to elementsArr.count do(
if (findItem elementsArr[o] currentElement) == 0 then(
append elementsArr currentElement
)
else(
exit
)
)
)
this runns an endless loop…
strange things for me I remarked are, that if you enable the “print currentElement”, it doesn’t print an array. only a number. doing this afterwards it prints an array.
I also tried to add a loop that runs trough each item in the currentElement, so finditem searches for a variable, not an array, but somehow this ended up again in an endless loop, but didn’t do what I want.
I hope somebody can help with that.
tnx
lol…sometimes it just happens that 5 min after posting a question, a light goes up and you see the solution.
well this happened right now
currentElement = #()
elementsArr = #(currentElement)
doAdd = false
for i = 1 to $.getNumFaces() do(
currentElement = ((polyop.getElementsUsingFace $ i) as array)
for o = 1 to elementsArr.count do(
if (findItem elementsArr[o] currentElement[1]) == 0 then(
doAdd = true
)
else(
doAdd = false
exit
)
)
if doAdd == true do(
append elementsArr currentElement
)
)
deleteItem elementsArr 1
elementsArr
the problem was that it appended the currentElement in the loop, so multiple times, and trough that it somehow extended the loop for each face again…causing a slowdown and very long loop
Here’s another approach using a bitArray, which is perfect for stuff like this:
(
-- Array to store elements
local Elements = #()
-- Array containing all face indices
local Faces = #{1..$.numFaces} as array
-- Loop until nothing left in 'Faces' array
while Faces.count > 0 do
(
-- Get the element using the first face in the 'Faces' array
local FaceElem = polyOp.getElementsUsingFace $ Faces[1]
-- Subtract the element from the 'Faces' array
Faces = ((Faces as bitArray) - FaceElem) as array
-- Append the elements
append Elements FaceElem
)
-- 'Elements' now contains an array of bitarrays
Elements
)
Cheers,
Martijn