PDA

View Full Version : Delete polys that are too close


displaced
04-29-2008, 03:53 PM
Hi,

im trying to write a script that will delete polys that are within a pre determined distance of each other

so far i can get the locations of the polys into an array and then work out the distance between the polys.

but im having trouble with the latter array.

I realized that i would have to work out the distance between every poly in the object and not just the next one along as there is no saying that the polys will be arranged in a sequential order, this is where i started to hit probelms.

so.....

i need to be able to work out the location of every poly and then calculate the distance that poly is from every other poly and the select polys that are below or equal to a pre defined value.

so here is what i have so far.



macroScript deletenearbypolys

(

Global distancearray = #()
Global facearray = #()
Global facecount
Global distancevalue = 0
Global selectionface = #()
Global Facenum


rollout deletepolys "Delete Polys" width:227 height:161
(


-- ROLLOUT FUNCTIONS --------------------------------------------
bitmap bmp1 "Bitmap" pos:[5,6] width:217 height:45
spinner spn_distance "Distance" pos:[33,73] width:156 height:16
groupBox grp1 "" pos:[5,51] width:216 height:102
button dist_select "select" pos:[21,108] width:73 height:29
button dist_delete "delete" pos:[122,108] width:73 height:29
---------------------------------------------------------------------------



--WORKINGS--------------------------------------------------------------
on spn_distance changed spn_amunt do (distancevalue = spn_amunt)


on dist_select pressed do
(

facecount = polyop.getnumfaces $

for f = 1 to facecount do
(
loc = polyop.getFaceCenter $ f
faceNum = f as string
print "face #:" + faceNum
print loc
append faceArray loc
)


print facearray


for f = 1 to facecount do
(
for g = f+1 to facecount do
(append distancearray ( distance facearray[f] facearray[g]))

)

)



)



createDialog deletepolys pos:[100,130] style:#(#style_minimizebox, #style_titlebar, #style_sysmenu)

)





Hope this makes sense

cheers Colin

MoonDoggie
04-29-2008, 06:00 PM
for f = 1 to facecount do
(
for g = f+1 to facecount do
(append distancearray ( distance facearray[f] facearray[g]))

)


This doesn't make sense at all, because if it's on f = 3 face 3, then g will start at 4 and completely miss 1 and 2...

Also you can consolodate these two loops into one


for f = 1 to facecount do
(
loc = polyop.getFaceCenter $ f
faceNum = f as string
print "face #:" + faceNum
print loc
append faceArray loc

-- You now need to loop through all the other faces and store the distance
for g = 1 to facecount where g != f do
append distancearray (distance faceArray[f] faceArray[g])
)
print distanceArray





Should get you started,
Colin

displaced
04-30-2008, 09:41 AM
Cheers Moondoggie

that made more sense to me know......

so here is where i've got to



(

Global distancearray = #()
Global facearray = #()
Global facecount
Global distancevalue = 0
Global selectionface = #()
Global Facenum
Global Selectface = #()


rollout deletepolys "Delete Polys" width:227 height:161
(


-- ROLLOUT FUNCTIONS --------------------------------------------
bitmap bmp1 "Bitmap" pos:[5,6] width:217 height:45
spinner spn_distance "Distance" pos:[33,73] width:156 height:16
groupBox grp1 "" pos:[5,51] width:216 height:102
button dist_select "select" pos:[21,108] width:73 height:29
button dist_delete "delete" pos:[122,108] width:73 height:29
---------------------------------------------------------------------------



--WORKINGS--------------------------------------------------------------
on spn_distance changed spn_amunt do (distancevalue = spn_amunt)


on dist_select pressed do
(

facecount = polyop.getnumfaces $
facearray = #()
distancearray = #()
selectface = #()

for f = 1 to facecount do
(
loc = polyop.getFaceCenter $ f
faceNum = f as string
print "face #:" + faceNum
print loc
append faceArray loc
)
for f = 1 to facecount do
(
for g = 1 to facecount where g != f do
(
append distancearray (distance faceArray[f] faceArray[g])

)
)
print distanceArray

for h = 1 to distancearray.count do
(
if distancearray[h] < distancevalue then (append selectface h)
)
print selectface
)
)



createDialog deletepolys pos:[100,130] style:#(#style_minimizebox, #style_titlebar, #style_sysmenu)

)




now this does exactly what i thought i wanted it do to.....

I get back a series of numbers which relate to the distances that are below my pre determined value.....

the problem is now how to get the original poly number from the these values.....

and also if two polys are a set distance apart both will be highlighted as they are both the same distance from each other and below this pre determined value, but i only want to select one of these polys as deleting both would be pointless.

this is where its confusing me.....as im not sure how to code the selection of just one of these polys......

Cheers

MoonDoggie
04-30-2008, 03:42 PM
I understand, I just had that problem too with a script of mine. What I did was store the original face in the first member of an array

local faceArray = #()
faceArray[1] = theOriginalFace


then when I added faces to the array I appended them to 'faceArray', when I went to delete them, I never deleted the first member of the faceArray (the original face).

This obviously won't work if you allow multiple face selections, so you could easily separate out the arrays for the original faceSelection array (all the faces they have selected to iterate over) and the faceArray which only stores the values gathered from checking distances, and always just delete faceArray.

Hope that helps,
Colin

displaced
05-02-2008, 12:36 AM
Cheers Again..


thats a good idea. I'll have a stab at that, and i'll post my results.

MoonDoggie
05-02-2008, 03:19 PM
All good men named Colin.

CGTalk Moderation
05-02-2008, 03:19 PM
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.