Skip to content

Commit

Permalink
add base without transform
Browse files Browse the repository at this point in the history
  • Loading branch information
chuongmep committed Apr 29, 2024
1 parent c74f329 commit c9566b2
Show file tree
Hide file tree
Showing 2 changed files with 164 additions and 10 deletions.
48 changes: 38 additions & 10 deletions AddInManager.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Build", "Build\Build.csproj
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test", "Test\Test.csproj", "{1661572C-EF3A-4DD6-83BD-CB4239CE8CDD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RevitElementBipChecker", "RevitElementBipChecker\RevitElementBipChecker.csproj", "{21460D85-C4AD-49D5-963F-CF13C4AE99EB}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RevitElementBipChecker", "RevitElementBipChecker\RevitElementBipChecker.csproj", "{21460D85-C4AD-49D5-963F-CF13C4AE99EB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test2", "Test2\Test2.csproj", "{DA609427-F086-4C79-A5FA-202DBB5DE48D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test2", "Test2\Test2.csproj", "{DA609427-F086-4C79-A5FA-202DBB5DE48D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -43,6 +43,8 @@ Global
{C872CDA2-93F5-4681-BD2F-207EACF83D2E}.Debug R23|Any CPU.Build.0 = Debug R23|Any CPU
{C872CDA2-93F5-4681-BD2F-207EACF83D2E}.Debug R24|Any CPU.ActiveCfg = Debug R24|Any CPU
{C872CDA2-93F5-4681-BD2F-207EACF83D2E}.Debug R24|Any CPU.Build.0 = Debug R24|Any CPU
{C872CDA2-93F5-4681-BD2F-207EACF83D2E}.Debug R25|Any CPU.ActiveCfg = Debug R25|Any CPU
{C872CDA2-93F5-4681-BD2F-207EACF83D2E}.Debug R25|Any CPU.Build.0 = Debug R25|Any CPU
{C872CDA2-93F5-4681-BD2F-207EACF83D2E}.Installer|Any CPU.ActiveCfg = Release R22|Any CPU
{C872CDA2-93F5-4681-BD2F-207EACF83D2E}.Release R19|Any CPU.ActiveCfg = Release R19|Any CPU
{C872CDA2-93F5-4681-BD2F-207EACF83D2E}.Release R19|Any CPU.Build.0 = Release R19|Any CPU
Expand All @@ -58,11 +60,11 @@ Global
{C872CDA2-93F5-4681-BD2F-207EACF83D2E}.Release R24|Any CPU.Build.0 = Release R24|Any CPU
{C872CDA2-93F5-4681-BD2F-207EACF83D2E}.Release R25|Any CPU.ActiveCfg = Release R25|Any CPU
{C872CDA2-93F5-4681-BD2F-207EACF83D2E}.Release R25|Any CPU.Build.0 = Release R25|Any CPU
{C872CDA2-93F5-4681-BD2F-207EACF83D2E}.Debug R25|Any CPU.ActiveCfg = Debug R25|Any CPU
{C872CDA2-93F5-4681-BD2F-207EACF83D2E}.Debug R25|Any CPU.Build.0 = Debug R25|Any CPU
{E3C87D34-638C-47A0-A73A-D967B119458D}.Debug R22|Any CPU.ActiveCfg = Debug|Any CPU
{E3C87D34-638C-47A0-A73A-D967B119458D}.Debug R23|Any CPU.ActiveCfg = Debug|Any CPU
{E3C87D34-638C-47A0-A73A-D967B119458D}.Debug R24|Any CPU.ActiveCfg = Debug|Any CPU
{E3C87D34-638C-47A0-A73A-D967B119458D}.Debug R25|Any CPU.ActiveCfg = Debug|Any CPU
{E3C87D34-638C-47A0-A73A-D967B119458D}.Debug R25|Any CPU.Build.0 = Debug|Any CPU
{E3C87D34-638C-47A0-A73A-D967B119458D}.Installer|Any CPU.ActiveCfg = Release|Any CPU
{E3C87D34-638C-47A0-A73A-D967B119458D}.Installer|Any CPU.Build.0 = Release|Any CPU
{E3C87D34-638C-47A0-A73A-D967B119458D}.Release R19|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -75,6 +77,8 @@ Global
{5016ED6D-5A9A-4F59-AE49-CAA9615798F7}.Debug R22|Any CPU.ActiveCfg = Debug|Any CPU
{5016ED6D-5A9A-4F59-AE49-CAA9615798F7}.Debug R23|Any CPU.ActiveCfg = Debug|Any CPU
{5016ED6D-5A9A-4F59-AE49-CAA9615798F7}.Debug R24|Any CPU.ActiveCfg = Debug|Any CPU
{5016ED6D-5A9A-4F59-AE49-CAA9615798F7}.Debug R25|Any CPU.ActiveCfg = Debug|Any CPU
{5016ED6D-5A9A-4F59-AE49-CAA9615798F7}.Debug R25|Any CPU.Build.0 = Debug|Any CPU
{5016ED6D-5A9A-4F59-AE49-CAA9615798F7}.Installer|Any CPU.ActiveCfg = Release|Any CPU
{5016ED6D-5A9A-4F59-AE49-CAA9615798F7}.Release R19|Any CPU.ActiveCfg = Release|Any CPU
{5016ED6D-5A9A-4F59-AE49-CAA9615798F7}.Release R20|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -86,6 +90,8 @@ Global
{1661572C-EF3A-4DD6-83BD-CB4239CE8CDD}.Debug R22|Any CPU.ActiveCfg = Debug R22|Any CPU
{1661572C-EF3A-4DD6-83BD-CB4239CE8CDD}.Debug R23|Any CPU.ActiveCfg = Debug R23|Any CPU
{1661572C-EF3A-4DD6-83BD-CB4239CE8CDD}.Debug R24|Any CPU.ActiveCfg = Debug R24|Any CPU
{1661572C-EF3A-4DD6-83BD-CB4239CE8CDD}.Debug R25|Any CPU.ActiveCfg = Release R25|Any CPU
{1661572C-EF3A-4DD6-83BD-CB4239CE8CDD}.Debug R25|Any CPU.Build.0 = Release R25|Any CPU
{1661572C-EF3A-4DD6-83BD-CB4239CE8CDD}.Installer|Any CPU.ActiveCfg = Debug R21|Any CPU
{1661572C-EF3A-4DD6-83BD-CB4239CE8CDD}.Installer|Any CPU.Build.0 = Debug R21|Any CPU
{1661572C-EF3A-4DD6-83BD-CB4239CE8CDD}.Release R19|Any CPU.ActiveCfg = Release R19|Any CPU
Expand All @@ -96,16 +102,16 @@ Global
{1661572C-EF3A-4DD6-83BD-CB4239CE8CDD}.Release R24|Any CPU.ActiveCfg = Release R24|Any CPU
{1661572C-EF3A-4DD6-83BD-CB4239CE8CDD}.Release R25|Any CPU.ActiveCfg = Release R25|Any CPU
{1661572C-EF3A-4DD6-83BD-CB4239CE8CDD}.Release R25|Any CPU.Build.0 = Release R25|Any CPU
{1661572C-EF3A-4DD6-83BD-CB4239CE8CDD}.Debug R25|Any CPU.ActiveCfg = Release R25|Any CPU
{1661572C-EF3A-4DD6-83BD-CB4239CE8CDD}.Debug R25|Any CPU.Build.0 = Release R25|Any CPU
{21460D85-C4AD-49D5-963F-CF13C4AE99EB}.Debug R22|Any CPU.ActiveCfg = Debug R22|Any CPU
{21460D85-C4AD-49D5-963F-CF13C4AE99EB}.Debug R22|Any CPU.Build.0 = Debug R22|Any CPU
{21460D85-C4AD-49D5-963F-CF13C4AE99EB}.Installer|Any CPU.ActiveCfg = Debug R22|Any CPU
{21460D85-C4AD-49D5-963F-CF13C4AE99EB}.Installer|Any CPU.Build.0 = Debug R22|Any CPU
{21460D85-C4AD-49D5-963F-CF13C4AE99EB}.Debug R23|Any CPU.ActiveCfg = Debug R23|Any CPU
{21460D85-C4AD-49D5-963F-CF13C4AE99EB}.Debug R23|Any CPU.Build.0 = Debug R23|Any CPU
{21460D85-C4AD-49D5-963F-CF13C4AE99EB}.Debug R24|Any CPU.ActiveCfg = Debug R24|Any CPU
{21460D85-C4AD-49D5-963F-CF13C4AE99EB}.Debug R24|Any CPU.Build.0 = Debug R24|Any CPU
{21460D85-C4AD-49D5-963F-CF13C4AE99EB}.Debug R25|Any CPU.ActiveCfg = Release R25|Any CPU
{21460D85-C4AD-49D5-963F-CF13C4AE99EB}.Debug R25|Any CPU.Build.0 = Release R25|Any CPU
{21460D85-C4AD-49D5-963F-CF13C4AE99EB}.Installer|Any CPU.ActiveCfg = Debug R22|Any CPU
{21460D85-C4AD-49D5-963F-CF13C4AE99EB}.Installer|Any CPU.Build.0 = Debug R22|Any CPU
{21460D85-C4AD-49D5-963F-CF13C4AE99EB}.Release R19|Any CPU.ActiveCfg = Release R19|Any CPU
{21460D85-C4AD-49D5-963F-CF13C4AE99EB}.Release R19|Any CPU.Build.0 = Release R19|Any CPU
{21460D85-C4AD-49D5-963F-CF13C4AE99EB}.Release R20|Any CPU.ActiveCfg = Release R20|Any CPU
Expand All @@ -120,8 +126,30 @@ Global
{21460D85-C4AD-49D5-963F-CF13C4AE99EB}.Release R24|Any CPU.Build.0 = Release R24|Any CPU
{21460D85-C4AD-49D5-963F-CF13C4AE99EB}.Release R25|Any CPU.ActiveCfg = Release R25|Any CPU
{21460D85-C4AD-49D5-963F-CF13C4AE99EB}.Release R25|Any CPU.Build.0 = Release R25|Any CPU
{21460D85-C4AD-49D5-963F-CF13C4AE99EB}.Debug R25|Any CPU.ActiveCfg = Release R25|Any CPU
{21460D85-C4AD-49D5-963F-CF13C4AE99EB}.Debug R25|Any CPU.Build.0 = Release R25|Any CPU
{DA609427-F086-4C79-A5FA-202DBB5DE48D}.Debug R22|Any CPU.ActiveCfg = Debug|Any CPU
{DA609427-F086-4C79-A5FA-202DBB5DE48D}.Debug R22|Any CPU.Build.0 = Debug|Any CPU
{DA609427-F086-4C79-A5FA-202DBB5DE48D}.Debug R23|Any CPU.ActiveCfg = Debug|Any CPU
{DA609427-F086-4C79-A5FA-202DBB5DE48D}.Debug R23|Any CPU.Build.0 = Debug|Any CPU
{DA609427-F086-4C79-A5FA-202DBB5DE48D}.Debug R24|Any CPU.ActiveCfg = Debug|Any CPU
{DA609427-F086-4C79-A5FA-202DBB5DE48D}.Debug R24|Any CPU.Build.0 = Debug|Any CPU
{DA609427-F086-4C79-A5FA-202DBB5DE48D}.Debug R25|Any CPU.ActiveCfg = Debug|Any CPU
{DA609427-F086-4C79-A5FA-202DBB5DE48D}.Debug R25|Any CPU.Build.0 = Debug|Any CPU
{DA609427-F086-4C79-A5FA-202DBB5DE48D}.Installer|Any CPU.ActiveCfg = Debug|Any CPU
{DA609427-F086-4C79-A5FA-202DBB5DE48D}.Installer|Any CPU.Build.0 = Debug|Any CPU
{DA609427-F086-4C79-A5FA-202DBB5DE48D}.Release R19|Any CPU.ActiveCfg = Release|Any CPU
{DA609427-F086-4C79-A5FA-202DBB5DE48D}.Release R19|Any CPU.Build.0 = Release|Any CPU
{DA609427-F086-4C79-A5FA-202DBB5DE48D}.Release R20|Any CPU.ActiveCfg = Release|Any CPU
{DA609427-F086-4C79-A5FA-202DBB5DE48D}.Release R20|Any CPU.Build.0 = Release|Any CPU
{DA609427-F086-4C79-A5FA-202DBB5DE48D}.Release R21|Any CPU.ActiveCfg = Release|Any CPU
{DA609427-F086-4C79-A5FA-202DBB5DE48D}.Release R21|Any CPU.Build.0 = Release|Any CPU
{DA609427-F086-4C79-A5FA-202DBB5DE48D}.Release R22|Any CPU.ActiveCfg = Release|Any CPU
{DA609427-F086-4C79-A5FA-202DBB5DE48D}.Release R22|Any CPU.Build.0 = Release|Any CPU
{DA609427-F086-4C79-A5FA-202DBB5DE48D}.Release R23|Any CPU.ActiveCfg = Release|Any CPU
{DA609427-F086-4C79-A5FA-202DBB5DE48D}.Release R23|Any CPU.Build.0 = Release|Any CPU
{DA609427-F086-4C79-A5FA-202DBB5DE48D}.Release R24|Any CPU.ActiveCfg = Release|Any CPU
{DA609427-F086-4C79-A5FA-202DBB5DE48D}.Release R24|Any CPU.Build.0 = Release|Any CPU
{DA609427-F086-4C79-A5FA-202DBB5DE48D}.Release R25|Any CPU.ActiveCfg = Release|Any CPU
{DA609427-F086-4C79-A5FA-202DBB5DE48D}.Release R25|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
126 changes: 126 additions & 0 deletions Test/TestCornorBoundingboxCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
using System;
using System.Collections.Generic;
using System.Windows;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Point = Autodesk.Revit.DB.Point;

namespace Test;

[Transaction(TransactionMode.Manual)]
public class TestConorBoundingBoxCommand : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
using Autodesk.Revit.DB.Transaction transaction =
new Autodesk.Revit.DB.Transaction(commandData.Application.ActiveUIDocument.Document);
transaction.Start("hack");
var doc = commandData.Application.ActiveUIDocument.Document;
Reference r = commandData.Application.ActiveUIDocument.Selection.PickObject(ObjectType.Element);
var instance = doc.GetElement(r) as Autodesk.Revit.DB.FamilyInstance;
// Collect 4x corners of symbol Bbox
BoundingBoxXYZ bbox = instance.Symbol.get_BoundingBox(doc.ActiveView);
(double, double) widthAndHeight = GetWidthAndHeight(bbox);
double rectangleWidth = widthAndHeight.Item1;
double rectangleHeight = widthAndHeight.Item2;
var location = instance.Location as LocationPoint;
double rotationAngle = location.Rotation;

bbox = instance.get_BoundingBox(doc.ActiveView);
var center = bbox.Min + (bbox.Max - bbox.Min) / 2;
(double topRightX, double topRightY) =
RotatePoint(rectangleWidth / 2, rectangleHeight / 2, center, rotationAngle);
(double bottomRightX, double bottomRightY) =
RotatePoint(rectangleWidth / 2, -rectangleHeight / 2, center, rotationAngle);
(double topLeftX, double topLeftY) =
RotatePoint(-rectangleWidth / 2, rectangleHeight / 2, center, rotationAngle);
(double bottomLeftX, double bottomLeftY) =
RotatePoint(-rectangleWidth / 2, -rectangleHeight / 2, center, rotationAngle);

topRightX += center.X;
topRightY += center.Y;
bottomRightX += center.X;
bottomRightY += center.Y;
topLeftX += center.X;
topLeftY += center.Y;
bottomLeftX += center.X;
bottomLeftY += center.Y;
List<XYZ> corners = new List<XYZ>();
corners.Add(new XYZ(bottomLeftX, bottomLeftY, 0));
corners.Add(new XYZ(bottomRightX, bottomRightY, 0));
corners.Add(new XYZ(topRightX, topRightY, 0));
corners.Add(new XYZ(topLeftX, topLeftY, 0));
foreach (XYZ corner in corners)
{
DirectShape ds =
DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_GenericModel));
ds.SetShape(new List<GeometryObject>(new[] { Point.Create(corner), }));
ds.Name = "BoundingBox";
// doc.ActiveView.IsolateElementsTemporary(new List<ElementId>(){ds.Id, instance.Id});
}

transaction.Commit();
return Result.Succeeded;
}

public static List<XYZ> Corners(BoundingBoxXYZ boundingBox)
{
if (boundingBox == null)
{
throw new ArgumentNullException("BoundingBox is null");
}

XYZ minPoint = boundingBox.Min;
XYZ maxPoint = boundingBox.Max;

List<XYZ> corners = new List<XYZ>();
corners.Add(minPoint);
corners.Add(new XYZ(minPoint.X, minPoint.Y, maxPoint.Z));
corners.Add(new XYZ(minPoint.X, maxPoint.Y, minPoint.Z));
corners.Add(new XYZ(minPoint.X, maxPoint.Y, maxPoint.Z));
corners.Add(new XYZ(maxPoint.X, minPoint.Y, minPoint.Z));
corners.Add(new XYZ(maxPoint.X, minPoint.Y, maxPoint.Z));
corners.Add(new XYZ(maxPoint.X, maxPoint.Y, minPoint.Z));
corners.Add(maxPoint);

return corners;
}

public double GetArea(BoundingBoxXYZ boundingBox)
{
if (boundingBox == null)
{
throw new ArgumentNullException("BoundingBox is null");
}

double width = boundingBox.Max.X - boundingBox.Min.X;
double height = boundingBox.Max.Y - boundingBox.Min.Y;

return width * height;
}

public (double, double) GetWidthAndHeight(BoundingBoxXYZ boundingBox)
{
if (boundingBox == null)
{
throw new ArgumentNullException("BoundingBox is null");
}

XYZ minPoint = boundingBox.Min;
XYZ maxPoint = boundingBox.Max;

double width = maxPoint.X - minPoint.X;
double height = maxPoint.Y - minPoint.Y;

return (width, height);
}

public static (double, double) RotatePoint(double x, double y, XYZ center, double angleRad)
{
double xRotated = center.X + (x - center.X) * Math.Cos(angleRad) - (y - center.Y) * Math.Sin(angleRad);
double yRotated = center.Y + (x - center.X) * Math.Sin(angleRad) + (y - center.Y) * Math.Cos(angleRad);
return (xRotated, yRotated);
}
}

0 comments on commit c9566b2

Please sign in to comment.