getting Dimension Segment data

Question: Can we use the API to automatically add up all of the dimension segments in a single string of dimensions? I want to use it to check the sum of a string of dimensions against an overall dimension for coordination purposes.

Answer:

Capture

public void DimensionSegments()
{
    Document doc = this.ActiveUIDocument.Document;
    UIDocument uidoc = this.ActiveUIDocument;
    Dimension dim = doc.GetElement(uidoc.Selection.PickObject(ObjectType.Element)) as Dimension;
    double total = 0;
    string segmentsWithText = "";
    string segmentsNoText = "";
    string segmentValues = "";
    foreach (DimensionSegment dimSeg in dim.Segments)
    {
        total += (double)dimSeg.Value;
        
        segmentsWithText += dimSeg.ValueString + Environment.NewLine;
        
        string segmentString = dimSeg.ValueString;
        if (dimSeg.Above != null && dimSeg.Above != "")
            segmentString = segmentString.Replace(dimSeg.Above,"");
        if (dimSeg.Prefix != null && dimSeg.Prefix != "")
            segmentString = segmentString.Replace(dimSeg.Prefix,"");
        if (dimSeg.Suffix != null && dimSeg.Suffix != "")
            segmentString = segmentString.Replace(dimSeg.Suffix,"");
        if (dimSeg.Below != null && dimSeg.Below != "")
            segmentString = segmentString.Replace(dimSeg.Below,"");
        segmentsNoText += segmentString.TrimStart(' ') + Environment.NewLine;
    
        segmentValues += dimSeg.Value + Environment.NewLine;
    }
    TaskDialog.Show("Total Dimension", 
                    "Sum of lengths: " + total + Environment.NewLine + Environment.NewLine +
                    "Segment text:" + Environment.NewLine + segmentsWithText + Environment.NewLine + 
                    "Segments no text:" + Environment.NewLine + segmentsNoText + Environment.NewLine + 
                    "Segment values:" + Environment.NewLine + segmentValues);
}
        
Advertisements

13 thoughts on “getting Dimension Segment data

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s