Labels a dimension with this global parameter.
Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 18.0.0.0 (18.2.0.0)
Since:
2016 Subscription Update
Syntax
C# |
---|
public void LabelDimension(
ElementId dimensionId
) |
Visual Basic |
---|
Public Sub LabelDimension ( _
dimensionId As ElementId _
) |
Visual C++ |
---|
public:
void LabelDimension(
ElementId^ dimensionId
) |
Remarks
Examples
CopyC#
public int DriveSelectedDimensions(Document document, string name, double value, ISet<ElementId> dimset)
{
if (!GlobalParametersManager.AreGlobalParametersAllowed(document))
throw new System.InvalidOperationException("Global parameters are not permitted in the given document");
if (!GlobalParametersManager.IsUniqueName(document, name))
throw new System.ArgumentException("Global parameter with such name already exists in the document", "name");
if (value <= 0.0)
throw new System.ArgumentException("Value of a global parameter that drives dimension must be a positive number", "value");
int nLabeledDims = 0;
using (Transaction trans = new Transaction(document, "Create Global Parameter"))
{
trans.Start();
GlobalParameter newgp = GlobalParameter.Create(document, name, ParameterType.Length);
if (newgp != null)
{
newgp.SetValue(new DoubleParameterValue(value));
foreach (ElementId elemid in dimset)
{
if (newgp.CanLabelDimension(elemid))
{
newgp.LabelDimension(elemid);
nLabeledDims += 1;
}
}
trans.Commit();
}
}
ElementId gpid = GlobalParametersManager.FindByName(document,name);
if (gpid == ElementId.InvalidElementId)
{
TaskDialog.Show("Error", "Failed to find a newly created global parameter");
}
GlobalParameter gp = document.GetElement(gpid) as GlobalParameter;
ISet<ElementId> labeledSet = gp.GetLabeledDimensions();
if (labeledSet.Count != nLabeledDims)
{
TaskDialog.Show("Error", "Have not found all the dimension that were labeled.");
}
return labeledSet.Count;
}
CopyVB.NET
Public Function DriveSelectedDimensions(document As Document, name As String, value As Double, dimset As ISet(Of ElementId)) As Integer
If Not GlobalParametersManager.AreGlobalParametersAllowed(document) Then
Throw New System.InvalidOperationException("Global parameters are not permitted in the given document")
End If
If Not GlobalParametersManager.IsUniqueName(document, name) Then
Throw New System.ArgumentException("Global parameter with such name already exists in the document", "name")
End If
If value <= 0.0 Then
Throw New System.ArgumentException("Value of a global parameter that drives dimension must be a positive number", "value")
End If
Dim nLabeledDims As Integer = 0
Using trans As New Transaction(document, "Create Global Parameter")
trans.Start()
Dim newgp As GlobalParameter = GlobalParameter.Create(document, name, ParameterType.Length)
If newgp IsNot Nothing Then
newgp.SetValue(New DoubleParameterValue(value))
For Each elemid As ElementId In dimset
If newgp.CanLabelDimension(elemid) Then
newgp.LabelDimension(elemid)
nLabeledDims += 1
End If
Next
trans.Commit()
End If
End Using
Dim gpid As ElementId = GlobalParametersManager.FindByName(document, name)
If gpid = ElementId.InvalidElementId Then
TaskDialog.Show("Error", "Failed to find a newly created global parameter")
End If
Dim gp As GlobalParameter = TryCast(document.GetElement(gpid), GlobalParameter)
Dim labeledSet As ISet(Of ElementId) = gp.GetLabeledDimensions()
If labeledSet.Count <> nLabeledDims Then
TaskDialog.Show("Error", "Have not found all the dimension that were labeled.")
End If
Return labeledSet.Count
End Function
Exceptions
Exception | Condition |
---|
Autodesk.Revit.Exceptions..::..ArgumentException |
Given element Id is not of a valid dimension element.
-or-
Dimension with the Id of dimensionId cannot be labeled by this global parameter.
Possible causes include the dimension cannot be labeled at all, or it is a dimension
of other than Linear or Angular type, or the Dimension object does not have the
appropriate labeling parameter, or the dimension has more than one segment and the parameter
is reporting.
|
Autodesk.Revit.Exceptions..::..ArgumentNullException |
A non-optional argument was NULL
|
See Also