Skip to content

Commit beba2c7

Browse files
author
Jeremy Tammik
committed

File tree

2 files changed

+61
-8
lines changed

2 files changed

+61
-8
lines changed

BuildingCoder/CmdSetTagType.cs

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ namespace BuildingCoder
3232
/// create and set a new door tag type.
3333
/// </summary>
3434
[Transaction(TransactionMode.Manual)]
35-
internal class CmdSetTagType : IExternalCommand
35+
class CmdSetTagType : IExternalCommand
3636
{
37-
private const double MeterToFeet = 3.2808399;
37+
const double MeterToFeet = 3.2808399;
3838

3939
public Result Execute(
4040
ExternalCommandData commandData,
@@ -172,7 +172,7 @@ var doorTagType
172172
/// i.e. System.Type, matching the given built-in
173173
/// category in the given document.
174174
/// </summary>
175-
private static FilteredElementCollector
175+
static FilteredElementCollector
176176
GetElementsOfType(
177177
Document doc,
178178
Type type,
@@ -192,7 +192,7 @@ var collector
192192
/// matching the given built-in category.
193193
/// Todo: Compare this with the FamilySymbolFilter class.
194194
/// </summary>
195-
private static FilteredElementCollector
195+
static FilteredElementCollector
196196
GetFamilySymbols(
197197
Document doc,
198198
BuiltInCategory bic)
@@ -205,7 +205,7 @@ private static FilteredElementCollector
205205
/// Return the first family symbol found in the given document
206206
/// matching the given built-in category, or null if none is found.
207207
/// </summary>
208-
private static FamilySymbol GetFirstFamilySymbol(
208+
static FamilySymbol GetFirstFamilySymbol(
209209
Document doc,
210210
BuiltInCategory bic)
211211
{
@@ -223,7 +223,7 @@ private static FamilySymbol GetFirstFamilySymbol(
223223
/// 'Level 1' and 'Level 2' will be returned.
224224
/// </summary>
225225
/// <returns>True if the two levels are successfully determined.</returns>
226-
private static bool GetBottomAndTopLevels(
226+
static bool GetBottomAndTopLevels(
227227
Document doc,
228228
ref Level levelBottom,
229229
ref Level levelTop)
@@ -378,8 +378,60 @@ var builtInParam
378378

379379
index = 0;
380380
}
381+
}
382+
383+
#endregion // Set Tag Colour to Element Colour
384+
385+
#region Determine Tag Extents Width and Height
386+
/// <summary>
387+
/// Determine tag extents, width and height
388+
/// By AmitMetz in
389+
/// https://forums.autodesk.com/t5/revit-api-forum/tag-width-height-or-accurate-boundingbox-of-independenttag/m-p/11274095
390+
/// </summary>
391+
public static Tuple<double, double> GetTagExtents(
392+
Document doc,
393+
IndependentTag tag)
394+
{
395+
Debug.Assert(
396+
tag.Document.GetProjectId().Equals(doc.GetProjectId()),
397+
"expected same document");
398+
399+
//Dimension to return
400+
double tagWidth;
401+
double tagHeight;
402+
403+
//Tag's View and Element
404+
View sec = doc.GetElement(tag.OwnerViewId) as View;
405+
XYZ rightDirection = sec.RightDirection;
406+
XYZ upDirection = sec.UpDirection;
407+
Reference pipeReference = tag.GetTaggedReferences().First();
408+
//Reference pipeReference = tag.GetTaggedReference(); //Older Revit Version
409+
410+
using (TransactionGroup transG = new TransactionGroup(doc))
411+
{
412+
transG.Start("Determine Tag Dimension");
413+
414+
using (Transaction trans = new Transaction(doc, "Determine Tag Dimension"))
415+
{
416+
trans.Start();
417+
418+
tag.LeaderEndCondition = LeaderEndCondition.Free;
419+
XYZ leaderEndPoint = tag.GetLeaderEnd(pipeReference);
420+
tag.TagHeadPosition = leaderEndPoint;
421+
tag.SetLeaderElbow(pipeReference, leaderEndPoint);
422+
423+
trans.Commit();
424+
}
425+
426+
//Tag Dimension
427+
BoundingBoxXYZ tagBox = tag.get_BoundingBox(sec);
428+
tagWidth = (tagBox.Max - tagBox.Min).DotProduct(rightDirection);
429+
tagHeight = (tagBox.Max - tagBox.Min).DotProduct(upDirection);
430+
431+
transG.RollBack();
432+
}
433+
return Tuple.Create(tagWidth, tagHeight);
381434
}
382-
383-
#endregion // Set Tag Colour to Element Colour
435+
#endregion // Determine Tag Extents Widht and Height
384436
}
385437
}

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,3 +372,4 @@
372372
- 2022-04-20 2023.1.152.0 flat migration to Revit 2023
373373
- 2022-04-28 2023.1.152.1 implemented GetAnalyticalElementId
374374
- 2022-06-22 2023.1.152.2 implemented GetFittingTypesOfPartType for https://forums.autodesk.com/t5/revit-api-forum/enumerate-pipefittings-familysymbols-with-part-type-union-in-c/m-p/11250754
375+
- 2022-07-12 2023.1.152.3 implemented GetTagExtents from https://forums.autodesk.com/t5/revit-api-forum/tag-width-height-or-accurate-boundingbox-of-independenttag/m-p/11274095

0 commit comments

Comments
 (0)