SemenG

Линии по траектории электрической цепи

Mar 26th, 2018
297
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import clr
  2. clr.AddReference("RevitServices")
  3. import RevitServices
  4. from RevitServices.Persistence import DocumentManager
  5. from RevitServices.Transactions import TransactionManager
  6. doc = DocumentManager.Instance.CurrentDBDocument
  7.  
  8. clr.AddReference('RevitAPI')
  9. import Autodesk
  10. from Autodesk.Revit.DB import *
  11.  
  12. clr.AddReference('ProtoGeometry')
  13. from Autodesk.DesignScript.Geometry import *
  14.  
  15. cirs = IN[0] # цепи
  16.  
  17. circuitPaths = [] # Достаём траектории каждой цепи
  18. for cir in UnwrapElement(cirs):
  19.     circuitPaths.append(cir.GetCircuitPath())
  20.  
  21. pointsAsStr = [] # Перевод данных из незнакомого мне формата в строку
  22. for circuitPath in circuitPaths:
  23.     sublist = []
  24.     for xyz in circuitPath:
  25.         sublist.append(str(xyz).replace('(','').replace(')',''))
  26.     pointsAsStr.append(sublist)
  27.  
  28. k = 304.8 # в 1 футе k мм
  29.  
  30. points = [] # Из строк делаем Points
  31. for path in pointsAsStr:
  32.     sublist = []
  33.     for i in path:
  34.         x = float(i.split(',')[0])
  35.         y = float(i.split(',')[1])
  36.         z = float(i.split(',')[2])
  37.         sublist.append(Point.ByCoordinates(x*k, y*k, z*k))
  38.     points.append(sublist)
  39.  
  40. lines = [] # Из Points делаем Lines
  41. for path in points:
  42.     sublist = []
  43.     for i, p in enumerate(path):
  44.         try:
  45.             sublist.append(Line.ByStartPointEndPoint(path[i], path[i+1]))
  46.         except IndexError:
  47.             continue
  48.     lines.append(sublist)
  49.  
  50. OUT = lines
RAW Paste Data