Guest User

Untitled

a guest
Mar 23rd, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.63 KB | None | 0 0
  1. from ghpythonlib.componentbase import dotnetcompiledcomponent as component
  2. import Grasshopper, GhPython
  3. import System
  4. import Rhino
  5. import rhinoscriptsyntax as rs
  6.  
  7. class SortPointEx(component):
  8. def __new__(cls):
  9. instance = Grasshopper.Kernel.GH_Component.__new__(cls,
  10. "Python", "SortPointEx", """GhPython provides a Python script component""", "Extra", "test")
  11. return instance
  12.  
  13. def get_ComponentGuid(self):
  14. return System.Guid("GUID")
  15.  
  16. def SetUpParam(self, p, name, nickname, description):
  17. p.Name = name
  18. p.NickName = nickname
  19. p.Description = description
  20. p.Optional = True
  21.  
  22. def RegisterInputParams(self, pManager):
  23. p = Grasshopper.Kernel.Parameters.Param_Point()
  24. self.SetUpParam(p, "Points", "Points", "Script variable Python")
  25. p.Access = Grasshopper.Kernel.GH_ParamAccess.list
  26. self.Params.Input.Add(p)
  27.  
  28. p = Grasshopper.Kernel.Parameters.Param_Integer()
  29. self.SetUpParam(p, "SortType", "SortType", "Script input SortType.")
  30. p.Access = Grasshopper.Kernel.GH_ParamAccess.item
  31. self.Params.Input.Add(p)
  32.  
  33.  
  34. def RegisterOutputParams(self, pManager):
  35. p = Grasshopper.Kernel.Parameters.Param_GenericObject()
  36. self.SetUpParam(p, "P", "P", "Script output P.")
  37. self.Params.Output.Add(p)
  38.  
  39. p = Grasshopper.Kernel.Parameters.Param_GenericObject()
  40. self.SetUpParam(p, "I", "I", "Script output I.")
  41. self.Params.Output.Add(p)
  42.  
  43.  
  44. def SolveInstance(self, DA):
  45. p0 = self.marshal.GetInput(DA, 0)
  46. p1 = self.marshal.GetInput(DA, 1)
  47. result = self.RunScript(p0, p1)
  48.  
  49. if result is not None:
  50. if not hasattr(result, '__getitem__'):
  51. self.marshal.SetOutput(result, DA, 0, True)
  52. else:
  53. self.marshal.SetOutput(result[0], DA, 0, True)
  54. self.marshal.SetOutput(result[1], DA, 1, True)
  55.  
  56. def get_Internal_Icon_24x24(self):
  57. o = "アイコン"
  58. return System.Drawing.Bitmap(System.IO.MemoryStream(System.Convert.FromBase64String(o)))
  59.  
  60.  
  61. def RunScript(self, Points, SortType):
  62. #点をソートする処理
  63.  
  64. # return outputs if you have them; here I try it for you:
  65. return (P, I)
  66.  
  67.  
  68. import SortPath as sp
  69.  
  70. class DisplaySortResult(component):
  71. def __new__(cls):
  72. instance = Grasshopper.Kernel.GH_Component.__new__(cls,
  73. "SortResDis", "DisplaySortResult", """GhPython provides a Python script component""", "Extra", "test")
  74. return instance
  75.  
  76. def get_ComponentGuid(self):
  77. return System.Guid("GUID")
  78.  
  79. def SetUpParam(self, p, name, nickname, description):
  80. p.Name = name
  81. p.NickName = nickname
  82. p.Description = description
  83. p.Optional = True
  84.  
  85. def RegisterInputParams(self, pManager):
  86. p = Grasshopper.Kernel.Parameters.Param_Point()
  87. self.SetUpParam(p, "Points", "Points", "Script variable Python")
  88. p.Access = Grasshopper.Kernel.GH_ParamAccess.list
  89. self.Params.Input.Add(p)
  90.  
  91. p = Grasshopper.Kernel.Parameters.Param_GenericObject()
  92. self.SetUpParam(p, "Reset", "Reset", "Script input Reset.")
  93. p.Access = Grasshopper.Kernel.GH_ParamAccess.item
  94. self.Params.Input.Add(p)
  95.  
  96. p = Grasshopper.Kernel.Parameters.Param_Integer()
  97. self.SetUpParam(p, "Speed", "Speed", "Script input Speed.")
  98. p.Access = Grasshopper.Kernel.GH_ParamAccess.item
  99. self.Params.Input.Add(p)
  100.  
  101.  
  102. def RegisterOutputParams(self, pManager):
  103. p = Grasshopper.Kernel.Parameters.Param_GenericObject()
  104. self.SetUpParam(p, "T", "T", "Script output T.")
  105. self.Params.Output.Add(p)
  106.  
  107. p = Grasshopper.Kernel.Parameters.Param_GenericObject()
  108. self.SetUpParam(p, "C", "C", "Script output C.")
  109. self.Params.Output.Add(p)
  110.  
  111. p = Grasshopper.Kernel.Parameters.Param_GenericObject()
  112. self.SetUpParam(p, "P", "P", "Script output P.")
  113. self.Params.Output.Add(p)
  114.  
  115. p = Grasshopper.Kernel.Parameters.Param_GenericObject()
  116. self.SetUpParam(p, "Pl", "Pl", "Script output Pl.")
  117. self.Params.Output.Add(p)
  118.  
  119.  
  120. def SolveInstance(self, DA):
  121. p0 = self.marshal.GetInput(DA, 0)
  122. p1 = self.marshal.GetInput(DA, 1)
  123. p2 = self.marshal.GetInput(DA, 2)
  124. result = self.RunScript(p0, p1, p2)
  125.  
  126. if result is not None:
  127. if not hasattr(result, '__getitem__'):
  128. self.marshal.SetOutput(result, DA, 0, True)
  129. else:
  130. self.marshal.SetOutput(result[0], DA, 0, True)
  131. self.marshal.SetOutput(result[1], DA, 1, True)
  132. self.marshal.SetOutput(result[2], DA, 2, True)
  133. self.marshal.SetOutput(result[3], DA, 3, True)
  134.  
  135. def get_Internal_Icon_24x24(self):
  136. o = "アイコン2"
  137. return System.Drawing.Bitmap(System.IO.MemoryStream(System.Convert.FromBase64String(o)))
  138. def __init__(self):
  139. self.createPl = sp.SortPath()
  140.  
  141. def RunScript(self, Points, Reset, Speed):
  142. #ソートされたパスを描画する処理
  143.  
  144. # return outputs if you have them; here I try it for you:
  145. return (T, C, P, Pl)
  146.  
  147.  
  148. class AssemblyInfo(GhPython.Assemblies.PythonAssemblyInfo):
  149. def get_AssemblyName(self):
  150. return "SortPointsEx"
  151.  
  152. def get_AssemblyDescription(self):
  153. return """"""
  154.  
  155. def get_AssemblyVersion(self):
  156. return "0.1"
  157.  
  158. def get_AuthorName(self):
  159. return ""
  160.  
  161. def get_Id(self):
  162. return System.Guid("GUID")
Add Comment
Please, Sign In to add comment