我正在尝试从我要设置的WinForms中传回一个值,但是一旦窗体关闭,单击继续按钮后Revit就会卡在蓝色微调器中,并且不会返回运行原始程序。
我已经检查了一下,但是没有找到任何可以返回程序的东西。 WinForms上的大多数(如果不是全部)教程与处理Revit无关。我发现/观察到的大多数内容都是将值从一种形式传递到另一种形式,尽管I found this one有所不同。
这是我的代码:
Form1.cs
public partial class Form1 : System.Windows.Forms.Form
{
private UIApplication uiapp;
private UIDocument uidoc;
private Autodesk.Revit.ApplicationServices.Application app;
private Document doc;
private string myVal;
public string MyVal
{
get { return myVal; }
set { myVal = value; }
}
public Form1(ExternalCommandData commandData)
{
InitializeComponent();
uiapp = commandData.Application;
uidoc = uiapp.ActiveUIDocument;
app = uiapp.Application;
doc = uidoc.Document;
}
public delegate void delPassData(System.Windows.Forms.ComboBox text);
private void Form1_Load(object sender, EventArgs e)
{
//Create a filter to get all the title block types.
FilteredElementCollector colTitleBlocks = new FilteredElementCollector(doc);
colTitleBlocks.OfCategory(BuiltInCategory.OST_TitleBlocks);
colTitleBlocks.WhereElementIsElementType();
foreach(Element x in colTitleBlocks)
{
comboBox1TitleBlockList.Items.Add(x.Name);
}
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button1Continue_Click(object sender, EventArgs e)
{
MyVal = comboBox1TitleBlockList.Text; // is returning with Titleblock.Name
button1Continue.DialogResult = DialogResult.OK;
Debug.WriteLine("OK button was clicked.");
Close();
//Dispose();
return;
}
private void button2Cancel_Click(object sender, EventArgs e)
{
button2Cancel.DialogResult = DialogResult.Cancel;
Debug.WriteLine("Cancel button was clicked");
//Dispose();
Close();
return;
}
private void comboBox1TitleBlockList_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
Command.cs
Form1 form1 = new Form1(commandData);
System.Windows.Forms.Application.Run(new Form1(commandData)); // not sure if this line is required.
form1.ShowDialog();
String elementString = form1.MyVal; //<---- this is returning null. need to figure out how to pass value from form1 back to Command.cs
if (elementString != null)
{
elementString = form1.MyVal.ToString();
Element eFromString = doc.GetElement(elementString);
titleBlockId = eFromString.Id;
}
else
{
titleBlockId = collector.FirstElementId();
}
感谢您提供所有帮助/指导。
这将永远无法工作。您在网上说not sure if this line is required
试图……我什至无法描述它正在试图实现的目标。
Revit API纯粹是事件驱动的,您的Revit加载项只能从有效的Revit API上下文中调用Revit API。这样的上下文仅在您与Revit事件关联的事件处理程序中提供。
您的代码未订阅任何此类事件。因此,它不是Revit加载项。
请通过Revit API getting started material,并按照Revit加载项体系结构要求构建您的加载项。