Python tag refresh editor selection
-
On 08/10/2014 at 04:19, xxxxxxxx wrote:
Hallo,
in this script ( c4d file https://www.hidrive.strato.com/share/mvm9t4h3vi#$/) i want to deselect a number of selected polygons but the editor is not refreshed.
import c4d
#Welcome to the world of Pythonchanged=0 # glabal variable
def main() :
# global changed # must be defined in function as global
# null=op.GetObject() # object of python tag
print " "
obj=doc.GetActiveObject()
if not (obj==None) :
print "selected object =",obj.GetName(), obj.GetTypeName()
if (obj.CheckType(c4d.Opolygon)) :
n=obj.GetPolygonCount()
sel=obj.GetPolygonS()
nsel=sel.GetCount()
nth=op[c4d.ID_USERDATA,1]
print "number of selected polygons:",n,nsel,nth
if (nsel>3) :
for i in range(0,nsel) :
if (i % nth==0) :
sel.Deselect(i)
print i,"deselected"
# here i want to refresh the editor
# c4dtools.utils.update_editor() # nothing happens
# obj.Message(c4d.MSG_UPDATE) # nothing happens
# c4d.EventAdd(); # endless loop calling this function
returnI have googleing one day without any result. Please excuse me its my first posting in forums.
Thanks Udo Welz
-
On 08/10/2014 at 08:24, xxxxxxxx wrote:
Welcome.
Try it like this:
import c4d def main() : #The object the tag is on obj = op.GetObject() if not obj: return False totalpolys = obj.GetPolygonCount() PolyS = obj.GetPolygonS() #If the user selects 4 or more polygons #The code below will automatically de-select every other polygon if PolyS.GetCount() > 3: #We will De-Select every other polygon #Change this variable. Or use a UserData gizmo to change it nth = 2 #First this code selects all of the polygons #Then it de-selects every other one for poly in xrange(totalpolys) : PolyS.Select(poly) if poly % nth==0: PolyS.Deselect(poly)
-ScottA
-
On 09/10/2014 at 04:12, xxxxxxxx wrote:
Thank you ScottA.
It's my first test in programming cinema. My goal is to select a bunch of polygons in editor e.g. like the loop selection on sphere. Then run the script to deselect nth polygon. Then i want to continue modelling with this selection in editor. I thought that sel is an array or so and the loop index e.g. 2 selected the 2.th selected polygon but it's only selecting the 2.th polygon of all polygons wich was not select. Sorry for my english. I am german and speaking or writting is not so good. Your suggestion was very helpful.
Udo
-
On 09/10/2014 at 05:10, xxxxxxxx wrote:
I've solved this problem by doing this
import c4d
import new
#Welcome to the world of Pythonchanged=0 # glabal variable
def main() :
# global changed # must be defined in function as global
# null=op.GetObject() # object of python tag
if (op!=doc.GetActiveTag()) : return
print " "
obj=doc.GetActiveObject()
if not (obj==None) :
print "selected object =",obj.GetName(), obj.GetTypeName()
if (obj.CheckType(c4d.Opolygon)) :
n=obj.GetPolygonCount()
sel=obj.GetPolygonS()
nsel=sel.GetCount()
nth=op[c4d.ID_USERDATA,1]
print "number of selected polygons:",n,nsel,nth
if (nsel>3) :
j=0
for i in xrange(n) :
if (sel.IsSelected(i)) :
if (j % nth==0) :
sel.Toggle(i)
print i,"deselected"
j+=1Thank you ScottA for help