THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 07/02/2012 at 08:01, xxxxxxxx wrote:
Thanks for that Yannick.
But I should have mentioned that I needed to be able to select all edges using a list. I'll see if I can use this in my project using lists.
This is all based on a bigger project I'm working on. Where I'm trying to select just one side of the outer edges of "shells" (also known as "islands" ) inside of a polygon. And convert them to splines.
Maya has tools and functions for working with polygon and UV shells and I'm trying to build my own in C4D.
Currently the only way I can do this is to use the ExplodeSegments command. Then select the desired edges on each generated polygon object.
This works ok. (I posted the script on CGTalk) But the problem is I have to generate thousands of objects this way(Ouch!). Just to generate those splines. And that's both very slow and very resource hungry. And frankly a bit of a hack.
So now I'm trying to use lists to try and cut these shells inside the polygon into groups so I can work with them as if they were individual objects. Sort of like using lists in place of a selection tags.
I need to be able to select all edges...But not just simply all edges. All edges per each shell... And not just all edges..But only the edges on one side of all these shells.
It's a rather complex problem.
I posted about it in another thread in the C++ forum.
The source code in the ExplodeSegments command might help me learn how to split up a polygon into groups. I don't even know if my approach is a good one.
This is what I've come up with so far.
It's almost there(it currently only selects the first shell's edges). But then I ran into selection problems:
import c4d
from c4d import utils
def main() :
################## Put polygon shells into an array #####################################
c4d.CallCommand(12187) #Polygons Mode
c4d.CallCommand(13324) #Deselect All polygons--Start from no polygons selected
lastsel = 0
obj = doc.GetActiveObject()
polycount = obj.GetPolygonCount()
selected = obj.GetPolygonS() #The selected polygons
selected.Select(0) #Select the first polygon
c4d.CallCommand(12557) #Select Connected polygons
selectedcount = selected.GetCount()#How many polygons per shell
polygons = c4d.BaseSelect()
polysPerShell = 0 #The number of polygons per shell
polygonlist = [] #The list of shell arrays(contains the individual lists for each shell)
for i in xrange(polycount/selectedcount) :
#print "shells:" ,i
newpolygonlist = [] #This list will be used to hold the selected polygons
for i in xrange(polycount) : #Loop amount = total number of polygons
if selected.IsSelected(i) : #Look for selected polygons
polysPerShell = polysPerShell +1 #The number of polygons per shell
newpolygonlist.append(i)#Fill the list with the selected polygons
lastsel = i #This is the last selected polygon's Id#
polygonlist.append(newpolygonlist)
c4d.StatusSetSpin() #Show the spinning staus bar
c4d.CallCommand(13324) #Deselect All polygons
selected.Select(lastsel+1) #Select the first polygon in the next shell
c4d.CallCommand(12557) #Select Connected polygons
################### Done with loop #################################################
pnts = obj.GetAllPoints()
edges = c4d.BaseSelect()
pntcount = obj.GetPointCount()
nibr = utils.Neighbor() #Assigns neighbor to a variable
nibr.Init(obj) #Instantiates the neighbor class
edgecount = nibr.GetEdgeCount() #Get all the edges in the entire polygon object
#print "total edges:", + edgecount
#print polysPerShell
shellpolylist = []
for i in xrange(len(polygonlist)) : #This gives the number of shells
shells = i
#print shells
for shells in polygonlist: #For each shell of polygons in the "polygonlist" array
#print shells
for j in xrange(0,polysPerShell) : #For each shell element
#print j
selected.Select(j) #Select each element(polygon)
shellpolylist.append(j) #Add each polygon to the list
edges.Select(shellpolylist[1])
edges.Select(shellpolylist[5])
edges.Select(shellpolylist[9])
#print shellpolylist
edges.CopyTo(obj.GetEdgeS())
#Convert selected objects to splines
utils.SendModelingCommand(c4d.MCOMMAND_EDGE_TO_SPLINE, list = [obj], mode = c4d.MODIFY_ALL, bc = c4d.BaseContainer(), doc = doc)
c4d.CallCommand(16351) #Edges
c4d.StatusClear() #Remove the spinning bar..We're done
#print edgelist
c4d.EventAdd()
if __name__=='__main__':
main()
I'm not sure if I'm on the right track or not.
I'm in a little bit over my head. And just looking for advice on doing this.
Not really a support issue. Just wanted to let you see what I was trying to do in the bigger picture.
-ScottA