简体   繁体   English

如何从 C# 运行内置的 Revit 命令

[英]How can I run built-in Revit commands from C#

I am wanting to know if there is a methodology to feed calculated values to a built-in Revit command from inside a C# program, and then possibly (based on results, such as whether this makes an element too short or too long for a known "maximum span" of a particular beam) continue with my C# program and change the beam size).我想知道是否有一种方法可以从 C# 程序内部将计算值提供给内置的 Revit 命令,然后可能(基于结果,例如这是否使元素对于已知的元素来说太短或太长特定梁的“最大跨度”)继续我的 C# 程序并更改梁大小)。 I am told you can invoke the Revit built-in command after execution of your c# external command, but you cannot then return to the c# program我听说您可以在执行 c# 外部命令后调用 Revit 内置命令,但之后无法返回到 c# 程序

As another example, I want to select an element to trim/extend to, and have the code figure out which "Joist" beams to extend to this element.再举一个例子,我想选择一个元素来修剪/延伸到,并让代码找出哪个“托梁”梁延伸到这个元素。 My program would do extended filtering (such as "Reference Level", or "Workset", or "Comments", or "Mark" parameters (etc.)) and then run the built in function, providing the element to extend to and then each of my beams.我的程序将进行扩展过滤(例如“参考级别”、“工作集”、“评论”或“标记”参数(等)),然后运行内置函数,提供要扩展到的元素,然后我的每一根梁。

I've tried internet searches, as well as the Revit SDK samples, and nothing obviously used this (but there are a lot of csproj's to look through).我已经尝试过互联网搜索以及 Revit SDK 示例,但显然没有使用它(但有很多 csproj 需要查看)。

Can anyone verify that you cannot go back and forth between the C# program and the Revit built-in command?谁能确认您不能在 C# 程序和 Revit 内置命令之间来回切换?

You can programmatically invoke a built in Revit command with the UIApplication.PostCommand() method.您可以使用 UIApplication.PostCommand() 方法以编程方式调用内置的 Revit 命令。 Refer to documentation and building coder for more information.有关更多信息,请参阅文档建筑编码器 It will not execute until after the API context is over, however.但是,它会在 API 上下文结束后才会执行。

I don't think you'll be able to feed arguments into the command however, short of some kind of Win32 hack.但是,我认为除了某种 Win32 hack 之外,您无法将参数输入到命令中。 Perhaps you will need to recreate the functionality of the built in command within the Revit API.也许您需要在 Revit API 中重新创建内置命令的功能。

Unfortunately, I don't think we can do (command "_line" pnt1 pnt2) type of thing here.不幸的是,我认为我们不能在这里做(命令“_line”pnt1 pnt2)类型的事情。

Perhaps start with the SDK sample "MoveLinear".也许从 SDK 示例“MoveLinear”开始。 It shows how to modify end points of linear elements (which includes beams).它显示了如何修改线性元素(包括梁)的端点。

The main part of the sample's code is示例代码的主要部分是

                Autodesk.Revit.DB.Line line;
                //get start point via "get_EndPoint(0)"
                Autodesk.Revit.DB.XYZ newStart = new XYZ(
                    lineLoc.Curve.GetEndPoint(0).X + 100,
                    lineLoc.Curve.GetEndPoint(0).Y,
                    lineLoc.Curve.GetEndPoint(0).Z);
                //get end point via "get_EndPoint(1)"
                Autodesk.Revit.DB.XYZ newEnd = new XYZ(
                    lineLoc.Curve.GetEndPoint(1).X,
                    lineLoc.Curve.GetEndPoint(1).Y + 100,
                    lineLoc.Curve.GetEndPoint(1).Z);
                //get a new line and use it to move current element 
                //with property "Autodesk.Revit.DB.LocationCurve.Curve"
                line = Line.CreateBound(newStart, newEnd);
                lineLoc.Curve = line;

Which moves the X of the first point and the Y of the second point 100 feet.这将第一个点的 X 和第二个点的 Y 移动 100 英尺。

you can try:你可以试试:

 RevitCommandId commandId = RevitCommandId.LookupPostableCommandId(PostableCommand.PlaceAComponent);
 commandData.Application.PostCommand(commandId);

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

相关问题 如何在不使用C#内置数学函数的情况下计算基数为2的对数? - How can I compute a base 2 logarithm without using the built-in math functions in C#? 如何在C#中复制Python的已排序内置函数的行为? - How can I replicate the behavior of Python's sorted built-in function in C#? 如何序列化继承内置c#类的对象? - How can I serialize objects that inherit built-in c# classes? 如何在 C# 中为内置类型设置别名? - How to alias a built-in type in C#? 从表中删除内容后,如何在 C# 的内置 SQL 数据库中将自动增量重置为从 1 开始? - How do I reset Auto-Increment to start from 1 in built-in SQL Database of C# after deleting contents from table? 如何从Revit-api C#中的Revit文档向Revit系列元素添加参数 - How to add parameters to a revit family element from revit document in revit-api c# 如何使用 C# 在 Microsoft excel 中运行回归 function(或任何工具/内置宏) - How to run the regression function (or any tool/built-in macro) in microsoft excel using C# C#内置事件 - C# built-in events 在 C# 中,是否有任何我不应该使用的内置异常? - In C#, are there any built-in exceptions I shouldn't use? 如何在 C# 单元测试中伪造内置方法的返回? - How do I fake the return of a built-in method in C# unit test?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM