我试图从我试图设置的WinForms中传递一个值,但是一旦窗体关闭,Revit在单击继续按钮后会卡在蓝色微调器中,并且不会返回运行原始程序。
我四处查看了一下,但没有找到任何可以让它返回程序的东西。WinForms上的大多数(如果不是全部)教程与处理Revit无关。我发现/观察到的大多数方法都是将值从一种形式传递到另一种形式,尽管
I found this one
尽管它有点不同。
这是我的代码:
表格1.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)
{
}
}
命令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();
}
感谢任何帮助/指导。