-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLine.py
More file actions
115 lines (99 loc) · 4.03 KB
/
Line.py
File metadata and controls
115 lines (99 loc) · 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import clr
import System
import math
from System.Collections.Generic import *
clr.AddReference("ProtoGeometry")
from Autodesk.DesignScript.Geometry import *
from Autodesk.DesignScript.Geometry import PolyCurve, Line
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import*
from Autodesk.Revit.UI.Selection import*
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from Autodesk.DesignScript.Geometry import Line
doc = DocumentManager.Instance.CurrentDBDocument
view = doc.ActiveView
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
#########################################################################
def getXyzItemsByOffsetPointsFromDbLines(lines, deltaX = 0, deltaY = 0, deltaZ =0):
xyzItems = []
for line in lines:
startPoint = line.GetEndPoint(0)
endPoint = line.GetEndPoint(1)
newStartPoint = XYZ(startPoint.X - deltaX, startPoint.Y - deltaY,startPoint.Z - deltaZ )
endStartPoint = XYZ(endPoint.X - deltaX, endPoint.Y - deltaY,endPoint.Z - deltaZ )
xyzItems.append([newStartPoint, endStartPoint])
return xyzItems
deltaX = IN[1]/304.8
deltaY = IN[2]/304.8
deltaZ = IN[3]/304.8
OUT = getXyzItemsByOffsetPointsFromDbLines(IN[0], deltaX, deltaY, deltaZ)
#########################################################################
def moveLinesByVector(lines, vector):
newLines = []
for line in lines:
newStartPoint = line.StartPoint.Add(vector)
newEndPoint = line.EndPoint.Add(vector)
newLine = Line.ByStartPointEndPoint(newStartPoint, newEndPoint)
newLines.append(newLine)
return newLines
# elements = [UnwrapElement(IN[0])] if not isinstance(IN[0], list) else UnwrapElement(IN[0])
# xTranslation = IN[1]
# yTranslation = IN[2]
# zTranslation = IN[3]
# vector = Vector.ByCoordinates(xTranslation, yTranslation, zTranslation)
# OUT = moveLinesByVector(elements, vector)
def offsetLines(lines, offsetDistanceMM):
offsetDistanceFeet = offsetDistanceMM / 304.8
offsetLines = []
for line in lines:
# Calculate the normal vector of the line
direction = line.Direction
normal = Vector.ByCoordinates(-direction.Y, direction.X, 0)
# Create new points based on the offset
startOffset = line.StartPoint.Add(normal.Scale(offsetDistanceFeet))
endOffset = line.EndPoint.Add(normal.Scale(offsetDistanceFeet))
# Create new line from start to end points
offsetLine = Line.ByStartPointEndPoint(startOffset, endOffset)
offsetLines.append(offsetLine)
return offsetLines
def createLinesByTwoPoints(p1,p2):
line = Line.ByStartPointEndPoint(p1,p2)
return line
def getStartPointsAndEndPoints(lines):
return [line.StartPoint for line in lines], [line.EndPoint for line in lines]
def convertGridsToDbLines(grids):
revitLines = []
for grid in grids:
curve = grid.Curve # Sử dụng phương thức asCurve() để chuyển đối tượng Edge thành Curve
revitLines.append(curve)
return revitLines
def divideLines(lines, number=2):
all_points = []
for line in lines:
points = []
for j in range(number):
param = j / float(number - 1)
point = line.Evaluate(param, True)
points.append(point)
all_points.append(points)
return all_points
def pointOnLineAtParam(line, params):
startPoint = line.StartPoint
endPoint = line.EndPoint
points = []
for param in params:
x = startPoint.X + (endPoint.X - startPoint.X) * param
y = startPoint.Y + (endPoint.Y - startPoint.Y) * param
z = startPoint.Z + (endPoint.Z - startPoint.Z) * param
points.append(XYZ(x / 304.84, y / 304.84, z / 304.84))
return points