来自 WinForm 的 Revit Pick 元素 [英] Revit Pick element from WinForm

查看:20
本文介绍了来自 WinForm 的 Revit Pick 元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在没有关闭表单的情况下单击按钮时在 Revit 中选取一个对象.问题是当我单击按钮时,我无法与 Revit 交互.

I'm trying to pick an object in Revit when clicking a button without closing the Form. the problem is when i click the button i can't interact with Revit.

这是调用表单并将 Revit 作为所有者传递的主要代码.

here's the main code calling the Form and passing Revit as owner.

IWin32Window revit_window = new JtWindowHandle(ComponentManager.ApplicationWindow);
Process process = Process.GetCurrentProcess();
IntPtr h = process.MainWindowHandle;

form.ShowDialog(revit_window);

public class JtWindowHandle : IWin32Window
{
    IntPtr _hwnd;

    public JtWindowHandle(IntPtr h)
    {
        Debug.Assert(IntPtr.Zero != h, "expected non-null window handle");

        _hwnd = h;
    }

    public IntPtr Handle
    {
        get
        {
            return _hwnd;
        }
    }
}

这里是选择元素的表单代码:

and here is the Form code to select the element:

private void button1_Click(object sender, EventArgs e)
    {
        Hide();
        SelectionFilter1 selfilter1 = new SelectionFilter1();
        pickedRef1 = sel.PickObject(ObjectType.Element, selfilter1, "Select Family instance");
        Show();

    }

推荐答案

您的 Windows 窗体可能未在有效的 Revit API 上下文中作为模式窗体运行.

Your Windows form is presumably not running as a modal form within a valid Revit API context.

因此,您尝试从外部访问 Revit 及其 API.这基本上是不可能的.通过使用外部事件存在解决方法.

Consequently, you are trying to access Revit and its API from outside. This is basically not possible. A workaround exists via the use of an external event.

这个问题目前也在 Revit API 中讨论上的讨论论坛主题带有 WPF 的 Revit API.

This issue is currently also being discussed in the Revit API discussion forum thread on Revit API with WPF.

Revit SDK 示例 ModelessDialog/ModelessForm_ExternalEvent 中介绍了官方方法.

The official approach is presented in the Revit SDK sample ModelessDialog/ModelessForm_ExternalEvent.

The Building Coder 在 无模式访问和从外部驱动 Revit 的空闲和外部事件.

Many other discussions and soutions are listed by The Building Coder in the topic group on Idling and External Events for Modeless Access and Driving Revit from Outside.

这篇关于来自 WinForm 的 Revit Pick 元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆