Revit API / Dynamo脚本中的MullionType错误

标准

我正在研究一个Python脚本,该脚本接受一组输入线,并将竖框分配给它们相交的相应网格线。但是,我收到一个奇怪的错误:

*预期的竖框类型,获得的家庭类型*

我不知道该如何在脚本结尾处进行更正。Python告诉我,它期望使用MullionType并获得Family类型(见图)。我使用的是Spring Nodes的Collector.WallTypes的修改版本,它代替了收集竖框类型,但是节点的输出是Family Type,该脚本不接受。知道如何将竖框类型输入到最终的Python节点吗?

SpringNodes脚本:

#Copyright(c) 2016, Dimitar Venkov
# @5devene, [email protected]

import clr

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument

clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

def tolist(obj1):
    if hasattr(obj1,"__iter__"): return obj1
    else: return [obj1]

fn = tolist(IN[0])
fn = [str(n) for n in fn]
result, similar, names = [], [], []

fec = FilteredElementCollector(doc).OfClass(MullionType)
for i in fec:
    n1 = Element.Name.__get__(i)
    names.append(n1)
    if any(fn1 == n1 for fn1 in fn):
        result.append(i.ToDSType(True))
    elif any(fn1.lower() in n1.lower() for fn1 in fn):
        similar.append(i.ToDSType(True))

if len(result) > 0:
    OUT = result,similar
if len(result) == 0 and len(similar) > 0:
    OUT = "No exact match found. Check partial below:",similar
if len(result) == 0 and len(similar) == 0:
    OUT = "No match found! Check names below:", names

即使收集器用于竖框类型,SpringNodes脚本也会输出Family Type(请参见上图)

这是我的脚本:

import clr

# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

# Import ToDSType(bool) extension method

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.GeometryConversion)

from System import Array
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

import math 

doc =  DocumentManager.Instance.CurrentDBDocument
app =  DocumentManager.Instance.CurrentUIApplication.Application


walls = UnwrapElement(IN[0])
toggle = IN[1]
inputLine = IN[2]
mullionType = IN[3]

wallSrf = []
heights = []
finalPoints = []
directions = []
isPrimary = []
projectedCrvs = []
keySegments = []
keySegmentsGeom = []
gridSegments = []
gridSegmentsGeom = []
gridLines = []
gridLinesGeom = []
keyGridLines = []
keyGridLinesGeom = []
projectedGridlines = []
lineDirections = []
gridLineDirection = []
allTrueFalse = []


if toggle == True:

    TransactionManager.Instance.EnsureInTransaction(doc)

    for w, g in zip(walls,inputLine):
        pointCoords = []
        primary = []

        ## Get curtain wall element sketch line

        originLine = Revit.GeometryConversion.RevitToProtoCurve.ToProtoType( w.Location.Curve, True )
        originLineLength = w.Location.Curve.ApproximateLength

        ## Get curtain wall element height, loft to create surface

        for p in w.Parameters:
            if p.Definition.Name == 'Unconnected Height':       
                height = p.AsDouble()   
        topLine = originLine.Translate(0,0,height)
        srfCurves = [originLine,topLine]
        wallSrf = NurbsSurface.ByLoft(srfCurves)

        ## Get centerpoint of curve, determine whether it extends across entire gridline

        projectedCrvCenterpoint = []

        for d in g:

            lineDirection = d.Direction.Normalized()
            lineDirections.append(lineDirection)
            curveProject= d.PullOntoSurface(wallSrf)
            if abs(lineDirection.Z) == 1:
                if curveProject.Length >= height-.5:
                    primary.append(False)
                else:
                    primary.append(True)
            else:
                if curveProject.Length >= originLineLength-.5:
                    primary.append(False)
                else:
                    primary.append(True)
            centerPoint = curveProject.PointAtParameter(0.5)
            pointList = []
            projectedCrvCenterpoint.append(centerPoint)

            ## Project centerpoint of curve onto wall surface

            for h in [centerPoint]:
                pointUnwrap = UnwrapElement(centerPoint)
                pointList.append(pointUnwrap.X)
                pointList.append(pointUnwrap.Y)
                pointList.append(pointUnwrap.Z)
            pointCoords.append(pointList)
        finalPoints.append(pointCoords)
        isPrimary.append(primary)
        projectedCrvs.append(projectedCrvCenterpoint)


    TransactionManager.Instance.TransactionTaskDone()       
    TransactionManager.Instance.EnsureInTransaction(doc)

    ##Gather all segments of gridline geometry

    for wall in UnwrapElement(walls):   
        gridSegments2 = []
        gridSegmentsGeom2 = []
        gridLines1 = []
        gridLinesGeom1 = []
        for id1 in wall.CurtainGrid.GetVGridLineIds():
            gridLinesGeom1.append(Revit.GeometryConversion.RevitToProtoCurve.ToProtoType(doc.GetElement(id1).FullCurve))
            gridLines1.append(doc.GetElement(id1))
            VgridSegments1 = []
            VgridSegmentsGeom1 = []
            for i in doc.GetElement(id1).AllSegmentCurves:
                VgridSegments1.append(i)
                VgridSegmentsGeom1.append(Revit.GeometryConversion.RevitToProtoCurve.ToProtoType(i,True))
            gridSegments2.append(VgridSegments1)
            gridSegmentsGeom2.append(VgridSegmentsGeom1)
        for id2 in wall.CurtainGrid.GetUGridLineIds():
            gridLinesGeom1.append(Revit.GeometryConversion.RevitToProtoCurve.ToProtoType(doc.GetElement(id2).FullCurve))
            gridLines1.append(doc.GetElement(id2))
            UgridSegments1 = []
            UgridSegmentsGeom1 = []
            for i in doc.GetElement(id2).AllSegmentCurves:
                UgridSegments1.append(i)
                UgridSegmentsGeom1.append(Revit.GeometryConversion.RevitToProtoCurve.ToProtoType(i,True))
            gridSegments2.append(UgridSegments1)
            gridSegmentsGeom2.append(UgridSegmentsGeom1)    
        gridSegments.append(gridSegments2)
        gridSegmentsGeom.append(gridSegmentsGeom2)
        gridLines.append(gridLines1)
        gridLinesGeom.append(gridLinesGeom1)

    boolFilter = [[[[b.DoesIntersect(x) for x in d] for d in z] for b in a] for a,z in zip(projectedCrvs, gridSegmentsGeom)]

    boolFilter2 = [[[b.DoesIntersect(x) for x in z] for b in a] for a,z in zip(projectedCrvs, gridLinesGeom)]

    ##Select gridline segments that intersect with centerpoint of projected lines

    for x,y in zip(boolFilter,gridSegments):
        keySegments2 = []
        keySegmentsGeom2 = []
        for z in x:
            keySegments1 = []
            keySegmentsGeom1 = []
            for g,l in zip(z,y):
                for d,m in zip(g,l):
                    if d == True:
                        keySegments1.append(m)
                        keySegmentsGeom1.append(Revit.GeometryConversion.RevitToProtoCurve.ToProtoType(m,True))
            keySegments2.append(keySegments1)
            keySegmentsGeom2.append(keySegmentsGeom1)
        keySegments.append(keySegments2)
        keySegmentsGeom.append(keySegmentsGeom2)

    ##Order gridlines according to intersection with projected points

    for x,y in zip(boolFilter2, gridLines):
        keyGridLines1 = []
        keyGridLinesGeom1 = []
        for z in x:

            for g,l in zip(z,y):
                if g == True:
                    keyGridLines1.append(l)
                    keyGridLinesGeom1.append(Revit.GeometryConversion.RevitToProtoCurve.ToProtoType(l.FullCurve,True))
        keyGridLines.append(keyGridLines1)
        keyGridLinesGeom.append(keyGridLinesGeom1)

    ##Add mullions at intersected gridline segments

    TransactionManager.Instance.TransactionTaskDone()
    TransactionManager.Instance.EnsureInTransaction(doc)


    for x,y,z in zip(keyGridLines,keySegments,isPrimary):
        projectedGridlines1 = []
        for h,j,k in zip(x,y,z):
            for i in j:
                if i != None:
                    h.AddMullions(i,mullionType,k)
                    projectedGridlines1.append(h)
        projectedGridlines.append(projectedGridlines1)

else:
    None

if toggle == True:
    OUT = projectedGridlines

else:
    None

TransactionManager.Instance.TransactionTaskDone()

Apologies for the messiness of the code, it's a modification of another node that I've been working on. Thanks for your help.

konrad

Bo,

Your problem is rooted in how Dynamo is wrapping elements to use with its own model. That last call .ToDSType(True) is the gist of the issue. MullionType class is a subclass (it inherits properties) from a ElementType class in Revit. When Dynamo team wraps that object into a custom wrapper they only wrote a top level wrapper that treats all ElementTypes the same, hence this outputs an ElementType/FamilyType rather than a specific MullionType.

First I would suggest that you replace the line of code in your code:

mullionType = IN[3] 

with:

mullionType = UnwrapElement(IN[3])

This is their built in method for unwrapping elements to be used with calls to Revit API.

如果仍然不能解决问题,则可以在使用它之前尝试再次检索MullionType对象,这次直接在脚本中。您可以这样做:

for x,y,z in zip(keyGridLines,keySegments,isPrimary):
    projectedGridlines1 = []
    for h,j,k in zip(x,y,z):
        for i in j:
            if i != None:
                h.AddMullions(i,doc.GetElement(mullionType.Id),k)
                projectedGridlines1.append(h)
    projectedGridlines.append(projectedGridlines1)

这应该确保在包装之前获得MullionType元素。

再次尝试先解开包装,如果先打开则无法再调用GetElement()。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

C# revit api 在 Revit 中创建面板

来自分类Dev

从外部Revit访问Revit API

来自分类Dev

在 Revit 2017 API 中获取房间的邻居

来自分类Dev

Revit API:“隐藏”方法?

来自分类Dev

如何在Revit API中检索嵌套的族实例

来自分类Dev

在Forge API中以JSON形式返回Revit元素数据

来自分类Dev

在Python中创建商品ID Revit API的集合

来自分类Dev

使用python获取Revit API中的过滤规则信息

来自分类Dev

Revit Python宏与脚本

来自分类Dev

Revit API-从Revit项目中完全删除系列

来自分类Dev

如何在button_click事件中从Revit API引用文档和应用程序?

来自分类Dev

Autodesk Revit Architecture 2014 .NET API C#在链接中为实例查找空间

来自分类Dev

Autodesk Revit Architecture 2014 .NET API C#在链接中查找FamilyInstance的主机

来自分类Dev

提示用户使用C#中的Revit API回答布尔选择

来自分类Dev

使用空闲事件处理程序中的Revit API(2014)关闭ActiveUIDocument

来自分类Dev

Revit子事务语句错误

来自分类Dev

Revit 插件(未出现在 Revit 中)

来自分类Dev

在 Revit 中关闭窗口 wpf

来自分类Dev

是否可以通过Revit API或FORGE API在Revit模型中加载新的Cloud(BIM 360)链接?

来自分类Dev

Revit API-C#-太阳和阴影设置-计算一年中每小时的太阳方向

来自分类Dev

如何通过Forge API设计自动化中的revit将巨大的json文件传递到Command.cs?

来自分类Dev

如何使用Forge Design Automation API将BIM 360中的Revit文件保存为云模型?

来自分类Dev

Revit API:使用 Autodesk.Revit.DB 访问特定楼层的组件

来自分类Dev

Revit语句中的运算符错误

来自分类Dev

Revit API:“ PickObject”未显示对话框窗口

来自分类Dev

Revit API-新墙类型-如何布置图层?

来自分类Dev

Revit API-调用PostCommand后如何返回“正常代码”

来自分类Dev

Revit API - 仅重命名风管系统实例

来自分类Dev

Autodesk 模型衍生 API - 无法翻译我的 revit 文件

Related 相关文章

  1. 1

    C# revit api 在 Revit 中创建面板

  2. 2

    从外部Revit访问Revit API

  3. 3

    在 Revit 2017 API 中获取房间的邻居

  4. 4

    Revit API:“隐藏”方法?

  5. 5

    如何在Revit API中检索嵌套的族实例

  6. 6

    在Forge API中以JSON形式返回Revit元素数据

  7. 7

    在Python中创建商品ID Revit API的集合

  8. 8

    使用python获取Revit API中的过滤规则信息

  9. 9

    Revit Python宏与脚本

  10. 10

    Revit API-从Revit项目中完全删除系列

  11. 11

    如何在button_click事件中从Revit API引用文档和应用程序?

  12. 12

    Autodesk Revit Architecture 2014 .NET API C#在链接中为实例查找空间

  13. 13

    Autodesk Revit Architecture 2014 .NET API C#在链接中查找FamilyInstance的主机

  14. 14

    提示用户使用C#中的Revit API回答布尔选择

  15. 15

    使用空闲事件处理程序中的Revit API(2014)关闭ActiveUIDocument

  16. 16

    Revit子事务语句错误

  17. 17

    Revit 插件(未出现在 Revit 中)

  18. 18

    在 Revit 中关闭窗口 wpf

  19. 19

    是否可以通过Revit API或FORGE API在Revit模型中加载新的Cloud(BIM 360)链接?

  20. 20

    Revit API-C#-太阳和阴影设置-计算一年中每小时的太阳方向

  21. 21

    如何通过Forge API设计自动化中的revit将巨大的json文件传递到Command.cs?

  22. 22

    如何使用Forge Design Automation API将BIM 360中的Revit文件保存为云模型?

  23. 23

    Revit API:使用 Autodesk.Revit.DB 访问特定楼层的组件

  24. 24

    Revit语句中的运算符错误

  25. 25

    Revit API:“ PickObject”未显示对话框窗口

  26. 26

    Revit API-新墙类型-如何布置图层?

  27. 27

    Revit API-调用PostCommand后如何返回“正常代码”

  28. 28

    Revit API - 仅重命名风管系统实例

  29. 29

    Autodesk 模型衍生 API - 无法翻译我的 revit 文件

热门标签

归档