所以我创建了两个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>发布于 2018-10-08 12:02:42
您在".addin“文件中对两个类使用相同的GUID。<AddInId>604b1052-F742-4951-8576-C261D1993107</AddInId>
每个加载项的GUID应该是不同的。
发布于 2018-10-24 18:51:34
每当遇到这样的问题时,我就从头开始重新创建整个外接程序,然后将第一个不能工作的代码复制到新的不工作的代码中。
由于我使用插件向导,所以只需单击一次就可以生成和安装一个可靠工作的全新外接程序框架。
https://stackoverflow.com/questions/52666509
复制相似问题