﻿using System.IO;
using System.Runtime.InteropServices;

internal static class Example
{
    [STAThread()]
    public static void Main()
    {

        SolidEdgeFramework.Application objApplication = null;
        SolidEdgeDraft.DraftDocument objDraftDocument = null;
        SolidEdgeDraft.Sheet objSheet = null;
        SolidEdgeFrameworkSupport.Dimensions objDimensions = null;
        SolidEdgeFrameworkSupport.Dimension objHzDimension = null;
        SolidEdgeFrameworkSupport.Dimension objVtDimension = null;
        SolidEdgeFrameworkSupport.Lines2d objLines2d = null;
        SolidEdgeFrameworkSupport.DimStyle objDimStyle = null;
        SolidEdgeFrameworkSupport.Line2d objHzLine2d = null;
        SolidEdgeFrameworkSupport.Line2d objVtLine2d = null;

        try
        {
            OleMessageFilter.Register();

            objApplication = (SolidEdgeFramework.Application)Marshal.GetActiveObject("SolidEdge.Application");
            objDraftDocument = objApplication.Documents.Add("SolidEdge.DraftDocument");

            //Get the active sheet
            objSheet = objDraftDocument.ActiveSheet;

            //Get the lines collection and dimensions collection.
            objLines2d = objSheet.Lines2d;
            objDimensions = objSheet.Dimensions;

            //Add a horizontal line and a vertical line
            objHzLine2d = objLines2d.AddBy2Points(x1:0.2, y1:0.2, x2:0.3, y2:0.2);
            objVtLine2d = objLines2d.AddBy2Points(x1:0.35, y1:0.35, x2:0.35, y2:0.25);

            //Add dimensions to the lines that are created above.
            objHzDimension = objDimensions.AddLength(object:objHzLine2d);
            objVtDimension = objDimensions.AddLength(object:objVtLine2d);

            //Get the horizontal dim style
            objDimStyle = objHzDimension.Style;

            //Get and Set Secondary Linear tolerance decimal round off.
            objDimStyle.SecondaryLinearToleranceDecimalRoundOff = SolidEdgeConstants.DimDecimalRoundOffTypeConstants.igDimStyleDecimal_3;

        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
        finally
        {
            OleMessageFilter.Revoke();
        }
    }
}