Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Check the overlapping dimension text

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
ttnhan1
424 Views, 3 Replies

Check the overlapping dimension text

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? 

Labels (2)
3 REPLIES 3
Message 2 of 4
jeremy_tammik
in reply to: ttnhan1

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
Message 3 of 4
ttnhan1
in reply to: ttnhan1

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.

Message 4 of 4
jeremy_tammik
in reply to: ttnhan1

Clever idea! Congratulations on achieving a good solution!

  

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report