所以我创建了两个Revit Addin。
一种方法是计算所选模型的面积(AreaChecker),另一种方法是检测所有房间并在单击时提供其面积(RoomChecker)。
在将外部插件连接到Revit方面,我基本上使用了相同的代码。
AreaChecker没有出现在外部工具中,但RoomChecker出现了。
我想知道是否有人可以在代码中看到问题?
RoomChecker.Class1:
using System;
using System.Collections.Generic;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Autodesk.Revit.DB.Architecture;
using System.Diagnostics;
using System.Windows.Forms;
using System;
namespace RoomChecker
{
[Transaction(TransactionMode.Manual)]
public class Class1 : IExternalCommand
{
public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Document doc = uidoc.Document;
FilteredElementCollector a
= new FilteredElementCollector(doc)
.OfClass(typeof(SpatialElement));
foreach (SpatialElement e in a)
{
if (e is Room room)
{
GetRoomDimensions(doc, room);
}
}
return Result.Succeeded;
}
//*************************************GetRoomDimensions()*************************************\\
public void GetRoomDimensions(Document doc, Room room)
{
String roominfo = "Room Properties \n -------------------------------- \n";
Boolean check = false;
String newName = room.Name.Remove(room.Name.Length - 3);
using (Transaction t = new Transaction(doc, "calculate"))
{
t.Start();
AreaVolumeSettings settings = AreaVolumeSettings.GetAreaVolumeSettings(doc);
settings.ComputeVolumes = true;
t.Commit();
}
if (newName == "Double Bedroom" && (room.Area / 10.7639) >= 11.4 && (room.Area / 10.7639) < 13)
{
check = true;
}
else if (newName == "Main Bedroom" && (room.Area / 10.7639) >= 13)
{
check = true;
}
else if (newName == "Single Bedroom" && (room.Area / 10.7639) > 7.1 && (room.Area / 10.7639) < 11.4)
{
check = true;
}
roominfo += "Name: " + newName + "\n";
roominfo += "Area: " + room.Area / 10.7639 + "\n"; //Calculating the perimeter in m2 rather than square foot
roominfo += "Perimeter: " + room.Perimeter / 0.0328084 + "\n"; //Calculating the perimeter in cm rather than feet
roominfo += "Compliance Status: " + check + "\n";
TaskDialog.Show("Revit", roominfo);
}
}
}
RoomChecker.ADDIN:
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<RevitAddIns>
<AddIn Type="Command">
<Assembly>C:\Users\Test\source\repos\RoomChecker\RoomChecker\bin\Debug\RoomChecker.dll</Assembly>
<AddInId>604b1052-F742-4951-8576-C261D1993107</AddInId>
<FullClassName>RoomChecker.Class1</FullClassName>
<Text>RoomChecker</Text>
<VendorId>NAME</VendorId>
<VendorDescription>Your Company Information</VendorDescription>
</AddIn>
</RevitAddIns>
AreaChecker.Class1:
using System;
using System.Collections.Generic;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using System.Linq;
using System.Text;
namespace AreaChecker
{
[Transaction(TransactionMode.Manual)]
public class Class1 : IExternalCommand
{
public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Application app = uiapp.Application;
Document doc = uidoc.Document;
Element e = SelectElement(uidoc, doc);
Parameter area = e.LookupParameter("Area");
using (Transaction tx = new Transaction(doc, "param"))
{
tx.Start("param");
tx.Commit();
TaskDialog.Show("Area:", "Title: " + e.Name + Environment.NewLine + " Area: " + GetParameterValue(area));
}
return Result.Succeeded;
}
//***************************************SelectElement()**************************************\\
public Element SelectElement(UIDocument uidoc, Document doc)
{
Reference reference = uidoc.Selection.PickObject(ObjectType.Element);
Element element = uidoc.Document.GetElement(reference);
return element;
}
//*************************************GetParameterValue()*************************************\\
public string GetParameterValue(Parameter parameter)
{
switch (parameter.StorageType)
{
case StorageType.Double:
return parameter.AsValueString();
case StorageType.ElementId:
return parameter.AsElementId().IntegerValue.ToString();
case StorageType.Integer:
return parameter.AsValueString();
case StorageType.None:
return parameter.AsValueString();
case StorageType.String:
return parameter.AsString();
default:
return "";
}
}
}
}
AreaChecker.ADDIN:
?xml version="1.0" encoding="utf-8" standalone="no"?>
<RevitAddIns>
<AddIn Type="Command">
<Assembly>C:\Users\Test\source\repos\AreaChecker\AreaChecker\bin\Debug\AreaChecker.dll</Assembly>
<AddInId>604b1052-F742-4951-8576-C261D1993107</AddInId>
<FullClassName>AreaChecker.Class1</FullClassName>
<Text>AreaChecker.Class1</Text>
<VendorId>NAME</VendorId>
<VendorDescription>Your Company Information</VendorDescription>
</AddIn>
</RevitAddIns>
答案 0 :(得分:2)
“。addin”文件中的两个类都使用相同的GUID。<AddInId>604b1052-F742-4951-8576-C261D1993107</AddInId>
每个插件的GUID应该不同。
答案 1 :(得分:0)
每当遇到这样的问题时,我都会从头开始重新创建整个加载项,然后将代码从第一个无效的代码复制到新的有效的代码。
由于我使用的是Visual Studio Revit add-in wizard,因此只需单击一下即可生成并安装一个可靠运行的全新插件框架。