C4D多种选择插件 Python : Sélections Supplétives(英文版+汉化版) 

2014-11-22 00:22 发布 | 作品版权归原作者所有,仅供参考学习,禁止商业使用!

插件脚本 /[系统辅助]
1337 0 0
C4D多种选择插件 Python : Sélections Supplétives(英文版+汉化版)
C4D多种选择插件 Python : Sélections Supplétives(英文版+汉化版) - C4D之家 - image_01.png
v 1.8 : (29 septembre 2013)
- Ajout de la sélection par miroir.

v 1.7 :
- Ajout de la sélection aléatoire.
- Les boîtes de dialogues sont désormais asynchrones.
- Plus d'options pour la sélection par orientation.
- Traduction anglaise par Lubo Bezek.
- Traduction tchèque par Pavel Zoch.
- Correction de divers bogues.

v 1.5 :
- La sélection alternative affecte désormais les points.
- Ajout de la sélection des éléments adjacents.
- Ajout de la sélection de position.
- Ajout de la description des outils.


Lot de sélections en tout genre.

Copiez le dossier « vonc_selsup » dans le dossier « plugins » du répertoire de Cinéma 4D.


Sélectionner les polygones de même orientation

Sélectionne les polygones ayant la même orientation que le polygone sélectionné.


Sélectionner les éléments alternativement

Sélectionne les polygones ou les points à intervalle régulier à partir de la sélection active.
Sélectionner un polygone sur 2, 1 sur 3, 2 sur 4...


Sélectionner les polygones de même taille

Sélectionne tous les polygones ayant plus ou moins le même périmètre que le polygone sélectionné.


Sélectionner les triangles

Sélectionne tous les triangles de l'objet actif.


Sélectionner les quadrangles

Sélectionne tous les quadrangles de l'objet actif.


Sélectionner les n-gones

Sélectionne tous les n-gones de l'objet actif.


Sélectionner jusqu'à l'indice

Sélectionne tous les polygones ou tous les points d'indice inférieur au polygone/point sélectionné d'un objet ou d'une cerce (spline).


Sélectionner les contours

Sélectionne tous les contours de l'objet actif.


Sélectionner les éléments adjacents

Sélectionne les polygones ou les points adjacents à la sélection active.


Sélectionner jusqu'à la position

Sélectionne les points ou les polygones ayant une position supérieure ou inférieure à un point donné.


Sélection aléatoire

Sélectionne les points ou les polygones de façon aléatoire. Un facteur chance permet de sélectionner plus ou moins d'éléments. Il est également possible de sélectionner un nombre précis d'éléments.

Sélection par miroir

Sélectionne les points, arêtes ou polygones opposés par rapport à l'axe de l'objet.

Fichier PYP :
  1. import os
  2. import c4d
  3. import math
  4. import random
  5. from c4d import plugins, bitmaps, gui, documents, Vector
  6. from c4d.utils import GetAngle, Neighbor, VectorEqual, SendModelingCommand
  7. from c4d.plugins import GeLoadString as txt
  8. from math import isnan

  9. doc = c4d.documents.GetActiveDocument()
  10. MODULE_ID = 1028615
  11. SEPARATEUR_ID = 1028614
  12. ID_SELTRI = 1028616
  13. ID_SELQUAD = 1028617
  14. ID_SELNGON = 1028618
  15. ID_SELDIR = 1028625
  16. ID_SELNSN = 1028626
  17. ID_SELCON = 1028627
  18. ID_SELIND = 1028628
  19. ID_SELTAIL = 1028644
  20. ID_SELADJ = 1029578
  21. ID_SELPOS = 1029579
  22. ID_SELPIF = 1030552
  23. ID_SELMIR = 1031153

  24. SS_SS_VAL = 101
  25. SS_SS_FER = 102
  26. SS_SELDIR_NOM = 1001
  27. SS_SELDIR_TOL = 1002
  28. SS_SELDIR_LIM = 1003
  29. SS_SELDIR_AID = 1004
  30. SS_SELDIR_NOR = 1005
  31. SS_SELNSN_NOM = 1101
  32. SS_SELNSN_SEL = 1102
  33. SS_SELNSN_SUR = 1103
  34. SS_SELNSN_DEC = 1104
  35. SS_SELNSN_AID = 1105
  36. SS_SELTAIL_NOM = 1201
  37. SS_SELTAIL_TOL = 1202
  38. SS_SELTAIL_INF = 1203
  39. SS_SELTAIL_SUP = 1204
  40. SS_SELTAIL_AID = 1205
  41. SS_SELTRI_NOM = 1301
  42. SS_SELTRI_AID = 1302
  43. SS_SELQUAD_NOM = 1401
  44. SS_SELQUAD_AID = 1402
  45. SS_SELNGON_NOM = 1501
  46. SS_SELNGON_AID = 1502
  47. SS_SELCON_NOM = 1601
  48. SS_SELCON_AID = 1602
  49. SS_SELIND_NOM = 1701
  50. SS_SELIND_AID = 1702
  51. SS_SELADJ_NOM = 1801
  52. SS_SELADJ_AID = 1802
  53. SS_SELPOS_NOM = 1901
  54. SS_SELPOS_TOL = 1902
  55. SS_SELPOS_AID = 1903
  56. SS_SELPIF_NOM = 2001
  57. SS_SELPIF_AID = 2002
  58. SS_SELPIF_SRC = 2003
  59. SS_SELPIF_QTE = 2004
  60. SS_SELPIF_CHC = 2005
  61. SS_SELMIR_NOM = 2101
  62. SS_SELMIR_AID = 2102
  63. SS_SELMIR_TOL = 2103
  64. SS_SELMIR_AJS = 2104
  65.         

  66. class Seldir_Dialogue(gui.GeDialog) :
  67.         tolerance = 0.17453
  68.         limite = False
  69.         norbool = False
  70.         normale = Vector()
  71.         
  72.         def CreateLayout(self) :
  73.                 self.GroupBegin(100, c4d.BFH_SCALEFIT, 1, 1)
  74.                 self.GroupBorderSpace(5, 5, 5, 5)
  75.                
  76.                 self.GroupBegin(101, c4d.BFH_SCALEFIT, 2, 1)
  77.                 self.AddStaticText(20, c4d.BFH_FIT, 0, 0, txt(SS_SELDIR_TOL))
  78.                 self.AddEditSlider(11, c4d.BFH_SCALEFIT)
  79.                 self.GroupEnd()
  80.                
  81.                 self.GroupBegin(102, c4d.BFH_SCALEFIT, 1, 1)
  82.                 self.AddCheckbox(12, c4d.BFH_SCALEFIT, 0, 0, txt(SS_SELDIR_LIM))
  83.                 self.AddCheckbox(13, c4d.BFH_SCALEFIT, 0, 0, txt(SS_SELDIR_NOR))
  84.                 self.GroupEnd()
  85.                
  86.                 self.GroupBegin(104, c4d.BFH_SCALEFIT, 3, 1)
  87.                 self.AddEditNumberArrows(130, c4d.BFH_SCALEFIT)
  88.                 self.AddEditNumberArrows(131, c4d.BFH_SCALEFIT)
  89.                 self.AddEditNumberArrows(132, c4d.BFH_SCALEFIT)
  90.                 self.GroupEnd()
  91.                
  92.                 self.GroupBegin(103, c4d.BFH_SCALEFIT, 2, 1)
  93.                 self.AddButton(1, c4d.BFH_SCALEFIT, initw = 70, inith = 15, name = txt(SS_SS_VAL))
  94.                 self.AddButton(2, c4d.BFH_SCALEFIT, initw = 70, inith = 15, name = txt(SS_SS_FER))
  95.                 self.GroupEnd()
  96.                
  97.                 self.GroupEnd()
  98.                 return True
  99.         
  100.         def InitValues(self) :
  101.                 self.SetTitle(txt(SS_SELDIR_NOM))
  102.                 self.SetDegree(11, self.tolerance, 0, 360)
  103.                 self.SetReal(130, 0.0, step=1.0)
  104.                 self.SetReal(131, 0.0, step=1.0)
  105.                 self.SetReal(132, 0.0, step=1.0)
  106.                 self.Enable(130, False)
  107.                 self.Enable(131, False)
  108.                 self.Enable(132, False)
  109.                 return True
  110.         
  111.         def Command(self, id, msg) :
  112.                 if id == 13 :
  113.                         nor = self.GetBool(13)
  114.                         self.Enable(130, nor)
  115.                         self.Enable(131, nor)
  116.                         self.Enable(132, nor)
  117.                         
  118.                 if id == c4d.DLG_OK :
  119.                         self.tolerance = self.GetReal(11)
  120.                         self.limite = self.GetBool(12)
  121.                         self.norbool = self.GetBool(13)
  122.                         self.normale = self.GetVector(130, 131, 132)
  123.                         
  124.                         doc = documents.GetActiveDocument()
  125.                         obj = doc.GetActiveObject()
  126.                         self.sel_dir(doc, obj)
  127.                 elif id == c4d.DLG_CANCEL :
  128.                         self.Close()
  129.                 return True
  130.         
  131.         
  132.         def recup_norm(self, index, obj) :
  133.                 poly = obj.GetPolygon(index)
  134.                 pA = obj.GetPoint(poly.a)
  135.                 pB = obj.GetPoint(poly.b)
  136.                 pC = obj.GetPoint(poly.c)
  137.                 pD = obj.GetPoint(poly.d)
  138.                 normale = (pA - pC).Cross(pB - pD)
  139.                 normale.Normalize()
  140.                 return normale
  141.         
  142.         def verif(self, va, vb, tol) :
  143.                 angle = GetAngle(va, vb)
  144.                 if isnan(angle) :
  145.                         if VectorEqual(va, -vb) : return False
  146.                         return True
  147.                 if tol >= angle : return True
  148.                 else : return False
  149.         
  150.         def sel_dir(self, doc, obj) :
  151.                 if not obj : return
  152.                 if obj.GetType() != c4d.Opolygon : return
  153.                 if doc.GetMode() != c4d.Mpolygons : return
  154.                
  155.                 bs = obj.GetPolygonS()
  156.                 nbsel = bs.GetCount()
  157.                 if nbsel == 0 and not self.norbool : return
  158.                
  159.                 # dial = Seldir_Dialogue()
  160.                 # dial.Open(c4d.DLG_TYPE_MODAL)
  161.                 # if dial.annuler : return
  162.                
  163.                 nbpol = obj.GetPolygonCount()
  164.                 normale_ref = Vector(0, 0, 0)
  165.                
  166.                 doc.StartUndo()
  167.                 doc.AddUndo(c4d.UNDOTYPE_CHANGE_SELECTION, obj)
  168.                
  169.                 premsel = 0
  170.                 for index, selec in enumerate(bs.GetAll(nbpol)) :
  171.                         if not selec: continue
  172.                         normale = self.recup_norm(index, obj)
  173.                         normale_ref += normale
  174.                         premsel = index
  175.                
  176.                 if self.norbool : normale_ref = self.normale
  177.                
  178.                 normale_ref.Normalize()
  179.                 tolerance = self.tolerance
  180.                 limite = self.limite
  181.                
  182.                 for i in xrange(nbpol) :
  183.                         normale = self.recup_norm(i, obj)
  184.                         if self.verif(normale_ref, normale, tolerance) :
  185.                                 bs.Select(i)
  186.                
  187.                 if limite and nbsel :
  188.                         commande = c4d.ID_MODELING_FILL_SELECTION_TOOL
  189.                         mode = c4d.MODELINGCOMMANDMODE_POLYGONSELECTION
  190.                         params = c4d.BaseContainer()
  191.                         # for i in xrange(2160) :
  192.                                 # params[i] = 167
  193.                         params[2157] = premsel #167
  194.                         SendModelingCommand(command=commande, list=[obj], mode=mode, bc=params, doc=doc, flags=c4d.MODELINGCOMMANDFLAGS_0)
  195.                
  196.                 doc.EndUndo()
  197.                 c4d.EventAdd()
  198.                 c4d.CallCommand(12187) # Polygones
  199.         
  200.         
  201. class Seldir(plugins.CommandData) :
  202.         dialog = None
  203.         
  204.         def Execute(self, doc) :
  205.                 if self.dialog is None:
  206.                         self.dialog = Seldir_Dialogue()
  207.                 return self.dialog.Open(dlgtype=c4d.DLG_TYPE_ASYNC, pluginid=ID_SELDIR, defaulth=100, defaultw=70)

  208.         def RestoreLayout(self, sec_ref):
  209.                 if self.dialog is None:
  210.                         self.dialog = Seldir_Dialogue()
  211.                 return self.dialog.Restore(pluginid=ID_SELDIR, secret=sec_ref)

  212. class Selnsn_Dialogue(gui.GeDialog) :
  213.         a = 1
  214.         b = 2
  215.         dec = 0
  216.         
  217.         def CreateLayout(self) :
  218.                 self.GroupBegin(10, c4d.BFH_SCALEFIT, 2, 3)
  219.                 self.GroupBorderSpace(5, 5, 5, 5)
  220.                 self.AddStaticText(20, c4d.BFH_SCALEFIT, 0, 0, txt(SS_SELNSN_SEL))
  221.                 self.AddEditNumberArrows(30, c4d.BFH_SCALEFIT)
  222.                 self.AddStaticText(21, c4d.BFH_SCALEFIT, 0, 0, txt(SS_SELNSN_SUR))
  223.                 self.AddEditNumberArrows(31, c4d.BFH_SCALEFIT)
  224.                 self.AddStaticText(22, c4d.BFH_SCALEFIT, 0, 0, txt(SS_SELNSN_DEC))
  225.                 self.AddEditNumberArrows(32, c4d.BFH_SCALEFIT)
  226.                 self.AddButton(1, c4d.BFH_SCALEFIT, initw = 70, inith = 15, name = txt(SS_SS_VAL))
  227.                 self.AddButton(2, c4d.BFH_SCALEFIT, initw = 70, inith = 15, name = txt(SS_SS_FER))
  228.                 self.GroupEnd()
  229.                 return True
  230.         
  231.         def InitValues(self) :
  232.                 self.SetTitle(txt(SS_SELNSN_NOM))
  233.                 self.SetLong(30, 1, 1)
  234.                 self.SetLong(31, 2, 1)
  235.                 return True
  236.         
  237.         def Command(self, id, msg) :
  238.                 if id == 1 :
  239.                         self.a = self.GetLong(30)
  240.                         self.b = self.GetLong(31)
  241.                         self.dec = self.GetLong(32)
  242.                         doc = documents.GetActiveDocument()
  243.                         obj = doc.GetActiveObject()
  244.                         self.sel_nsn(doc, obj)
  245.                 if id == 2 :
  246.                         self.Close()
  247.                 return True
  248.         
  249.         def verif(self, p, li, bs) :
  250.                 if not bs.IsSelected(p) : return False
  251.                 if li.IsSelected(p) : return False
  252.                 return True
  253.         
  254.         def point_voisin(self, pp, li, bs, n, obj) :
  255.                 if pp is None : return None
  256.                
  257.                 polys = n.GetPointPolys(pp)
  258.                 points = []
  259.                 for poly in polys :
  260.                         poly = obj.GetPolygon(poly)
  261.                         points.extend([poly.a, poly.b, poly.c, poly.d])
  262.                 points = list(set(points))
  263.                
  264.                 points_aretes = []
  265.                 for pt in points :
  266.                         arete = n.GetEdgePolys(pp, pt)
  267.                         if arete != (-1, -1) : points_aretes.append(pt)
  268.                
  269.                 for pt in points_aretes :
  270.                         if not bs.IsSelected(pt) : continue
  271.                         if li.IsSelected(pt) : continue
  272.                         return pt
  273.                
  274.                 return None
  275.         
  276.         def mono_voisin(self, pp, li, bs, n, obj) :
  277.                 if pp is None : return None
  278.                 pol = obj.GetPolygon(pp)
  279.                
  280.                 nab = n.GetNeighbor(pol.a, pol.b, pp)
  281.                 if self.verif(nab, li, bs) : return nab
  282.                
  283.                 nbc = n.GetNeighbor(pol.b, pol.c, pp)
  284.                 if self.verif(nbc, li, bs) : return nbc
  285.                
  286.                 ncd = n.GetNeighbor(pol.c, pol.d, pp)
  287.                 if self.verif(ncd, li, bs) : return ncd
  288.                
  289.                 nda = n.GetNeighbor(pol.d, pol.a, pp)
  290.                 if self.verif(nda, li, bs) : return nda
  291.                
  292.                 return None

  293.         def sel_nsn(self, doc, obj) :
  294.                 if not obj : return
  295.                 polygonal = obj.CheckType(c4d.Opolygon)
  296.                 cerce = obj.CheckType(c4d.Ospline)
  297.                 modePoints = doc.GetMode() == c4d.Mpoints
  298.                 modePolys = doc.GetMode() == c4d.Mpolygons
  299.                 if not polygonal and not cerce : return
  300.                 #if polygonal and not modePolys : return
  301.                 if cerce and not modePoints : return
  302.                 if not modePoints and not modePolys : return
  303.                
  304.                 if modePolys :
  305.                         bs = obj.GetPolygonS()
  306.                         nbp = obj.GetPolygonCount()
  307.                 else :
  308.                         bs = obj.GetPointS()
  309.                         nbp = obj.GetPointCount()
  310.                
  311.                 bs_total = bs.GetCount()
  312.                 if bs_total and bs_total < 2 : return
  313.                
  314.                 # dial = Selnsn_Dialogue()
  315.                 # dial.Open(c4d.DLG_TYPE_MODAL)
  316.                 # if dial.annuler : return
  317.                
  318.                 a = self.a
  319.                 b = self.b
  320.                 if (self.b < self.a) : b = a
  321.                 dec = self.dec % b
  322.                
  323.                 doc.StartUndo()
  324.                 doc.AddUndo(c4d.UNDOTYPE_CHANGE_SELECTION, obj)
  325.                
  326.                 #-----------
  327.                 if cerce :
  328.                         if not bs_total : bs.SelectAll(nbp-1)
  329.                         li = bs.GetClone()
  330.                         bs.DeselectAll()
  331.                         j = dec
  332.                         bs_sel = li.GetAll(nbp)
  333.                         for i, sel in enumerate(bs_sel) :
  334.                                 if not sel :
  335.                                         j = dec
  336.                                         continue
  337.                                 if (j%b) < a : bs.Select(i)
  338.                                 j += 1
  339.                         
  340.                         doc.EndUndo()
  341.                         c4d.EventAdd()
  342.                         return
  343.                 #----------
  344.                
  345.                 n = Neighbor()
  346.                 n.Init(obj)
  347.                 if not bs_total : bs.SelectAll(nbp)
  348.                
  349.                 def traite(li, p, ordre) :
  350.                         if p != None :
  351.                                 li.Select(p)
  352.                                 ordre.append(p)
  353.                
  354.                 def tour(pp) :
  355.                         ordre1 = []
  356.                         voisin = self.mono_voisin
  357.                         if modePoints : voisin = self.point_voisin
  358.                         
  359.                         pa = voisin(pp, li, bs, n, obj)
  360.                         traite(li, pp, ordre1)
  361.                         traite(li, pa, ordre1)
  362.                         
  363.                         po = voisin(pa, li, bs, n, obj)
  364.                         while (po != None) :
  365.                                 traite(li, po, ordre1)
  366.                                 po = voisin(po, li, bs, n, obj)
  367.                         
  368.                         ordre2 = []
  369.                         pb = voisin(pp, li, bs, n, obj)
  370.                         if pb != None :
  371.                                 traite(li, pb, ordre2)
  372.                                 po = voisin(pb, li, bs, n, obj)
  373.                         else : po = None
  374.                         while (po != None) :
  375.                                 traite(li, po, ordre2)
  376.                                 po = voisin(po, li, bs, n, obj)
  377.                         
  378.                         ordre1.reverse()
  379.                         ordre1.extend(ordre2)
  380.                         return ordre1
  381.                
  382.                 ordre = []
  383.                
  384.                 li = bs.GetClone()
  385.                 li.DeselectAll()
  386.                 bs_sel = bs.GetAll(nbp)
  387.                 for i, sel in enumerate(bs_sel) :
  388.                         if not sel : continue
  389.                         if li.IsSelected(i) : continue
  390.                         ordre.extend(tour(i))
  391.                
  392.                 j = 0
  393.                 jmax = len(ordre)
  394.                 bs.DeselectAll()
  395.                
  396.                 while (j < jmax) :
  397.                         for k in xrange(a) :
  398.                                 s = j + k + dec
  399.                                 if s >= jmax : break
  400.                                 bs.Select(ordre[s])
  401.                         j += b
  402.                
  403.                 doc.EndUndo()
  404.                 c4d.EventAdd()
  405.         
  406.         
  407. class Selnsn(plugins.CommandData) :
  408.         dialog = None
  409.         
  410.         def Execute(self, doc) :
  411.                 if self.dialog is None:
  412.                         self.dialog = Selnsn_Dialogue()
  413.                 return self.dialog.Open(dlgtype=c4d.DLG_TYPE_ASYNC, pluginid=ID_SELNSN, defaulth=100, defaultw=100)

  414.         def RestoreLayout(self, sec_ref):
  415.                 if self.dialog is None:
  416.                         self.dialog = Selnsn_Dialogue()
  417.                 return self.dialog.Restore(pluginid=ID_SELNSN, secret=sec_ref)

  418. class Seltri(plugins.CommandData) :
  419.         def sel_tri(self, doc, obj) :
  420.                 if not obj : return
  421.                 if obj.GetType() != c4d.Opolygon : return
  422.                 ng = obj.GetNgonEdgesCompact()
  423.                 bs = obj.GetPolygonS()
  424.                 n = -1
  425.                 doc.StartUndo()
  426.                 doc.AddUndo(c4d.UNDOTYPE_CHANGE_SELECTION, obj)
  427.                 for p in ng :
  428.                         n += 1
  429.                         if p != 0: continue
  430.                         pol = obj.GetPolygon(n)
  431.                         if pol.c == pol.d : bs.Select(n)
  432.                 doc.EndUndo()
  433.                 c4d.EventAdd()
  434.                 c4d.CallCommand(12187) # Polygones
  435.         
  436.         def Execute(self, doc) :
  437.                 obj = doc.GetActiveObject()
  438.                 self.sel_tri(doc, obj)
  439.                 return True

  440. class Selquad(plugins.CommandData) :
  441.         def sel_quad(self, doc, obj):
  442.                 if not obj: return
  443.                 if obj.GetType() != c4d.Opolygon: return
  444.                 ng = obj.GetNgonEdgesCompact()
  445.                 bs = obj.GetPolygonS()
  446.                 n = -1
  447.                 doc.StartUndo()
  448.                 doc.AddUndo(c4d.UNDOTYPE_CHANGE_SELECTION, obj)
  449.                 for p in ng:
  450.                         n += 1
  451.                         if p != 0: continue
  452.                         pol = obj.GetPolygon(n)
  453.                         if pol.c != pol.d : bs.Select(n)
  454.                 doc.EndUndo()
  455.                 c4d.EventAdd()
  456.                 c4d.CallCommand(12187) # Polygones
  457.         
  458.         def Execute(self, doc) :
  459.                 obj = doc.GetActiveObject()
  460.                 self.sel_quad(doc, obj)
  461.                 return True

  462. class Selngon(plugins.CommandData) :
  463.         def sel_ngon(self, doc, obj) :
  464.                 if not obj: return
  465.                 if obj.GetType() != c4d.Opolygon: return
  466.                 ng = obj.GetNgonEdgesCompact()
  467.                 bs = obj.GetPolygonS()
  468.                 n = 0
  469.                 doc.StartUndo()
  470.                 doc.AddUndo(c4d.UNDOTYPE_CHANGE_SELECTION, obj)
  471.                 for p in ng:
  472.                         if p != 0: bs.Select(n)
  473.                         n += 1
  474.                 doc.EndUndo()
  475.                 c4d.EventAdd()
  476.                 c4d.CallCommand(12187) # Polygones
  477.         
  478.         def Execute(self, doc) :
  479.                 obj = doc.GetActiveObject()
  480.                 self.sel_ngon(doc, obj)
  481.                 return True

  482. class Selcon(plugins.CommandData) :
  483.         def sel_con(self, doc, obj):
  484.                 if not obj: return
  485.                 if obj.GetType() != c4d.Opolygon: return
  486.                 nb_pol = obj.GetPolygonCount()
  487.                 bs = c4d.BaseSelect()
  488.                 n = Neighbor()
  489.                 n.Init(obj)
  490.                
  491.                 for i in xrange(nb_pol):
  492.                         pol = obj.GetPolygon(i)
  493.                         
  494.                         pa = pol.a
  495.                         pb = pol.b
  496.                         pc = pol.c
  497.                         pd = pol.d
  498.                         
  499.                         nab = n.GetNeighbor(pa, pb, i)
  500.                         nbc = n.GetNeighbor(pb, pc, i)
  501.                         ncd = n.GetNeighbor(pc, pd, i)
  502.                         nda = n.GetNeighbor(pd, pa, i)
  503.                         
  504.                         cotes = n.GetPolyInfo(i)["edge"]
  505.                         
  506.                         if nab == -1:
  507.                                 bs.Select(cotes[0])
  508.                         if nbc == -1:
  509.                                 bs.Select(cotes[1])
  510.                         if ncd == -1:
  511.                                 if pc != pd: bs.Select(cotes[2])
  512.                         if nda == -1:
  513.                                 bs.Select(cotes[3])
  514.                
  515.                 doc.StartUndo()
  516.                 doc.AddUndo(c4d.UNDOTYPE_CHANGE_SELECTION, obj)
  517.                 obj.SetSelectedEdges(n, bs, 0)
  518.                 doc.EndUndo()
  519.                 c4d.EventAdd()
  520.                 c4d.CallCommand(16351) # Arêtes
  521.         
  522.         def Execute(self, doc) :
  523.                 obj = doc.GetActiveObject()
  524.                 self.sel_con(doc, obj)
  525.                 return True

  526. class Selind(plugins.CommandData) :
  527.         def sel_ind(self, doc, obj):
  528.                 if not obj : return
  529.                 if obj.GetType() != c4d.Opolygon and obj.GetType() != c4d.Ospline : return
  530.                
  531.                 if c4d.IsCommandChecked(12187) and obj.GetType() == c4d.Opolygon : # Polygones
  532.                         bs = obj.GetPolygonS()
  533.                         nbp = obj.GetPolygonCount()
  534.                 else :
  535.                         bs = obj.GetPointS()
  536.                         nbp = obj.GetPointCount()
  537.                
  538.                 nbsel = bs.GetCount()
  539.                 if nbsel == 0 : return
  540.                
  541.                 doc.StartUndo()
  542.                 doc.AddUndo(c4d.UNDOTYPE_CHANGE_SELECTION, obj)
  543.                
  544.                 for i, sel in enumerate(bs.GetAll(nbp)) :
  545.                         if not sel :
  546.                                 bs.Select(i)
  547.                                 continue
  548.                         break
  549.                
  550.                 doc.EndUndo()
  551.                 c4d.EventAdd()
  552.         
  553.         def Execute(self, doc) :
  554.                 obj = doc.GetActiveObject()
  555.                 self.sel_ind(doc, obj)
  556.                 return True

  557. class Seltail_Dialogue(gui.GeDialog) :
  558.         tol = 0
  559.         inf = False
  560.         sup = False
  561.         
  562.         def CreateLayout(self) :
  563.                 self.GroupBegin(10, c4d.BFH_SCALEFIT, 1, 4)
  564.                 self.GroupBorderSpace(5, 5, 5, 5)
  565.                 self.GroupBegin(15, c4d.BFH_SCALEFIT, 2, 1)
  566.                 self.AddStaticText(16, c4d.BFH_SCALEFIT, name = txt(SS_SELTAIL_TOL))
  567.                 self.AddEditNumberArrows(11, c4d.BFH_SCALEFIT)
  568.                 self.GroupEnd()
  569.                 self.AddCheckbox(13, c4d.BFH_SCALEFIT, initw = 250, inith = 10, name = txt(SS_SELTAIL_INF))
  570.                 self.AddCheckbox(14, c4d.BFH_SCALEFIT, initw = 250, inith = 10, name = txt(SS_SELTAIL_SUP))
  571.                 self.GroupBegin(16, c4d.BFH_SCALEFIT, 2, 1)
  572.                 self.AddButton(1, c4d.BFH_SCALEFIT, initw = 70, inith = 15, name = txt(SS_SS_VAL))
  573.                 self.AddButton(2, c4d.BFH_SCALEFIT, initw = 70, inith = 15, name = txt(SS_SS_FER))
  574.                 self.GroupEnd()
  575.                 self.GroupEnd()
  576.                 return True
  577.         
  578.         def InitValues(self) :
  579.                 self.SetTitle(txt(SS_SELTAIL_NOM))
  580.                 self.SetPercent(11, 0.005, 0)
  581.                 return True
  582.         
  583.         def Command(self, id, msg) :
  584.                 if id == 1 :
  585.                         self.tol = self.GetReal(11)
  586.                         self.inf = self.GetBool(13)
  587.                         self.sup = self.GetBool(14)
  588.                         doc = documents.GetActiveDocument()
  589.                         obj = doc.GetActiveObject()
  590.                         self.sel_tail(doc, obj)
  591.                 if id == 2 :
  592.                         self.Close()
  593.                 return True
  594.                
  595.         def perim(self, i, obj) :
  596.                 poly = obj.GetPolygon(i)
  597.                 pA = obj.GetPoint(poly.a)
  598.                 pB = obj.GetPoint(poly.b)
  599.                 pC = obj.GetPoint(poly.c)
  600.                 pD = obj.GetPoint(poly.d)
  601.                 per = (pA - pB).GetLengthSquared() + (pB - pC).GetLengthSquared() + (pC - pD).GetLengthSquared() + (pD - pA).GetLengthSquared()
  602.                 return per

  603.         def verif(self, ta, tb, tol, inf, sup) :
  604.                 tatol = ta*tol
  605.                 if inf :
  606.                         if tb <= (ta + tatol) :
  607.                                  return True
  608.                
  609.                 if sup :
  610.                         if tb >= (ta - tatol) :
  611.                                  return True
  612.                
  613.                 if tb <= (ta + tatol) :
  614.                         if tb >= (ta - tatol) :
  615.                                 return True
  616.                
  617.                 return False
  618.         
  619.         def sel_tail(self, doc, obj):
  620.                 if not obj : return
  621.                 if obj.GetType() != c4d.Opolygon : return
  622.                 if doc.GetMode() != c4d.Mpolygons : return
  623.                
  624.                 bs = obj.GetPolygonS()
  625.                 nbsel = bs.GetCount()
  626.                 if nbsel == 0 : return
  627.                
  628.                 # dial = Seltail_Dialogue()
  629.                 # dial.Open(c4d.DLG_TYPE_MODAL)
  630.                 # if dial.annuler : return
  631.                
  632.                 nbpol = obj.GetPolygonCount()
  633.                 taille_ref = 0
  634.                
  635.                 doc.StartUndo()
  636.                 doc.AddUndo(c4d.UNDOTYPE_CHANGE_SELECTION, obj)
  637.                
  638.                 for index, selec in enumerate(bs.GetAll(nbpol)) :
  639.                         if not selec: continue
  640.                         taille = self.perim(index, obj)
  641.                         taille_ref += taille
  642.                
  643.                 for i in xrange(nbpol) :
  644.                         taille = self.perim(i, obj)
  645.                         if self.verif(taille_ref, taille, self.tol, self.inf, self.sup) :
  646.                                 bs.Select(i)
  647.                
  648.                 doc.EndUndo()
  649.                 c4d.EventAdd()
  650.                 c4d.CallCommand(12187) # Polygones
  651.         

  652. class Seltail(plugins.CommandData) :
  653.         dialog = None
  654.         
  655.         def Execute(self, doc) :
  656.                 if self.dialog is None:
  657.                         self.dialog = Seltail_Dialogue()
  658.                 return self.dialog.Open(dlgtype=c4d.DLG_TYPE_ASYNC, pluginid=ID_SELTAIL, defaulth=100, defaultw=70)

  659.         def RestoreLayout(self, sec_ref):
  660.                 if self.dialog is None:
  661.                         self.dialog = Seltail_Dialogue()
  662.                 return self.dialog.Restore(pluginid=ID_SELTAIL, secret=sec_ref)

  663. class Seladj(plugins.CommandData) :
  664.         def sel_adj(self, doc, obj):
  665.                 if not obj : return
  666.                 modePoints = doc.GetMode() == c4d.Mpoints
  667.                 modePolys = doc.GetMode() == c4d.Mpolygons
  668.                 polygonal = obj.CheckType(c4d.Opolygon)
  669.                 cerce = obj.CheckType(c4d.Ospline)
  670.                 if not polygonal and not cerce : return
  671.                 if not modePoints and not modePolys : return
  672.                 if cerce and modePolys : return
  673.                
  674.                 if polygonal :
  675.                         nb_pol = obj.GetPolygonCount()
  676.                         bs = obj.GetPolygonS()
  677.                         n = Neighbor()
  678.                         n.Init(obj)
  679.                         
  680.                 nb_pts = obj.GetPointCount()
  681.                 bs_p = obj.GetPointS()

  682.                 doc.StartUndo()
  683.                 doc.AddUndo(c4d.UNDOTYPE_CHANGE_SELECTION, obj)
  684.                
  685.                 if modePolys :
  686.                         for i, sel in enumerate(bs.GetAll(nb_pol)):
  687.                                 if not sel: continue
  688.                                 pol = obj.GetPolygon(i)
  689.                                 
  690.                                 cotes = []
  691.                                 cotes.extend(n.GetPointPolys(pol.a))
  692.                                 cotes.extend(n.GetPointPolys(pol.b))
  693.                                 cotes.extend(n.GetPointPolys(pol.c))
  694.                                 cotes.extend(n.GetPointPolys(pol.d))
  695.                                 
  696.                                 for p in cotes :
  697.                                         bs.Select(p)
  698.                
  699.                 else :
  700.                         if polygonal :
  701.                                 for i, sel in enumerate(bs_p.GetAll(nb_pts)):
  702.                                         if not sel : continue
  703.                                         polys = n.GetPointPolys(i)
  704.                                         for poly in polys :
  705.                                                 p = obj.GetPolygon(poly)
  706.                                                 bs_p.Select(p.a)
  707.                                                 bs_p.Select(p.b)
  708.                                                 bs_p.Select(p.c)
  709.                                                 bs_p.Select(p.d)
  710.                         else :
  711.                                 for i, sel in enumerate(bs_p.GetAll(nb_pts)):
  712.                                         if not sel : continue
  713.                                         iP = i + 1
  714.                                         iM = i - 1
  715.                                         if iP < nb_pts : bs_p.Select(iP)
  716.                                         if iM >= 0 : bs_p.Select(iM)

  717.                 doc.EndUndo()
  718.                 c4d.EventAdd()
  719.         
  720.         def Execute(self, doc) :
  721.                 obj = doc.GetActiveObject()
  722.                 self.sel_adj(doc, obj)
  723.                 return True

  724. class Selpos_Dialogue(gui.GeDialog) :
  725.         tol = 0.001
  726.         pos = Vector()
  727.         Xcon = 0
  728.         Ycon = 0
  729.         Zcon = 0
  730.         
  731.         def CreateLayout(self) :
  732.                 self.GroupBegin(10, c4d.BFH_SCALEFIT, 1, 3)
  733.                 self.GroupBorderSpace(5, 5, 5, 5)
  734.                
  735.                 self.GroupBegin(12, c4d.BFH_SCALEFIT, 5, 3)
  736.                 self.AddStaticText(20, c4d.BFH_SCALEFIT, name = "X")
  737.                 self.AddCheckbox(21, c4d.BFH_SCALEFIT, initw = 70, inith = 10, name = "<")
  738.                 self.AddCheckbox(22, c4d.BFH_SCALEFIT, initw = 70, inith = 10, name = ">")
  739.                 self.AddCheckbox(23, c4d.BFH_SCALEFIT, initw = 70, inith = 10, name = "=")
  740.                 self.AddEditNumberArrows(24, c4d.BFH_SCALEFIT, initw = 140)
  741.                
  742.                 self.AddStaticText(30, c4d.BFH_SCALEFIT, name = "Y")
  743.                 self.AddCheckbox(31, c4d.BFH_SCALEFIT, initw = 70, inith = 10, name = "<")
  744.                 self.AddCheckbox(32, c4d.BFH_SCALEFIT, initw = 70, inith = 10, name = ">")
  745.                 self.AddCheckbox(33, c4d.BFH_SCALEFIT, initw = 70, inith = 10, name = "=")
  746.                 self.AddEditNumberArrows(34, c4d.BFH_SCALEFIT, initw = 140)
  747.                
  748.                 self.AddStaticText(40, c4d.BFH_SCALEFIT, name = "Z")
  749.                 self.AddCheckbox(41, c4d.BFH_SCALEFIT, initw = 70, inith = 10, name = "<")
  750.                 self.AddCheckbox(42, c4d.BFH_SCALEFIT, initw = 70, inith = 10, name = ">")
  751.                 self.AddCheckbox(43, c4d.BFH_SCALEFIT, initw = 70, inith = 10, name = "=")
  752.                 self.AddEditNumberArrows(44, c4d.BFH_SCALEFIT, initw = 140)
  753.                 self.GroupEnd()
  754.                
  755.                 self.GroupBegin(14, c4d.BFH_SCALEFIT, 2, 1)
  756.                 self.AddStaticText(13, c4d.BFH_SCALEFIT, name = txt(SS_SELPOS_TOL))
  757.                 self.AddEditNumberArrows(11, c4d.BFH_SCALEFIT)
  758.                
  759.                 self.AddButton(1, c4d.BFH_SCALEFIT, initw = 70, inith = 15, name = txt(SS_SS_VAL))
  760.                 self.AddButton(2, c4d.BFH_SCALEFIT, initw = 70, inith = 15, name = txt(SS_SS_FER))
  761.                 self.GroupEnd()
  762.                
  763.                 self.GroupEnd()
  764.                 return True
  765.         
  766.         def InitValues(self) :
  767.                 doc = documents.GetActiveDocument()
  768.                 obj = doc.GetActiveObject()
  769.                 self.pos = self.sel_pos(doc, obj, True)
  770.                 self.SetTitle(txt(SS_SELPOS_NOM))
  771.                 self.SetMeter(11, self.tol, 0)
  772.                 if self.pos is None : return True
  773.                 self.SetMeter(24, self.pos.x)
  774.                 self.SetMeter(34, self.pos.y)
  775.                 self.SetMeter(44, self.pos.z)
  776.                 return True
  777.         
  778.         def conditionneur(self, n) :
  779.                 inf = self.GetBool(n+1)
  780.                 sup = self.GetBool(n+2)
  781.                 ega = self.GetBool(n+3)
  782.                 # 0 : aucun, 1 : =, 2 : <, 3 : <=, 4 : >, 5 : >=
  783.                 return (inf*2 + sup*4 + ega)
  784.         
  785.         def Command(self, id, msg) :
  786.                 if id == 21 and self.GetBool(21) : self.SetBool(22, False)
  787.                 if id == 22 and self.GetBool(22) : self.SetBool(21, False)
  788.                 if id == 31 and self.GetBool(31) : self.SetBool(32, False)
  789.                 if id == 32 and self.GetBool(32) : self.SetBool(31, False)
  790.                 if id == 41 and self.GetBool(41) : self.SetBool(42, False)
  791.                 if id == 42 and self.GetBool(42) : self.SetBool(41, False)
  792.                
  793.                 if id == 1 :
  794.                         self.tol = self.GetReal(11)
  795.                         if self.pos is None : return True
  796.                         self.pos.x = self.GetReal(24)
  797.                         self.pos.y = self.GetReal(34)
  798.                         self.pos.z = self.GetReal(44)
  799.                         self.Xcon = self.conditionneur(20)
  800.                         self.Ycon = self.conditionneur(30)
  801.                         self.Zcon = self.conditionneur(40)
  802.                         doc = documents.GetActiveDocument()
  803.                         obj = doc.GetActiveObject()
  804.                         self.sel_pos(doc, obj)
  805.                 if id == 2 :
  806.                         self.Close()
  807.                 return True
  808.         
  809.         def CoreMessage(self, id, msg) :
  810.                 if id == c4d.EVMSG_CHANGE :
  811.                         self.InitValues()
  812.                 return True
  813.         
  814.         def condition(self, pt, pos, con, tol) :
  815.                 if con == 1 :
  816.                         if pt < (pos+tol) and pt > (pos-tol) : return True
  817.                 elif con == 2 :
  818.                         if pt < (pos+tol) : return True
  819.                 elif con == 3 :
  820.                         if pt <= (pos+tol) : return True
  821.                 elif con == 4 :
  822.                         if pt > (pos-tol) : return True
  823.                 elif con == 5 :
  824.                         if pt >= (pos-tol) : return True
  825.                 return False
  826.         
  827.         def centrepoly(self, obj, i) :
  828.                 poly = obj.GetPolygon(i)
  829.                 centre = Vector()
  830.                 centre += obj.GetPoint(poly.a)
  831.                 centre += obj.GetPoint(poly.b)
  832.                 centre += obj.GetPoint(poly.c)
  833.                 if poly.c == poly.d :
  834.                         centre /= 3.0
  835.                 else :
  836.                         centre += obj.GetPoint(poly.d)
  837.                         centre *= 0.25
  838.                 return centre
  839.         
  840.         def sel_pos(self, doc, obj, init=False) :
  841.                 if not obj : return
  842.                 polygonal = obj.CheckType(c4d.Opolygon)
  843.                 cerce = obj.CheckType(c4d.Ospline)
  844.                 if not polygonal and not cerce : return
  845.                 mode = doc.GetMode()
  846.                 if mode != c4d.Mpoints and mode != c4d.Mpolygons : return
  847.                 if mode == c4d.Mpolygons and cerce : return
  848.                
  849.                 if mode == c4d.Mpoints :
  850.                         points = True
  851.                         bs = obj.GetPointS()
  852.                 else :
  853.                         points = False
  854.                         bs = obj.GetPolygonS()
  855.                
  856.                 nbsel = bs.GetCount()
  857.                 if points : nbp = obj.GetPointCount()
  858.                 else : nbp = obj.GetPolygonCount()
  859.                
  860.                 if not init :
  861.                         doc.StartUndo()
  862.                         doc.AddUndo(c4d.UNDOTYPE_CHANGE_SELECTION, obj)
  863.                
  864.                 centrepoly = self.centrepoly
  865.                 nb = 0
  866.                 p = Vector()
  867.                 pos_min = Vector()
  868.                 pos_max = Vector()
  869.                
  870.                 for i, sel in enumerate(bs.GetAll(nbp)) :
  871.                         if not sel : continue
  872.                         
  873.                         if points : p = obj.GetPoint(i)
  874.                         else : p = centrepoly(obj, i)
  875.                         
  876.                         if p.x < pos_min.x or not nb : pos_min.x = p.x
  877.                         if p.y < pos_min.y or not nb : pos_min.y = p.y
  878.                         if p.z < pos_min.z or not nb : pos_min.z = p.z
  879.                         
  880.                         if p.x > pos_max.x or not nb : pos_max.x = p.x
  881.                         if p.y > pos_max.y or not nb : pos_max.y = p.y
  882.                         if p.z > pos_max.z or not nb : pos_max.z = p.z
  883.                         
  884.                         nb += 1
  885.                         if nb == nbp : break
  886.                
  887.                 pos = (pos_min + pos_max) * 0.5
  888.                
  889.                 if init : return pos
  890.                
  891.                 # dial = Selpos_Dialogue(pos)
  892.                 # dial.Open(c4d.DLG_TYPE_MODAL)
  893.                 # if dial.annuler : return
  894.                
  895.                 pos = self.pos
  896.                 tol = self.tol
  897.                 Xcon = self.Xcon
  898.                 Ycon = self.Ycon
  899.                 Zcon = self.Zcon
  900.                 condition = self.condition
  901.                 pt = Vector()
  902.                
  903.                 for i in xrange(nbp) :
  904.                         if points :
  905.                                 pt = obj.GetPoint(i)
  906.                         else :
  907.                                 pt = centrepoly(obj, i)
  908.                         cond = 0
  909.                         res = 0
  910.                         if Xcon :
  911.                                 cond += condition(pt.x, pos.x, Xcon, tol)
  912.                                 res += 1
  913.                         if Ycon :
  914.                                 cond += condition(pt.y, pos.y, Ycon, tol)
  915.                                 res += 1
  916.                         if Zcon :
  917.                                 cond += condition(pt.z, pos.z, Zcon, tol)
  918.                                 res += 1
  919.                         if cond == res :
  920.                                 bs.Select(i)
  921.                         
  922.                 doc.EndUndo()
  923.                 c4d.EventAdd()

  924. class Selpos(plugins.CommandData) :
  925.         dialog = None
  926.         
  927.         def Execute(self, doc) :
  928.                 if self.dialog is None:
  929.                         self.dialog = Selpos_Dialogue()
  930.                 return self.dialog.Open(dlgtype=c4d.DLG_TYPE_ASYNC, pluginid=ID_SELPOS, defaulth=100, defaultw=70)

  931.         def RestoreLayout(self, sec_ref):
  932.                 if self.dialog is None:
  933.                         self.dialog = Selpos_Dialogue()
  934.                 return self.dialog.Restore(pluginid=ID_SELPOS, secret=sec_ref)

  935. class Selmir_Dialogue(gui.GeDialog) :
  936.         tol = 0.001
  937.         Xcon = True
  938.         Ycon = 0
  939.         Zcon = 0
  940.         ajsel = True
  941.         
  942.         def CreateLayout(self) :
  943.                 self.GroupBegin(10, c4d.BFH_SCALEFIT, 1, 3)
  944.                 self.GroupBorderSpace(5, 5, 5, 5)
  945.                
  946.                 self.GroupBegin(12, c4d.BFH_SCALEFIT, 3, 1)
  947.                 self.AddCheckbox(21, c4d.BFH_SCALEFIT, initw = 20, inith = 0, name = "-X")
  948.                 self.AddCheckbox(22, c4d.BFH_SCALEFIT, initw = 20, inith = 0, name = "-Y")
  949.                 self.AddCheckbox(23, c4d.BFH_SCALEFIT, initw = 20, inith = 0, name = "-Z")
  950.                 self.GroupEnd()
  951.                
  952.                 self.GroupBegin(15, c4d.BFH_SCALEFIT, 1, 1)
  953.                 self.AddCheckbox(24, c4d.BFH_SCALEFIT, initw = 0, inith = 0, name = txt(SS_SELMIR_AJS))
  954.                 self.GroupEnd()
  955.                
  956.                 self.GroupBegin(14, c4d.BFH_SCALEFIT, 2, 1)
  957.                 self.AddStaticText(13, c4d.BFH_SCALEFIT, name = txt(SS_SELMIR_TOL))
  958.                 self.AddEditNumberArrows(11, c4d.BFH_SCALEFIT)
  959.                
  960.                 self.AddButton(1, c4d.BFH_SCALEFIT, initw = 80, inith = 15, name = txt(SS_SS_VAL))
  961.                 self.AddButton(2, c4d.BFH_SCALEFIT, initw = 80, inith = 15, name = txt(SS_SS_FER))
  962.                 self.GroupEnd()
  963.                
  964.                 self.GroupEnd()
  965.                 return True
  966.         
  967.         def InitValues(self) :
  968.                 doc = documents.GetActiveDocument()
  969.                 obj = doc.GetActiveObject()
  970.                 self.SetTitle(txt(SS_SELMIR_NOM))
  971.                 self.SetMeter(11, self.tol, 0.0001, step = 0.01)
  972.                 self.SetBool(21, self.Xcon)
  973.                 self.SetBool(22, self.Ycon)
  974.                 self.SetBool(23, self.Zcon)
  975.                 self.SetBool(24, self.ajsel)
  976.                 return True
  977.         
  978.         def Command(self, id, msg) :
  979.                 if id == 11 : self.tol = self.GetReal(11)
  980.                 if id == 21 : self.Xcon = self.GetBool(21)
  981.                 if id == 22 : self.Ycon = self.GetBool(22)
  982.                 if id == 23 : self.Zcon = self.GetBool(23)
  983.                 if id == 24 : self.ajsel = self.GetBool(24)
  984.                 if id == 1 :
  985.                         self.tol = self.GetReal(11)
  986.                         self.Xcon = self.GetBool(21)
  987.                         self.Ycon = self.GetBool(22)
  988.                         self.Zcon = self.GetBool(23)
  989.                         doc = documents.GetActiveDocument()
  990.                         obj = doc.GetActiveObject()
  991.                         self.sel_mir(doc, obj)
  992.                 if id == 2 :
  993.                         self.Close()
  994.                 return True
  995.         
  996.         def _texte(self, vec, tol) :
  997.                 vec *= tol
  998.                 vec.x = int(vec.x)
  999.                 vec.y = int(vec.y)
  1000.                 vec.z = int(vec.z)
  1001.                 p_txt = str(int(vec.x)) + "." + str(int(vec.y)) + "." + str(int(vec.z))
  1002.                 return p_txt, vec
  1003.         
  1004.         def _centrepoly(self, obj, poly) :
  1005.                 centre = Vector()
  1006.                 centre += obj.GetPoint(poly.a)
  1007.                 centre += obj.GetPoint(poly.b)
  1008.                 centre += obj.GetPoint(poly.c)
  1009.                 if poly.c == poly.d :
  1010.                         centre /= 3.0
  1011.                 else :
  1012.                         centre += obj.GetPoint(poly.d)
  1013.                         centre *= 0.25
  1014.                 return centre
  1015.                
  1016.         def _centrearete(self, obj, poly, arete, polycen) :
  1017.                 centre = Vector()
  1018.                 aretes = [(poly.a, poly.b), (poly.b, poly.c), (poly.c, poly.d), (poly.d, poly.a)]
  1019.                 for i in xrange(2) :
  1020.                         centre += obj.GetPoint(aretes[arete][i])
  1021.                 centre = centre * 0.5 + polycen
  1022.                 return centre
  1023.         
  1024.         def sel_mir(self, doc, obj) :
  1025.                 if not obj : return
  1026.                 polygonal = obj.CheckType(c4d.Opolygon)
  1027.                 cerce = obj.CheckType(c4d.Ospline)
  1028.                 if not polygonal and not cerce : return
  1029.                 mode = doc.GetMode()
  1030.                 if cerce and mode != c4d.Mpoints : return
  1031.                
  1032.                 if mode == c4d.Mpoints :
  1033.                         bs = obj.GetPointS()
  1034.                         tab = obj.GetAllPoints()
  1035.                         nbp = obj.GetPointCount()
  1036.                         
  1037.                 elif mode == c4d.Medges :
  1038.                         bs = obj.GetEdgeS()
  1039.                         tab = obj.GetAllPolygons()
  1040.                         nbp = obj.GetPolygonCount()
  1041.                         
  1042.                 elif mode == c4d.Mpolygons :
  1043.                         bs = obj.GetPolygonS()
  1044.                         tab = obj.GetAllPolygons()
  1045.                         nbp = obj.GetPolygonCount()
  1046.                         
  1047.                 else :
  1048.                         return
  1049.                
  1050.                 if not bs or not nbp : return
  1051.                 nbsel = bs.GetCount()
  1052.                 if not nbsel : return
  1053.                
  1054.                 dic = {}
  1055.                 liste = []
  1056.                 tol = self.tol
  1057.                 itol = 1.0 / tol
  1058.                 Xcon = self.Xcon
  1059.                 Ycon = self.Ycon
  1060.                 Zcon = self.Zcon
  1061.                 Mpolys = c4d.Mpolygons
  1062.                 Maretes = c4d.Medges
  1063.                 _centrepoly = self._centrepoly
  1064.                 _centrearete = self._centrearete
  1065.                 _texte = self._texte
  1066.                
  1067.                 for i, p in enumerate(tab) :
  1068.                         if mode == Maretes :
  1069.                                 polycen = _centrepoly(obj, p)
  1070.                                 for j in xrange(4) :
  1071.                                         pt = _centrearete(obj, p, j, polycen)
  1072.                                         p_txt, vec = _texte(pt, itol)
  1073.                                         if (p_txt in dic) : dic[p_txt].append(i*4 + j)
  1074.                                         else : dic[p_txt] = [i*4 + j]
  1075.                                         liste.append(vec)
  1076.                         else :
  1077.                                 if mode == Mpolys : pt = _centrepoly(obj, p)
  1078.                                 else : pt = p
  1079.                                 p_txt, vec = _texte(pt, itol)
  1080.                                 if (p_txt in dic) : dic[p_txt].append(i)
  1081.                                 else : dic[p_txt] = [i]
  1082.                                 liste.append(vec)
  1083.                
  1084.                 doc.StartUndo()
  1085.                 doc.AddUndo(c4d.UNDOTYPE_CHANGE_SELECTION, obj)
  1086.                
  1087.                 if self.ajsel : bsAct = bs
  1088.                 else :
  1089.                         bsAct = bs.GetClone()
  1090.                         bs.DeselectAll()
  1091.                
  1092.                 if mode == Maretes : nbp = nbp * 4 + 4
  1093.                
  1094.                 for i, sel in enumerate(bsAct.GetAll(nbp)) :
  1095.                         if not sel : continue
  1096.                         
  1097.                         vec = liste[i]
  1098.                         if Xcon : vec.x *= -1
  1099.                         if Ycon : vec.y *= -1
  1100.                         if Zcon : vec.z *= -1
  1101.                         p_txt = str(int(vec.x)) + "." + str(int(vec.y)) + "." + str(int(vec.z))
  1102.                         
  1103.                         try :
  1104.                                 js = dic[p_txt]
  1105.                         except KeyError :
  1106.                                 pass
  1107.                         else :
  1108.                                 for j in js :
  1109.                                         bs.Select(j)
  1110.                
  1111.                 if mode == Maretes :
  1112.                         obj.ValidateEdgeSelection(bs)
  1113.                         
  1114.                 doc.EndUndo()
  1115.                 c4d.EventAdd()

  1116. class Selmir(plugins.CommandData) :
  1117.         dialog = None
  1118.         
  1119.         def Execute(self, doc) :
  1120.                 if self.dialog is None:
  1121.                         self.dialog = Selmir_Dialogue()
  1122.                 return self.dialog.Open(dlgtype=c4d.DLG_TYPE_ASYNC, pluginid=ID_SELMIR, defaulth=80, defaultw=100)

  1123.         def RestoreLayout(self, sec_ref):
  1124.                 if self.dialog is None:
  1125.                         self.dialog = Selmir_Dialogue()
  1126.                 return self.dialog.Restore(pluginid=ID_SELMIR, secret=sec_ref)


  1127. class Selpif_Dialogue(gui.GeDialog) :
  1128.         src = 123456
  1129.         chc = 0
  1130.         bool_src = False
  1131.         qte = 10
  1132.         bool_qte = False
  1133.         
  1134.         def CreateLayout(self) :
  1135.                 self.GroupBegin(100, c4d.BFH_SCALEFIT, 1, 1)
  1136.                 self.GroupBorderSpace(5, 5, 5, 5)
  1137.                
  1138.                 self.GroupBegin(101, c4d.BFH_SCALEFIT, 2, 2)
  1139.                 self.AddCheckbox(12, c4d.BFH_SCALEFIT, initw = 0, inith = 0, name = txt(SS_SELPIF_SRC))
  1140.                 self.AddEditNumberArrows(11, c4d.BFH_SCALEFIT)
  1141.                 self.AddCheckbox(16, c4d.BFH_SCALEFIT, initw = 0, inith = 0, name = txt(SS_SELPIF_QTE))
  1142.                 self.AddEditNumberArrows(15, c4d.BFH_SCALEFIT)
  1143.                 self.AddStaticText(13, c4d.BFH_SCALEFIT, name = txt(SS_SELPIF_CHC))
  1144.                 self.AddEditNumberArrows(14, c4d.BFH_SCALEFIT)
  1145.                 self.GroupEnd()
  1146.                
  1147.                 self.GroupBegin(102, c4d.BFH_SCALEFIT, 2, 2)
  1148.                 self.AddButton(1, c4d.BFH_SCALEFIT, initw = 70, inith = 15, name = txt(SS_SS_VAL))
  1149.                 self.AddButton(2, c4d.BFH_SCALEFIT, initw = 70, inith = 15, name = txt(SS_SS_FER))
  1150.                 self.GroupEnd()
  1151.                
  1152.                 self.GroupEnd()
  1153.                 return True
  1154.         
  1155.         def InitValues(self) :
  1156.                 self.SetTitle(txt(SS_SELPIF_NOM))
  1157.                 self.SetLong(11, self.src)
  1158.                 self.SetBool(12, self.bool_src)
  1159.                 self.SetLong(15, self.qte, 0)
  1160.                 self.SetBool(16, self.bool_qte)
  1161.                 self.SetLong(14, self.chc)
  1162.                 self.Enable(11, self.bool_src)
  1163.                 self.Enable(15, self.bool_qte)
  1164.                 self.Enable(14, not self.bool_qte)
  1165.                 self.Enable(11, self.bool_src)
  1166.                 return True
  1167.                
  1168.         def Command(self, id, msg) :
  1169.                 if id == 12 : self.Enable(11, self.GetBool(12))
  1170.                 if id == 16 :
  1171.                         self.Enable(15, self.GetBool(16))
  1172.                         self.Enable(14, not self.GetBool(16))
  1173.                
  1174.                 if id == 1 :
  1175.                         self.src = self.GetLong(11)
  1176.                         self.bool_src = self.GetBool(12)
  1177.                         self.qte = self.GetLong(15)
  1178.                         self.bool_qte = self.GetBool(16)
  1179.                         self.chc = self.GetLong(14)
  1180.                         doc = documents.GetActiveDocument()
  1181.                         obj = doc.GetActiveObject()
  1182.                         self.sel_pif(doc, obj)
  1183.                 if id == 2 :
  1184.                         self.Close()
  1185.                 return True
  1186.         
  1187.         def sel_pif(self, doc, obj) :
  1188.                 if not obj : return
  1189.                 polygonal = obj.CheckType(c4d.Opolygon)
  1190.                 cerce = obj.CheckType(c4d.Ospline)
  1191.                 if not polygonal and not cerce : return
  1192.                 mode = doc.GetMode()
  1193.                 if mode != c4d.Mpoints and mode != c4d.Mpolygons : return
  1194.                 if mode == c4d.Mpolygons and cerce : return
  1195.                
  1196.                 if mode == c4d.Mpoints :
  1197.                         points = True
  1198.                         bs = obj.GetPointS()
  1199.                 else :
  1200.                         points = False
  1201.                         bs = obj.GetPolygonS()
  1202.                
  1203.                 nbsel = bs.GetCount()
  1204.                 if points : nbp = obj.GetPointCount()
  1205.                 else : nbp = obj.GetPolygonCount()
  1206.                
  1207.                 doc.StartUndo()
  1208.                 doc.AddUndo(c4d.UNDOTYPE_CHANGE_SELECTION, obj)
  1209.                 src = self.src
  1210.                 chc = abs(self.chc) + 1
  1211.                 qte = self.qte
  1212.                 if qte > nbp : qte = nbp
  1213.                 bs.DeselectAll()
  1214.                
  1215.                 if self.bool_src : random.seed(src)
  1216.                
  1217.                 if self.bool_qte :
  1218.                         liste = [0] * nbp
  1219.                         for i in xrange(qte) : liste[i] = 1
  1220.                         random.shuffle(liste)
  1221.                         bs.SetAll(liste)
  1222.                
  1223.                 else :
  1224.                         if self.chc > 0 :
  1225.                                 for i in xrange(nbp) :
  1226.                                         pif = random.randint(0, chc)
  1227.                                         if pif : bs.Select(i)
  1228.                         else :
  1229.                                 for i in xrange(nbp) :
  1230.                                         pif = random.randint(0, chc)
  1231.                                         if not pif : bs.Select(i)
  1232.                         
  1233.                 doc.EndUndo()
  1234.                 c4d.EventAdd()

  1235. class Selpif(plugins.CommandData) :
  1236.         dialog = None
  1237.         
  1238.         def Execute(self, doc) :
  1239.                 if self.dialog is None:
  1240.                         self.dialog = Selpif_Dialogue()
  1241.                 return self.dialog.Open(dlgtype=c4d.DLG_TYPE_ASYNC, pluginid=ID_SELPIF, defaulth=100, defaultw=70)

  1242.         def RestoreLayout(self, sec_ref):
  1243.                 if self.dialog is None:
  1244.                         self.dialog = Selpif_Dialogue()
  1245.                 return self.dialog.Restore(pluginid=ID_SELPIF, secret=sec_ref)


  1246. class SelSup(plugins.CommandData) :
  1247.         pass

  1248. def icone(nom) :
  1249.         bmp = bitmaps.BaseBitmap()
  1250.         dir, file = os.path.split(__file__)
  1251.         fn = os.path.join(dir, "res", nom)
  1252.         bmp.InitWith(fn)
  1253.         return bmp

  1254. if __name__ == "__main__":
  1255.         plugins.RegisterCommandPlugin(id=ID_SELNSN, str = "#$00" + txt(SS_SELNSN_NOM), info = 0, help = txt(SS_SELNSN_AID), dat = Selnsn(), icon = icone("selnsn.tif"))
  1256.         plugins.RegisterCommandPlugin(id=ID_SELADJ, str = "#$01" + txt(SS_SELADJ_NOM), info = 0, help = txt(SS_SELADJ_AID), dat = Seladj(), icon = icone("seladj.tif"))
  1257.         plugins.RegisterCommandPlugin(id=ID_SELPIF, str = "#$02" + txt(SS_SELPIF_NOM), info = 0, help = txt(SS_SELPIF_AID), dat = Selpif(), icon = icone("selpif.tif"))
  1258.         plugins.RegisterCommandPlugin(id=ID_SELMIR, str = "#$03" + txt(SS_SELMIR_NOM), info = 0, help = txt(SS_SELMIR_AID), dat = Selmir(), icon = icone("selmir.tif"))
  1259.         plugins.RegisterCommandPlugin(id=ID_SELDIR, str = "#$04" + txt(SS_SELDIR_NOM), info = 0, help = txt(SS_SELDIR_AID), dat = Seldir(), icon = icone("seldir.tif"))
  1260.         plugins.RegisterCommandPlugin(id=ID_SELTAIL, str = "#$05" + txt(SS_SELTAIL_NOM), info = 0, help = txt(SS_SELTAIL_AID), dat = Seltail(), icon = icone("seltail.tif"))
  1261.         plugins.RegisterCommandPlugin(id=ID_SELTRI, str = "#$06" + txt(SS_SELTRI_NOM), info = 0, help = txt(SS_SELTRI_AID), dat = Seltri(), icon = icone("seltri.tif"))
  1262.         plugins.RegisterCommandPlugin(id=ID_SELQUAD, str = "#$07" + txt(SS_SELQUAD_NOM), info = 0, help = txt(SS_SELQUAD_AID), dat = Selquad(), icon = icone("selquad.tif"))
  1263.         plugins.RegisterCommandPlugin(id=ID_SELNGON, str = "#$08" + txt(SS_SELNGON_NOM), info = 0, help = txt(SS_SELNGON_AID), dat = Selngon(), icon = icone("selngon.tif"))
  1264.         plugins.RegisterCommandPlugin(id=ID_SELCON, str = "#$09" + txt(SS_SELCON_NOM), info = 0, help = txt(SS_SELCON_AID), dat = Selcon(), icon = icone("selcon.tif"))
  1265.         plugins.RegisterCommandPlugin(id=ID_SELIND, str = "#$10" + txt(SS_SELIND_NOM), info = 0, help = txt(SS_SELIND_AID), dat = Selind(), icon = icone("selind.tif"))
  1266.         plugins.RegisterCommandPlugin(id=ID_SELPOS, str = "#$11" + txt(SS_SELPOS_NOM), info = 0, help = txt(SS_SELPOS_AID), dat = Selpos(), icon = icone("selpos.tif"))
  1267.         plugins.RegisterCommandPlugin(id=SEPARATEUR_ID, str = "#$12--", info = 0, help = "vonc_selsup", dat = SelSup(), icon = None)
  1268.         plugins.RegisterCommandPlugin(id=MODULE_ID, str = "#$13v 1.8 - http://code.vonc.fr", info = 0, help = "http://code.vonc.fr", dat = SelSup(), icon = icone("selsup.tif"))
复制代码
Fichier H :
  1. enum
  2. {
  3.         SS_SS_VAL                        = 101,
  4.         SS_SS_FER                        = 102,
  5.         
  6.         SS_SELDIR_NOM                = 1001,
  7.     SS_SELDIR_TOL                = 1002,
  8.         SS_SELDIR_LIM                = 1003,
  9.         SS_SELDIR_AID                = 1004,
  10.         SS_SELDIR_NOR                = 1005,
  11.         
  12.         SS_SELNSN_NOM                = 1101,
  13.         SS_SELNSN_SEL                = 1102,
  14.         SS_SELNSN_SUR                = 1103,
  15.         SS_SELNSN_DEC                = 1104,
  16.         SS_SELNSN_AID                = 1105,
  17.         
  18.         SS_SELTAIL_NOM                = 1201,
  19.         SS_SELTAIL_TOL                = 1202,
  20.         SS_SELTAIL_INF                = 1203,
  21.         SS_SELTAIL_SUP                = 1204,
  22.         SS_SELTAIL_AID                = 1205,
  23.         
  24.         SS_SELTRI_NOM                = 1301,
  25.         SS_SELTRI_AID                = 1302,
  26.         
  27.         SS_SELQUAD_NOM                = 1401,
  28.         SS_SELQUAD_AID                = 1402,
  29.         
  30.         SS_SELNGON_NOM                = 1501,
  31.         SS_SELNGON_AID                = 1502,
  32.         
  33.         SS_SELCON_NOM                = 1601,
  34.         SS_SELCON_AID                = 1602,
  35.         
  36.         SS_SELIND_NOM                = 1701,
  37.         SS_SELIND_AID                = 1702,
  38.         
  39.         SS_SELADJ_NOM                = 1801,
  40.         SS_SELADJ_AID                = 1802,
  41.         
  42.         SS_SELPOS_NOM                = 1901,
  43.         SS_SELPOS_TOL                = 1902,
  44.         SS_SELPOS_AID                = 1903,
  45.         
  46.         SS_SELPIF_NOM                = 2001,
  47.         SS_SELPIF_AID                = 2002,
  48.         SS_SELPIF_SRC                = 2003,
  49.         SS_SELPIF_QTE                = 2004,
  50.         SS_SELPIF_CHC                = 2005,
  51.         
  52.         SS_SELMIR_NOM                = 2101,
  53.         SS_SELMIR_AID                = 2102,
  54.         SS_SELMIR_TOL                = 2103,
  55.         SS_SELMIR_AJS                = 2104,
  56.         
  57.         _DUMMY_ELEMENT_
  58. }
复制代码
Fichier STR :
  1. STRINGTABLE
  2. {
  3.         SS_SS_VAL                        "Appliquer";
  4.         SS_SS_FER                        "Fermer";
  5.         
  6.         SS_SELDIR_NOM                "S\u00E9lectionner les polys de m\u00EAme orientation";
  7.         SS_SELDIR_TOL                "Tol\u00E9rance :";
  8.         SS_SELDIR_LIM                "Limiter aux \u00E9l\u00E9ments connect\u00E9s";
  9.         SS_SELDIR_NOR                "D\u00E9finir la normale";
  10.         SS_SELDIR_AID                "S\u00E9lectionne les polygones ayant la m\u00EAme normale que le polygone s\u00E9lectionn\u00E9.";
  11.         
  12.         SS_SELNSN_NOM                "S\u00E9lectionner les \u00E9l\u00E9ments alternativement";
  13.         SS_SELNSN_SEL                "S\u00E9lectionner :";
  14.         SS_SELNSN_SUR                "Sur :";
  15.         SS_SELNSN_DEC                "D\u00E9calage :";
  16.         SS_SELNSN_AID                "S\u00E9lectionne les polygones ou les points \u00E0 intervalle r\u00E9gulier \u00E0 partir de la s\u00E9lection active.";
  17.         
  18.         SS_SELTAIL_NOM                "S\u00E9lectionner les polys de m\u00EAme taille";
  19.         SS_SELTAIL_TOL                "Tol\u00E9rance :";
  20.         SS_SELTAIL_INF                "Inclure les tailles inf\u00E9rieures";
  21.         SS_SELTAIL_SUP                "Inclure les tailles sup\u00E9rieures";
  22.         SS_SELTAIL_AID                "S\u00E9lectionne tous les polygones ayant plus ou moins le m\u00EAme p\u00E9rim\u00E8tre que le polygone s\u00E9lectionn\u00E9.";
  23.         
  24.         SS_SELTRI_NOM                "S\u00E9lectionner les triangles";
  25.         SS_SELTRI_AID                "S\u00E9lectionne tous les triangles de l'objet actif.";
  26.         
  27.         SS_SELQUAD_NOM                "S\u00E9lectionner les quadrangles";
  28.         SS_SELQUAD_AID                "S\u00E9lectionne tous les quadrangles de l'objet actif.";
  29.         
  30.         SS_SELNGON_NOM                "S\u00E9lectionner les n-gones";
  31.         SS_SELNGON_AID                "S\u00E9lectionne tous les n-gones de l'objet actif.";
  32.         
  33.         SS_SELCON_NOM                "S\u00E9lectionner les contours";
  34.         SS_SELCON_AID                "S\u00E9lectionne tous les contours de l'objet actif.";
  35.         
  36.         SS_SELIND_NOM                "S\u00E9lectionner jusqu'\u00E0 l'indice";
  37.         SS_SELIND_AID                "S\u00E9lectionne tous les polygones ou tous les points d'indice inf\u00E9rieur au polygone/point s\u00E9lectionn\u00E9 d'un objet ou d'une cerce (spline).";
  38.         
  39.         SS_SELADJ_NOM                "S\u00E9lectionner les \u00E9l\u00E9ments adjacents";
  40.         SS_SELADJ_AID                "S\u00E9lectionne les polygones ou les points adjacents \u00E0 la s\u00E9lection active.";
  41.         
  42.         SS_SELPOS_NOM                "S\u00E9lectionner jusqu'\u00E0 la position";
  43.         SS_SELPOS_TOL                "Tol\u00E9rance :";
  44.         SS_SELPOS_AID                "S\u00E9lectionne les points ou les polygones ayant une position sup\u00E9rieure ou inf\u00E9rieure \u00E0 un point donn\u00E9.";
  45.         
  46.         SS_SELPIF_NOM                "S\u00E9lectionner les \u00E9l\u00E9ments al\u00E9atoirement";
  47.         SS_SELPIF_AID                "S\u00E9lectionne des polygones ou des points de fa\u00E7on al\u00E9atoire.";
  48.         SS_SELPIF_SRC                "Source :";
  49.         SS_SELPIF_QTE                "Quantit\u00E9 :";
  50.         SS_SELPIF_CHC                "Chances :";
  51.         
  52.         SS_SELMIR_NOM                "S\u00E9lectionner les \u00E9l\u00E9ments par miroir";
  53.         SS_SELMIR_AID                "S\u00E9lectionne les points, ar\u00EAtes ou polygones oppos\u00E9s par rapport l'axe.";
  54.         SS_SELMIR_TOL                "Tol\u00E9rance :";
  55.         SS_SELMIR_AJS                "Ajouter \u00E0 la s\u00E9lection";
  56. }
复制代码

点击下载图标
下载等级
C8D
登录后下载


插件脚本
软件性质:  
适用版本: C4D R15 - C4D R16 - C4D R17 - C4D R18 - C4D R19 - C4D R20 - C4D R21 - C4D S22 - C4D R23 - C4D S24 - C4D R25 - C4D S26 - C4D 2023 - C4D 2024 - C4D 2025
软件版本: Sélections Supplétives - v 1.8
系统平台: Win MAC 
软件语言: 汉化 
插件来源: https://www.c4d.cn/c4dsoft.html
百套精美Kitbash3D模型专题合集下载
时尚卡通办公室人物C4D立体图标工程下载Cinema 4D Fashion Cartoon Office Character 3D Icon Project Download
C4D科技新闻片头电视栏目频道包装动画工程下载Cinema 4D Technology News Headline TV Program Channel Packaging Animation Project Download
关闭

C4D精选推荐 上一条 /10 下一条

智能
客服
快速回复 返回顶部 返回列表