Chào mừng các bác đã ghé thăm blog của mình.😄

Tại sao lại có chia sẻ này ?

Mình ngó sơ qua các bài của mọi người gửi cho mình trợ giúp đều không có, vì đa số viết chạy một lần.Nhưng với cách trình bày này, mình có thể lưu trữ lại sử dụng và gợi nhớ lâu hơn, người khác nhìn vào cũng cảm thấy chuyên nghiệp, người sử dụng cũng dễ dàng nắm bắt và sử dụng tệp không phải do họ tạo ra.


Tải xuống

Dynamo Template cho người dùng UI

DynamoTemplate

Liên kết tải xuống : Here

Dynamo Template cho người dùng viết mã

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
clr.AddReference('System')
from System.Collections.Generic import List
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
import System
from System.Collections.Generic import *
import sys
sys.path.append(r'C:\Program Files (x86)\IronPython 2.7\Lib')
doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = DocumentManager.Instance.CurrentUIApplication.Application
def tolist(obj1):
if hasattr(obj1,'__iter__') : return obj1
else : return [obj1]
# toList = lambda x : x if hasattr(x, '__iter__') else [x]
# element = toList(UnwrapElement(IN[0]))
def flatten(x):
result = []
for el in x:
if hasattr(el, "__iter__") and not isinstance(el, basestring):
result.extend(flatten(el))
else:
result.append(el)
return result
#Preparing input from dynamo to revit
element = UnwrapElement(tolist(IN[0]))
#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
#Do Action
TransactionManager.Instance.TransactionTaskDone()
OUT = element

Thiết lập mặc định

Để thiết lập mặc định rất đơn giản, bạn tạo một tệp với tên dynamo template.py và dán vào vị trí này, tùy vào tên người dùng trên máy tính của bạn mà đường dẫn sẽ thay đổi:

 Image 31103942 8a2a 4dd9 b84e 925b581a4693

Sau đó bạn sửa một tệp DynamoSettings.xml tại vị trí đường dẫn cùng cấp ở thẻ PythonTemplateFilePath, đường dẫn chính là đường dẫn của tệp dynamotemplate.py mà bạn vừa tạo.

<PythonTemplateFilePath>
<string>C:\Users\CURRENTUSER\AppData\Roaming\Dynamo\Dynamo Core\2.0\PythonTemplate.py</string>
</PythonTemplateFilePath>

Hình ảnh trên máy tính cá nhân của mình.

 Image 7e54c1b3 0679 4450 bdca 979dd656663a

Tổng kết

Trên đây chỉ là mẫu cá nhân phù hợp mà theo quan điểm cá nhân của mình nên có thể sẽ không phù hợp với từng nhu cầu của mỗi người, vì vậy việc chỉnh sửa biến hoá theo ý muốn là của các bạn.Cám ơn các bạn đã ghé thăm blog.

Tham khảo :

Python-Templates