PDA

View Full Version : hmmm.....there should be a better way ?


Technofreak
04-08-2004, 09:38 PM
this is what I got so far.......


fn bitarray2array bitarray_ = -- converts a bitarray to a normal array
(
local outgoing = for BA in bitarray_ collect BA
)
vertSel = bitarray2array (polyop.getVertSelection $);
for v in vertSel do
(
select $.verts[v];
nVerts = polyop.getfacesusingvert $ v as string;
print nVerts;

if findstring nVerts "." == undefined then
(
macros.run "Editable Polygon Object" "EPoly_Remove";
)
)

-- Runtime error: EPoly vertex index out of range: < 1 or > 113: 114

what am I missing here? or is there a better way on doing this? basically what I want is to check whether the vertices is connected to 2 edges and if it does then delete that vertex.

Thanks All (especially Bobo)

Reality3D
04-08-2004, 10:05 PM
Just use conversion between types to transform a Bitarray to a normal array
a=#{1..5}
b=a as array

Technofreak
04-08-2004, 10:24 PM
i'll try it now.....

Bobo
04-09-2004, 12:46 AM
There are lots of things to say about this.
Could you please explain what exactly the script should do?
Why do you check for neighbour FACES when you say you want to check 2 edges?

But the reason it is crashing is that you are counting from 1 to the end of the array.

You should be counting backwards to avoid the crash.
What happens is: let's say you have an array of the letters
someArray = #("A","B","C","D") and you want to delete elements 2 and 4. You delete element 2 and get
someArray = #("A","C","D")
Now you try to delete element 4, but there are only 3 left!
So you get the error you already know!

If you delete backwards, you get
someArray = #("A","B","C") after deleting element 4,
but element 2 is still there so you finish with someArray = #("A","C")...


The code you have would look like

--get the selection as array
vertSel = (polyop.getVertSelection $) as array
--count backwards:
for i = vertSel.count to 1 by -1 do
(
v = vertSel[ i ] -- get the i-th element of the array
select $.verts[v] --select the vertex
--no idea what are you doing from this point on... :o)
nVerts = (polyop.getfacesusingvert $ v) as string
print nVerts
if findstring nVerts "." == undefined then
(
macros.run "Editable Polygon Object" "EPoly_Remove";
)
)

but I don't think it does what you want it to,

Cheers,

Bobo


Originally posted by Technofreak

-- Runtime error: EPoly vertex index out of range: < 1 or > 113: 114

what am I missing here? or is there a better way on doing this? basically what I want is to check whether the vertices is connected to 2 edges and if it does then delete that vertex.

Thanks All (especially Bobo)

Bobo
04-09-2004, 12:57 AM
Originally posted by Bobo

--no idea what are you doing from this point on... :o)



Ok, looking at your explanation, you want to remove any vertices that have exactly two edges connected? Like the corners of an EPoly plane?

Here is your code with a slight change that does that:

vertSel = (polyop.getVertSelection $) as array
for i = vertSel.count to 1 by -1 do
(
v = vertSel[i]
select $.verts[v]
nVerts = (polyop.getedgesusingvert $ v) as array
if nVerts.count == 2 do
$.EditablePoly.buttonOp #Remove
)

Cheers,

Bobo

Technofreak
04-09-2004, 01:19 AM
:bowdown: :bowdown: :bowdown:

thanks Bobo

CGTalk Moderation
01-18-2006, 12:00 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.