Search code examples
autodeskrevit-apirevit

Revit Addin (Not appearing in Revit)


So I have created two Revit Addin's.

One is to calculate the area of a selected model (AreaChecker), another is to detect all rooms and give their area upon click (RoomChecker).

I have essentially used the same code in terms of connecting the external addin to Revit.

The AreaChecker isn't appearing within the external tools, but the RoomChecker is.

I was wondering if anyone can see the issue within the code?

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>

Solution

  • You are using same GUID for both class in the ".addin" file.. <AddInId>604b1052-F742-4951-8576-C261D1993107</AddInId>

    This GUID should be different for each addin.