简体   繁体   English

将 .Net 对象转换为 IronPython、Dynamo 中的另一个 .Net 对象

[英]Cast .Net object to another .Net object in IronPython, Dynamo

  • the revit API IndependentTag.Create() method requires a Reference object as one of its inputs revit API IndependentTag.Create() 方法需要一个 Reference 对象作为其输入之一
  • A Reference object is instantiated with a revit Element object参考对象使用 revit 元素对象实例化
  • I have bunch of revit Wall objects which inherit from the Element class我有一堆从 Element 类继承的 revit Wall 对象
  • in C# I can simply say: Reference ref = new Reference(wall as Element);在 C# 中,我可以简单地说: Reference ref = new Reference(wall as Element);
  • clr.Convert does not cast correctly, just returns the object as a Wall again clr.Convert 没有正确投射,只是再次将对象作为 Wall 返回
  • ref = Reference(wall) in python gives an exception that the reference cannot be used ref = Reference(wall)在python中给出了一个不能使用引用的异常

Can one cast a .Net object to its parent object in python (iron python)?可以在 python (iron python) 中将 .Net 对象转换为它的父对象吗? I am trying to bandage up someone's dynamo/python script and that one object is mucking it up我试图包扎某人的发电机/python 脚本,而那个对象正在把它搞砸

In C#, if wall is of class Wall and that inherits from Element , there is no need to cast wall to Element .在 C# 中,如果wall属于Wall类并且继承自Element ,则无需将wallElement You can just use wall as is.您可以按原样使用wall It is already a Wall and therefore also an Element .它已经是一个Wall ,因此也是一个Element I would assume the same applies in Python.我认为这同样适用于 Python。 I suggest you post a code snippet for better understanding.我建议您发布代码片段以更好地理解。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM