Can you please add a setting that will control the default justification of the text in a linear dimension so that we can choose center, so that the text is in line with the dimension line and not always above it? See attached sketch. We currently have to move every piece of text inside the line and it is time consuming. We are a fabrication company and we have a lot of information on our drawings. By moving the text inside the line, it frees up a lot of paper space that we can use for other tags/labels, etc.
Solved! Go to Solution.
Solved by RPTHOMAS108. Go to Solution.
Solved by RPTHOMAS108. Go to Solution.
Hello @Anonymous this is not technically an API question but it can be applied and automated to a certain extent with a macro.
If you open the Macro Manager (Manage > Macros) then create a new Module (Application Tab) with language set to VB.NET. When SharpDevelop opens replace the entire contents of ThisApplication.vb with the below. Then Build the macro (Build > Build Solution). Close SharpDevelop. Then back within the Macro Manager select the tree branch of 'CentreDimValuesOnLine' and press run for each view required. If the view scale changes in a view you'll have to run the macro again.
Option Strict off
Imports System
Imports Autodesk.Revit.UI
Imports Autodesk.Revit.DB
Imports Autodesk.Revit.UI.Selection
Imports System.Collections.Generic
Imports System.Linq
<Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)> _
<Autodesk.Revit.DB.Macros.AddInId("EF4F27C9-EE2D-410E-B676-F3600AA5F812")> _
Partial Public Class ThisApplication
Private Sub UpdateDimText(Doc As Document, Dm As Object, TxtH As Double, GFactor As Double)
Dm.ResetTextPosition()
Doc.Regenerate()
Dim SegOrig As XYZ = Dm.Origin 'Centre of dim line between extension lines
Dim TextPos As XYZ = Dm.TextPosition
Dim S1 As XYZ = SegOrig - TextPos
Dim S1n As XYZ = S1.Normalize
Dim Shift As XYZ = TextPos + S1 + (S1n * (TxtH / 2)) + (S1n * GFactor)
Dm.TextPosition = Shift
End Sub
Public Sub CentreDimValuesOnLine
If me.ActiveUIDocument Is Nothing Then Exit sub Else
Dim UIDoc As UIDocument = me.ActiveUIDocument
Dim Doc As Document = UIDoc.Document
Dim AcView As View = UIDoc.ActiveGraphicalView
Dim FEC As New FilteredElementCollector(Doc, Doc.ActiveView.Id)
Dim ECF As New ElementCategoryFilter(BuiltInCategory.OST_Dimensions)
Dim Els As List(Of Dimension) = FEC.WherePasses(ECF).WhereElementIsNotElementType.ToElements.Cast(Of Dimension).ToList
Dim T As Transform = Transform.Identity
T.BasisX = AcView.RightDirection
T.BasisY = AcView.UpDirection
T.BasisZ = AcView.ViewDirection
'Seems horizontal and vertical dimensions have a larger gap between the text and the blue origin dot
Const GapFactor = 0.75 / 2.5 '0.3
Using tx As New Transaction(Doc, "Adjust dim text position")
If tx.Start = TransactionStatus.Started Then
For i = 0 To Els.Count - 1
Dim Dm As Dimension = Els(i)
Dim Dm_Typ As DimensionType = Doc.GetElement(Dm.GetTypeId)
Dim TxtH_P As Parameter = Dm_Typ.Parameter(BuiltInParameter.TEXT_SIZE)
Dim TxtH As Double = TxtH_P.AsDouble * AcView.Scale
Dm.HasLeader = False
Dim LNdir As Line = TryCast(Dm.Curve, Line)
If LNdir Is Nothing Then Continue For Else
Dim LNdirV As XYZ = T.OfVector(LNdir.Direction)
Dim Sx As Double = CDbl(LNdirV.X.ToString("F8")) ^ 2
Dim Sy As Double = CDbl(LNdirV.Y.ToString("F8")) ^ 2
Dim GFactor As Double = 0
If Sx = 1 OrElse Sy = 1 Then 'Horizontal or vertical in view
GFactor = TxtH_P.AsDouble * GapFactor
GFactor *= AcView.Scale
End If
If Dm.Segments.Size = 0 Then
UpdateDimText(Doc, Dm, TxtH, GFactor)
Else
For si = 0 To Dm.Segments.Size - 1
Dim DSeg As DimensionSegment = Dm.Segments(si)
UpdateDimText(Doc, DSeg, TxtH, GFactor)
Next
End If
Next
tx.Commit()
End If
End Using
End Sub
End Class
The below is a further discussion that may be of interest to others dealing with the dimension text in the API.
In doing the above exercise I observed that when the dimension text is horizontal or vertical the gap between the bottom of the text and the blue dot representing the text origin increases. In the above I have therefore approximated this gap as follows:
Gap = 0.3 x Text Height
From 0.75mm Gap / 2.5mm Text Height
This above was checked against Arial 2.5mm and 5.0mm and seems fairly stable for differing angles between vertical and horizontal.
Thanks for that!! We are using 2019, and I am assuming your macro was for 2020 or above. We had to make a slight adjustment to the macro because "hasleader" is not a member, so we called it and set it a little different, but the code below will work for Revit 2019. Thanks again for your input. I actually did not mean to post to API forum, I thought I was adding to the ideas section, but I am glad I did!
Option Strict off
Imports System
Imports Autodesk.Revit.UI
Imports Autodesk.Revit.DB
Imports Autodesk.Revit.UI.Selection
Imports System.Collections.Generic
Imports System.Linq
<Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)> _
<Autodesk.Revit.DB.Macros.AddInId("EF4F27C9-EE2D-410E-B676-F3600AA5F812")> _
Partial Public Class ThisApplication
Private Sub UpdateDimText(Doc As Document, Dm As Object, TxtH As Double, GFactor As Double)
Dm.ResetTextPosition()
Doc.Regenerate()
Dim SegOrig As XYZ = Dm.Origin 'Centre of dim line between extension lines
Dim TextPos As XYZ = Dm.TextPosition
Dim S1 As XYZ = SegOrig - TextPos
Dim S1n As XYZ = S1.Normalize
Dim Shift As XYZ = TextPos + S1 + (S1n * (TxtH / 2)) + (S1n * GFactor)
Dm.TextPosition = Shift
End Sub
Public Sub CentreDimValuesOnLine
If me.ActiveUIDocument Is Nothing Then Exit sub Else
Dim UIDoc As UIDocument = me.ActiveUIDocument
Dim Doc As Document = UIDoc.Document
Dim AcView As View = UIDoc.ActiveGraphicalView
Dim FEC As New FilteredElementCollector(Doc, Doc.ActiveView.Id)
Dim ECF As New ElementCategoryFilter(BuiltInCategory.OST_Dimensions)
Dim Els As List(Of Dimension) = FEC.WherePasses(ECF).WhereElementIsNotElementType.ToElements.Cast(Of Dimension).ToList
Dim T As Transform = Transform.Identity
T.BasisX = AcView.RightDirection
T.BasisY = AcView.UpDirection
T.BasisZ = AcView.ViewDirection
'Seems horizontal and vertical dimensions have a larger gap between the text and the blue origin dot
Const GapFactor = 0.75 / 2.5 '0.3
Using tx As New Transaction(Doc, "Adjust dim text position")
If tx.Start = TransactionStatus.Started Then
For i = 0 To Els.Count - 1
Dim Dm As Dimension = Els(i)
Dim Dm_Typ As DimensionType = Doc.GetElement(Dm.GetTypeId)
Dim TxtH_P As Parameter = Dm_Typ.Parameter(BuiltInParameter.TEXT_SIZE)
Dim TxtH As Double = TxtH_P.AsDouble * AcView.Scale
Dim para As Parameter = Dm.LookupParameter("Leader")
para.SetValueString("No")
Dim LNdir As Line = TryCast(Dm.Curve, Line)
If LNdir Is Nothing Then Continue For Else
Dim LNdirV As XYZ = T.OfVector(LNdir.Direction)
Dim Sx As Double = CDbl(LNdirV.X.ToString("F8")) ^ 2
Dim Sy As Double = CDbl(LNdirV.Y.ToString("F8")) ^ 2
Dim GFactor As Double = 0
If Sx = 1 OrElse Sy = 1 Then 'Horizontal or vertical in view
GFactor = TxtH_P.AsDouble * GapFactor
GFactor *= AcView.Scale
End If
If Dm.Segments.Size = 0 Then
UpdateDimText(Doc, Dm, TxtH, GFactor)
Else
For si = 0 To Dm.Segments.Size - 1
Dim DSeg As DimensionSegment = Dm.Segments(si)
UpdateDimText(Doc, DSeg, TxtH, GFactor)
Next
End If
Next
tx.Commit()
End If
End Using
End Sub
End Class
@Anonymous updated code below:
Option Strict off
Imports System
Imports Autodesk.Revit.UI
Imports Autodesk.Revit.DB
Imports Autodesk.Revit.UI.Selection
Imports System.Collections.Generic
Imports System.Linq
<Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)> _
<Autodesk.Revit.DB.Macros.AddInId("EF4F26C9-EE2D-410E-B676-F3600AA5F822")> _
Partial Public Class ThisApplication
Private Sub UpdateDimText(Doc As Document, Dm As Object, TxtH As Double, GFactor As Double)
Dm.ResetTextPosition()
Doc.Regenerate()
Dim SegOrig As XYZ = Dm.Origin 'Centre of dim line between extension lines
Dim TextPos As XYZ = Dm.TextPosition
Dim S1 As XYZ = SegOrig - TextPos
Dim S1n As XYZ = S1.Normalize
Dim Shift As XYZ = TextPos + S1 + (S1n * (TxtH / 2)) + (S1n * GFactor)
Dm.TextPosition = Shift
End Sub
Public Sub CentreDimValuesOnLine
If me.ActiveUIDocument Is Nothing Then Exit sub Else
Dim UIDoc As UIDocument = me.ActiveUIDocument
Dim Doc As Document = UIDoc.Document
Dim AcView As View = Doc.ActiveView
Dim TD As New TaskDialog("Option") With {.MainInstruction = "Select option to use"}
TD.AddCommandLink(TaskDialogCommandLinkId.CommandLink1, "Update all dimensions in view")
TD.AddCommandLink(TaskDialogCommandLinkId.CommandLink2, "Update selected dimensions in view")
Dim Res As TaskDialogResult = TD.Show
Dim EIDs As List(Of ElementId)
If Res = TaskDialogResult.CommandLink1 Then
Dim FEC As New FilteredElementCollector(Doc, Doc.ActiveView.Id)
Dim ECF As New ElementCategoryFilter(BuiltInCategory.OST_Dimensions)
EIDs = FEC.WherePasses(ECF).WhereElementIsNotElementType.ToElementIds '.Cast(Of Dimension).ToList
ElseIf Res = TaskDialogResult.CommandLink2 Then
Dim Refs As New List(Of Reference)
Try
Refs = UIDoc.Selection.PickObjects(ObjectType.Element, New SelDimCatFilt, "Select dimensions to update")
Catch ex As Exception
Exit sub
End Try
EIDs = New List(Of ElementId)
For i = 0 To Refs.Count - 1
EIDs.Add(Refs(i).ElementId)
Next
Else
Exit sub
End If
Dim T As Transform = Transform.Identity
T.BasisX = AcView.RightDirection
T.BasisY = AcView.UpDirection
T.BasisZ = AcView.ViewDirection
'Seems horizontal and vertical dimensions have a larger gap between the text and the blue origin dot
Const GapFactor = 0.75 / 2.5 '0.3
Using tx As New Transaction(Doc, "Adjust dim text position")
If tx.Start = TransactionStatus.Started Then
For i = 0 To EIDs.Count - 1
Dim Dm As Dimension = TryCast(Doc.GetElement(EIDs(i)), Dimension)
If Dm Is Nothing Then Continue For Else
Dim Dm_Typ As DimensionType = Doc.GetElement(Dm.GetTypeId)
Dim TxtH_P As Parameter = Dm_Typ.Parameter(BuiltInParameter.TEXT_SIZE)
Dim TxtH As Double = TxtH_P.AsDouble * AcView.Scale
'Dm.HasLeader = False
Dim P As Parameter = Dm.Parameter(BuiltInParameter.DIM_LEADER)
If P Is Nothing = False Then
P.Set(CInt(0))
End If
Dim LNdir As Line = TryCast(Dm.Curve, Line)
If LNdir Is Nothing Then Continue For Else
Dim LNdirV As XYZ = T.OfVector(LNdir.Direction)
Dim Sx As Double = CDbl(LNdirV.X.ToString("F8")) ^ 2
Dim Sy As Double = CDbl(LNdirV.Y.ToString("F8")) ^ 2
Dim GFactor As Double = 0
If Sx = 1 OrElse Sy = 1 Then 'Horizontal or vertical in view
GFactor = TxtH_P.AsDouble * GapFactor
GFactor *= AcView.Scale
End If
If Dm.Segments.Size = 0 Then
UpdateDimText(Doc, Dm, TxtH, GFactor)
Else
For si = 0 To Dm.Segments.Size - 1
Dim DSeg As DimensionSegment = Dm.Segments(si)
UpdateDimText(Doc, DSeg, TxtH, GFactor)
Next
End If
Next
tx.Commit()
End If
End Using
End Sub
Private Class SelDimCatFilt
Implements Autodesk.Revit.UI.Selection.ISelectionFilter
Public Function AllowElement(elem As Element) As Boolean Implements Autodesk.Revit.UI.Selection.ISelectionFilter.AllowElement
Return elem.Category.Id.IntegerValue = CInt(BuiltInCategory.OST_Dimensions)
End Function
Public Function AllowReference(reference As Reference, position As XYZ) As Boolean Implements Autodesk.Revit.UI.Selection.ISelectionFilter.AllowReference
Return False
End Function
End Class
End Class
We were doing some testing on the macro and was curious why macros are disabled in assembly views? is this a setting we can change? or is built into Revit?
No that is odd, I've never noticed it.
I assume perhaps you can still run the macro on an assembly view but you need to start it from another view.
I tried to do that, but once I open macro manager, it does not allow me to interact with Revit until I close it. I might post this into the API forum and see if anyone with Autodesk knows the reason or has an answer. I appreciate all your help! It works great in all the views that really matter. We are developing a dynamo workaround in the assembly views, but since we rarely do assembly drawings, your macro will help us out tremendously. Kudos!
Can't find what you're looking for? Ask the community or share your knowledge.