César Vonc
23/04/2012, 23h33
http://code.vonc.fr/details/s19-00.png
v1.1
Voici un script Python sélectionnant tous les polygones ayant la même orientation que le polygone sélectionné.
Avec une valeur de tolérance pour une utilisation plus souple !
http://code.vonc.fr/details/s19-01.png
import c4d
import math
from c4d import gui, Vector
from c4d.utils import GetAngle
from math import isnan
# César Vonc - v 1.1
class Dialogue(gui.GeDialog) :
annuler = True
tolerance = 0
def CreateLayout(self) :
self.GroupBegin(10, c4d.BFH_SCALEFIT, 1, 2)
self.AddEditNumberArrows(11, c4d.BFH_SCALEFIT)
self.AddButton(12, c4d.BFH_SCALEFIT, initw = 100, inith = 20, name = "Valider")
self.GroupEnd()
return True
def InitValues(self) :
self.SetTitle("Tolérance")
self.SetDegree(11, 0)
return True
def Command(self, id, msg) :
if id == 12 :
self.annuler = False
self.tolerance = self.GetReal(11)
self.Close()
return True
def recup_norm(index) :
poly = op.GetPolygon(index)
pA = op.GetPoint(poly.a)
pB = op.GetPoint(poly.b)
pC = op.GetPoint(poly.c)
pD = op.GetPoint(poly.d)
normale = (pA - pC).Cross(pB - pD)
normale.Normalize()
return normale
def verif(va, vb, tol) :
angle = GetAngle(va, vb)
if isnan(angle) : return True
if tol >= angle : return True
else : return False
def main() :
if not op : return
if op.GetType() != c4d.Opolygon : return
bs = op.GetPolygonS()
nbsel = bs.GetCount()
if nbsel == 0 : return
dial = Dialogue()
dial.Open(c4d.DLG_TYPE_MODAL)
if dial.annuler is True : return
nbpol = op.GetPolygonCount()
normale_ref = Vector(0, 0, 0)
doc.StartUndo()
doc.AddUndo(c4d.UNDOTYPE_CHANGE_SELECTION, op)
for index, selec in enumerate(bs.GetAll(nbpol)) :
if not selec: continue
normale = recup_norm(index)
normale_ref += normale
normale_ref.Normalize()
tolerance = dial.tolerance
for i in xrange(nbpol) :
normale = recup_norm(i)
if verif(normale_ref, normale, tolerance) is True :
bs.Select(i)
doc.EndUndo()
c4d.EventAdd()
if __name__=='__main__':
main()
Télécharger (http://code.vonc.fr/?a=19)
v1.1
Voici un script Python sélectionnant tous les polygones ayant la même orientation que le polygone sélectionné.
Avec une valeur de tolérance pour une utilisation plus souple !
http://code.vonc.fr/details/s19-01.png
import c4d
import math
from c4d import gui, Vector
from c4d.utils import GetAngle
from math import isnan
# César Vonc - v 1.1
class Dialogue(gui.GeDialog) :
annuler = True
tolerance = 0
def CreateLayout(self) :
self.GroupBegin(10, c4d.BFH_SCALEFIT, 1, 2)
self.AddEditNumberArrows(11, c4d.BFH_SCALEFIT)
self.AddButton(12, c4d.BFH_SCALEFIT, initw = 100, inith = 20, name = "Valider")
self.GroupEnd()
return True
def InitValues(self) :
self.SetTitle("Tolérance")
self.SetDegree(11, 0)
return True
def Command(self, id, msg) :
if id == 12 :
self.annuler = False
self.tolerance = self.GetReal(11)
self.Close()
return True
def recup_norm(index) :
poly = op.GetPolygon(index)
pA = op.GetPoint(poly.a)
pB = op.GetPoint(poly.b)
pC = op.GetPoint(poly.c)
pD = op.GetPoint(poly.d)
normale = (pA - pC).Cross(pB - pD)
normale.Normalize()
return normale
def verif(va, vb, tol) :
angle = GetAngle(va, vb)
if isnan(angle) : return True
if tol >= angle : return True
else : return False
def main() :
if not op : return
if op.GetType() != c4d.Opolygon : return
bs = op.GetPolygonS()
nbsel = bs.GetCount()
if nbsel == 0 : return
dial = Dialogue()
dial.Open(c4d.DLG_TYPE_MODAL)
if dial.annuler is True : return
nbpol = op.GetPolygonCount()
normale_ref = Vector(0, 0, 0)
doc.StartUndo()
doc.AddUndo(c4d.UNDOTYPE_CHANGE_SELECTION, op)
for index, selec in enumerate(bs.GetAll(nbpol)) :
if not selec: continue
normale = recup_norm(index)
normale_ref += normale
normale_ref.Normalize()
tolerance = dial.tolerance
for i in xrange(nbpol) :
normale = recup_norm(i)
if verif(normale_ref, normale, tolerance) is True :
bs.Select(i)
doc.EndUndo()
c4d.EventAdd()
if __name__=='__main__':
main()
Télécharger (http://code.vonc.fr/?a=19)