Check the overlapping dimension text

Check the overlapping dimension text

ttnhan1
Contributor Contributor
759 Views
3 Replies
Message 1 of 4

Check the overlapping dimension text

ttnhan1
Contributor
Contributor

I am new to Revit API, I am trying to make an add-in to add the dimension automatically. But some dimension texts overlap. For example here: 

I use this function to add a dimension to the grid 

 Dimension dim = doc.Create.NewDimension(doc.ActiveView, rowDimLine, rowsArr);

 

The new dimension have some overlapped text like this: 

Screenshot 2024-02-22 175258.png

 

A dimension has many segments, how can I find which segments (or which text) overlap?

As I researched, I can get the "drag point" of the text by this code:

Dimension dim = doc.Create.NewDimension(doc.ActiveView, rowDimLine, rowsArr);
var firstSegment = dim.Segments.get_Item(0);
XYZ dragPoint = firstSegment.TextPosition;

 However, with one point, I cannot check if that text overlaps other text.

 

With the dimension' type, I can get the text size but not the text box's width.

Dimension dim = doc.Create.NewDimension(doc.ActiveView, rowDimLine, rowsArr);
var type = doc.GetElement(dim.DimensionType.Id);
double textSize = type.get_Parameter(BuiltInParameter.TEXT_SIZE).AsDouble();

 

How can get the dimension textbox's width or check which text overlaps? 

0 Likes
Accepted solutions (1)
760 Views
3 Replies
Replies (3)
Message 2 of 4

jeremy_tammik
Alumni
Alumni

Well, just checking whether the dimension texts overlap is not that hard, in theory at least:

  

  • Retrieve all dimensions' text extents
  • Check for collision between the 2D bounding boxes

  

The first has been discussed here in the past:

  

  

Detecting overlapping boxes in 2D is a standard geometric algebra task:

  

  

What do you do with that information? Adjusting manually is possible but may be tedious. Automatically removing overlaps is a pretty challenging task, cf.:

  

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 4

ttnhan1
Contributor
Contributor
Accepted solution

Hi @jeremy_tammik,

Thank you for your response, I tried your suggestion in this post https://forums.autodesk.com/t5/revit-api-forum/the-height-and-width-of-the-dimension-text/m-p/108732... 
I tried to get TextNode in onText function. However, I'm not sure when onText is called, It didn't work for my case.

 

I tried another way (a silly and complex way, I think). I got segments of the dimension and created textNotes with the same font style. I got the text boxes' width and height from textNotes.

 

ElementId defaultTextTypeId = doc.GetDefaultElementTypeId(ElementTypeGroup.TextNoteType);
TextNoteType type = doc.GetElement(defaultTextTypeId) as TextNoteType;

DimensionType dimType = dimension.DimensionType;

type.get_Parameter(BuiltInParameter.TEXT_FONT).Set(dimType.get_Parameter(BuiltInParameter.TEXT_FONT).Id);
type.get_Parameter(BuiltInParameter.TEXT_SIZE).Set(dimType.get_Parameter(BuiltInParameter.TEXT_SIZE).AsDouble());
type.get_Parameter(BuiltInParameter.TEXT_STYLE_BOLD).Set(dimType.get_Parameter(BuiltInParameter.TEXT_STYLE_BOLD).AsDouble());
type.get_Parameter(BuiltInParameter.TEXT_STYLE_ITALIC).Set(dimType.get_Parameter(BuiltInParameter.TEXT_STYLE_ITALIC).AsDouble());

foreach (DimensionSegment seg in dimension.Segments)
{
    TextNote note = TextNote.Create(doc, doc.ActiveView.Id, seg.TextPosition, seg.ValueString.Trim(), type.Id);
    newTextNote.Add(note);
}

 


Based on the text's width and Text position, I checked which segment's text overlapped and changed the Text Position.
Finally, I remove all created textNotes.

 

At least, It solved my issue.

I appreciate your help.

0 Likes
Message 4 of 4

jeremy_tammik
Alumni
Alumni

Clever idea! Congratulations on achieving a good solution!

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes