简体   繁体   English

Revit API如何使外部命令异步运行?

[英]Revit API How to make a external command run asynchrously?

I have an External Command to create about 40 (or even more) Generic model in Revit. 我有一个外部命令可以在Revit中创建大约40个(或更多)通用模型。 I want to make Revit run the command asynchronously to speed up the process according to this flow: 我想让Revit异步运行命令,以根据以下流程加快过程:

load command -> run command -> load families -> generate family instances asynchronously -> end command. 加载命令->运行命令->加载族-> 异步生成族实例 ->结束命令。

I 've read some ideas a bout make a modeless dialog to work around but it is not what I need. 我已经阅读了一些有关回合进行无模式对话的想法,但这不是我所需要的。 How can I do this? 我怎样才能做到这一点?

Meiki is completely correct. Meiki是完全正确的。 The Revit API can only be used within a valid Revit API context, and such a context is provided exclusively by Revit events. Revit API只能在有效的Revit API上下文中使用,并且此类上下文仅由Revit事件提供。 You can however implement an external event and trigger that from outside to obtain access to a valid Revit API context. 但是,您可以实现一个外部事件,并从外部触发该事件以获得对有效Revit API上下文的访问。 This is discussed in detail with many solutions provided by The Building Coder in the topic group on Idling and External Events for Modeless Access and Driving Revit from Outside . 空闲和外部事件的主题组中,建筑编码器提供了许多解决方案,进行了详细的讨论,这些空闲和外部事件用于从外部进行无模式访问和驱动Revit

Another approach might be to make use of the DocumentOpened Event . 另一种方法可能是利用DocumentOpened事件 You could use that to trigger the execution flow you desire. 您可以使用它来触发所需的执行流程。

A third but unsupported approach might be to make use of a journal file, as in the IFC Import and Conversion Journal Script . 第三种但不受支持的方法可能是使用日志文件,如IFC导入和转换日志脚本所示

I would start out reading the numerous solutions listed in the topic group, and probably end up making use of an external event. 我将开始阅读主题组中列出的众多解决方案,并且最终可能会利用外部事件。

Good luck and have fun! 祝好运并玩得开心点!

You can't run external command asynchronously for creating (or modifying) something because of Transactions and remember that Revit doesn't support Async methods or approaches. 您不能因事务而异步运行外部命令来创建(或修改)某些内容,并且请记住Revit不支持异步方法或方法。 can you describe what you gonna do exactly maybe there is another approach. 您能描述一下您将要做什么吗,也许还有另一种方法。

According to the docs: 根据文档:

The Autodesk Revit API supports single threaded access only. Autodesk Revit API仅支持单线程访问。 This means that your API application must perform all Autodesk Revit API calls in the main thread (which is called by the Autodesk Revit process at various API entry points), and your API application cannot maintain operations in other threads and expect them to be able to make calls to Autodesk Revit at any time. 这意味着您的API应用程序必须在主线程中执行所有Autodesk Revit API调用(由Autodesk Revit进程在各个API入口点调用),并且您的API应用程序无法维护其他线程中的操作并且希望它们能够随时可以致电Autodesk Revit。

However, I believe you could create an external API and consume it from your command. 但是,我相信您可以创建一个外部API并从命令中使用它。

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

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