Revit 附加模块中的 Windows 窗体



我现在写了很多不同的附加模块,但我一直在努力让一个在Revit上运行的窗口窗体。该程序构建良好,我已经为 Revit 设置了 dll 以访问。

以下是我的代码的不同部分。该程序比看到的要广泛得多,但我相信问题是参考问题或我的 ADDIN 文件的问题。也许我需要以不同的方式设置我的 ADDIN 文件,因为我有一个 Windows 表单??让我知道。

这是一个包含屏幕截图的Dropbox文件夹。

如果还有什么需要看的,请告诉我。Revit 中的错误说它与全名有关,但我相信我正确地将其放入 ADDIN 文件中,并且我的做法与其他 ADDIN 相同。

感谢您的帮助!

[TransactionAttribute(TransactionMode.Manual)]
[RegenerationAttribute(RegenerationOption.Manual)]
public class CicuitChecker : IExternalCommand
{
    public Result Execute(
      ExternalCommandData commandData,
      ref string message,
      ElementSet elements)
    {
        //set document variable
        Document document = commandData.Application.ActiveUIDocument.Document;
        using (Transaction trans = new Transaction(document))
        {
            trans.Start("Circuit Checker");
            UIApplication uiApp = commandData.Application;
            Document doc = uiApp.ActiveUIDocument.Document;
            //run through looped form in case of user not selecting needed fields, and store what family the user wants the program to check
            Boolean messedUp = false;
            Boolean All = false, lightF = false, recep = false, elecEquip = false, equipCon = false, junc = false, panels = false;
            FilteredElementCollector collector = new FilteredElementCollector(doc), collector2 = new FilteredElementCollector(doc);
            while (messedUp)
            { 
                CircuitChecker.CircuitCheckerForm form = new CircuitChecker.CircuitCheckerForm();
                form.ShowDialog();
                //Get application and document objects

                foreach (String item in form.getSelectionElementsLB())
                {
                    if (item.Equals("All"))
                    {
                        All = true;
                        break;
                    }
                    else if (item.Equals("Lighting Fixtures"))
                    {
                        lightF = true;
                    }
                    else if (item.Equals("Recepticales"))
                    {
                        recep = true;
                    }
                    else if (item.Equals("Electrical Equipment (including Panels)"))
                    {
                        elecEquip = true;
                    }
                    else if (item.Equals("Junctions"))
                    {
                        junc = true;
                    }
                    else
                    {
                        messedUp = true;
                        TaskDialog.Show("Error", "At least one element must be selected.");
                    }
                }
                if (form.getSelectionPlaceLB().Equals("Entire Project"))
                {
                    collector
                        = new FilteredElementCollector(doc)
                        .WhereElementIsNotElementType();
                    collector2
                        = new FilteredElementCollector(doc)
                        .WhereElementIsNotElementType();
                }
                else if (form.getSelectionPlaceLB().Equals("Elements in Current View"))
                {
                    collector
                        = new FilteredElementCollector(doc, document.ActiveView.Id)
                        .WhereElementIsNotElementType();
                    collector2
                        = new FilteredElementCollector(doc, document.ActiveView.Id)
                        .WhereElementIsNotElementType();
                }
                else
                {
                    messedUp = true;
                    TaskDialog.Show("Error", "A place must be selected.");
                }
            }

            Color color = new Color(138, 43, 226); // RGB
            OverrideGraphicSettings ogs = new OverrideGraphicSettings();
            OverrideGraphicSettings ogsOriginal = new OverrideGraphicSettings();
            ogs.SetProjectionLineColor(color);
            int notCircuited = 0;
            //ElementId symbolId = family
            ElementCategoryFilter lightFilter = new ElementCategoryFilter(BuiltInCategory.OST_LightingFixtures);
            ElementCategoryFilter recepFilter = new ElementCategoryFilter(BuiltInCategory.OST_ElectricalFixtures);
            ElementCategoryFilter elecEquipFilter = new ElementCategoryFilter(BuiltInCategory.OST_ElectricalEquipment);
            //ElementClassFilter filter = new ElementClassFilter(typeof("Junction Boxes - Load"));
            //FamilyInstanceFilter juncFilter1 = new FamilyInstanceFilter(doc, );
            LogicalOrFilter first = new LogicalOrFilter(lightFilter, recepFilter);
            if (All)
            {

                collector.WherePasses(first);
                IList<Element> allArr = collector.ToElements();
                foreach (Element e in allArr)
                {
                    int cirNum = e.get_Parameter(BuiltInParameter.RBS_ELEC_CIRCUIT_NUMBER).AsInteger();
                    String panel = e.get_Parameter(BuiltInParameter.RBS_ELEC_CIRCUIT_PANEL_PARAM).AsString();
                    if (!(IsNumeric(cirNum)) || (panel.Equals("")) || (panel.Equals("<unnamed>")))
                    {
                        doc.ActiveView.SetElementOverrides(e.Id, ogs);
                        notCircuited++;
                    }
                    else
                    {
                        doc.ActiveView.SetElementOverrides(e.Id, ogsOriginal);
                    }
                }
                collector2.WherePasses(elecEquipFilter);
                IList<Element> elecEquipArr = collector.ToElements();
                foreach (Element e in elecEquipArr)
                {
                    String panel = e.get_Parameter(BuiltInParameter.RBS_ELEC_PANEL_SUPPLY_FROM_PARAM).AsString();
                    if ((panel.Equals("")))
                    {
                        doc.ActiveView.SetElementOverrides(e.Id, ogs);
                        notCircuited++;
                    }
                    else
                    {
                        doc.ActiveView.SetElementOverrides(e.Id, ogsOriginal);
                    }
                }
                TaskDialog.Show("Circuit Checker", notCircuited + " lighting fixtures are not circuited in this view.");
                trans.Commit();
            }
            if (!trans.HasEnded())
            {
                if (lightF)
                {
                    collector.WherePasses(lightFilter);
                    IList<Element> lightArr = collector.ToElements();
                    foreach (Element e in lightArr)
                    {
                        int cirNum = e.get_Parameter(BuiltInParameter.RBS_ELEC_CIRCUIT_NUMBER).AsInteger();
                        String panel = e.get_Parameter(BuiltInParameter.RBS_ELEC_CIRCUIT_PANEL_PARAM).AsString();
                        if (!(IsNumeric(cirNum)) || (panel.Equals("")) || (panel.Equals("<unnamed>")))
                        {
                            doc.ActiveView.SetElementOverrides(e.Id, ogs);
                            notCircuited++;
                        }
                        else
                        {
                            doc.ActiveView.SetElementOverrides(e.Id, ogsOriginal);
                        }
                    }
                }
                if (recep)
                {
                    collector.WherePasses(recepFilter);
                    IList<Element> recepArr = collector.ToElements();
                    foreach (Element e in recepArr)
                    {
                        int cirNum = e.get_Parameter(BuiltInParameter.RBS_ELEC_CIRCUIT_NUMBER).AsInteger();
                        String panel = e.get_Parameter(BuiltInParameter.RBS_ELEC_CIRCUIT_PANEL_PARAM).AsString();
                        if (!(IsNumeric(cirNum)) || (panel.Equals("")) || (panel.Equals("<unnamed>")))
                        {
                            doc.ActiveView.SetElementOverrides(e.Id, ogs);
                            notCircuited++;
                        }
                        else
                        {
                            doc.ActiveView.SetElementOverrides(e.Id, ogsOriginal);
                        }
                    }
                }
                if (elecEquip)
                {
                    collector.WherePasses(elecEquipFilter);
                    IList<Element> elecEquipArr = collector.ToElements();
                    foreach (Element e in elecEquipArr)
                    {
                        String panel = e.get_Parameter(BuiltInParameter.RBS_ELEC_PANEL_SUPPLY_FROM_PARAM).AsString();
                        if ((panel.Equals("")))
                        {
                            doc.ActiveView.SetElementOverrides(e.Id, ogs);
                            notCircuited++;
                        }
                        else
                        {
                            doc.ActiveView.SetElementOverrides(e.Id, ogsOriginal);
                        }
                    }
                }
                if (junc)
                {
                    collector.WherePasses(recepFilter);
                    IList<Element> juncArr = collector.ToElements();
                    foreach (Element e in juncArr)
                    {
                        int cirNum = e.get_Parameter(BuiltInParameter.RBS_ELEC_CIRCUIT_NUMBER).AsInteger();
                        String panel = e.get_Parameter(BuiltInParameter.RBS_ELEC_CIRCUIT_PANEL_PARAM).AsString();
                        if (!(IsNumeric(cirNum)) || (panel.Equals("")) || (panel.Equals("<unnamed>")))
                        {
                            doc.ActiveView.SetElementOverrides(e.Id, ogs);
                            notCircuited++;
                        }
                        else
                        {
                            doc.ActiveView.SetElementOverrides(e.Id, ogsOriginal);
                        }
                    }
                }
                TaskDialog.Show("Circuit Checker", notCircuited + " lighting fixtures are not circuited in this view.");
                trans.Commit();
            }
        }
        return Result.Succeeded;
    }
    public static Boolean IsNumeric(Object Expression)
    {
        if (Expression == null || Expression is DateTime)
            return false;
        if (Expression is Int16 || Expression is Int32 || Expression is Int64 || Expression is Decimal || Expression is Single || Expression is Double || Expression is Boolean)
            return true;
        try
        {
            if (Expression is string)
                Double.Parse(Expression as string);
            else
                Double.Parse(Expression.ToString());
            return true;
        }
        catch { } // just dismiss errors but return false
        return false;
    }
}

此代码在"主类"中具有功能。 此后,我已按照康拉德的建议将功能移动到窗体类中,但仍然在Revit中收到FullClassName错误。请帮忙!

计划数据加载项提供了一个完整的 Visual Studio 解决方案,演示如何在 Revit 加载项中显示 Windows 窗体,包括动态生成 Windows 窗体:

http://thebuildingcoder.typepad.com/blog/2012/05/the-schedule-api-and-access-to-schedule-data.html

以下是我通常如何设置基于 Windows 窗体的外部命令。请记住,您必须创建一个外部命令,并且您的 addin 清单必须指向此类。然后从这个类中,你可以像这样启动表单:

    [Transaction(TransactionMode.Manual)]
    public class SomeCommand : IExternalCommand
    {
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            // Get application and document objects
            UIApplication uiApp = commandData.Application;
            Document doc = uiApp.ActiveUIDocument.Document;
            UIDocument uidoc = uiApp.ActiveUIDocument;
            try
            {
                SomeNamespace.SomeForm form = new SomeNamespace.SomeForm(doc);
                form.ShowDialog();
                return Result.Succeeded;
            }
            // Catch any exceptions and display them
            catch (Autodesk.Revit.Exceptions.OperationCanceledException)
            {
                return Result.Cancelled;
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return Result.Failed;
            }
        }
    }

所以我有一个Form类,我从我的ExternalCommand实例化并Document传递给它的构造函数。这样,当我稍后与表单交互时,我就可以访问文档。我在窗体后面的代码中连接所有功能。

同意,OP 的问题是为什么插件不起作用...... 从查看图像来看,问题似乎是Revit没有正确找到命令的完整类名。

没有将命令类包装在命名空间中有点不寻常(例如,您的表单类是(。

我建议将其包装在像"电路检查器"这样的命名空间中 - 就像你的表单类一样。

然后addin文件中的"全名"将变为"circuitchecker.circuitchecker">

(命名空间.classname( - 这有助于Revit区分可能具有相同名称的不同类。

旁注:我不相信将 URL 放入插件中的图像/大图像字段中会起作用 - 但不是积极的。

最新更新