'//////////////////////////////////////////////////////////////////////////////
'//
'//  Copyright 2025 Autodesk, Inc.  All rights reserved.
'//
'//  Use of this software is subject to the terms of the Autodesk license 
'//  agreement provided at the time of installation or download, or which 
'//  otherwise accompanies this software in either electronic or hard copy form.   
'//
'//////////////////////////////////////////////////////////////////////////////
'

Imports System.Runtime.InteropServices
Imports System.Reflection
Imports System.Type

Imports SymBBAuto.McadOrientation
Imports SymBBAuto.McadWeldSymbolType
Imports AcadmAuto.McadObjectType
Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common
Imports Autodesk.AutoCAD.Runtime
Imports AcadmAuto
Imports SymBBAuto
Imports GEAuto

<Assembly: ExtensionApplication(GetType(netSectionLine.netSectionLine))>
<Assembly: CommandClass(GetType(netSectionLine.CreateCommand))>

Namespace netSectionLine

    Public Class netSectionLine
        Implements Autodesk.AutoCAD.Runtime.IExtensionApplication

        ' Declaration of global variables
        Dim acmApp As AcadmApplication
        Dim symbb As McadSymbolBBMgr
        Dim acadApp As AcadApplication = Library.COM.getActiveObject("AutoCAD.Application.26")
        Dim ThisDrawing As AcadDocument = acadApp.ActiveDocument
        Private acAllViewports As AcRegenType

        Public Sub Initialize() Implements IExtensionApplication.Initialize

        End Sub

        Public Sub Terminate() Implements IExtensionApplication.Terminate

        End Sub

        Public Sub createSectionLine()
            Dim sectionline As McadSectionLine = ThisDrawing.ModelSpace.AddCustomObject("AmdtSectionSym")

            ' Set properties
            sectionline.ArrowVisibility = True
            sectionline.PlaneSymbolsVisibility = True
            sectionline.LineVisibility = McadLineVisibility.sbBetweenPlanes

            ' Set vertexes of section line
            Dim points(0 To 11) As Double

            points(0) = 12 : points(1) = 13 : points(2) = 0
            points(3) = 14 : points(4) = 10 : points(5) = 0
            points(6) = 13 : points(7) = 8 : points(8) = 0
            points(9) = 16 : points(10) = 6 : points(11) = 0

            Dim ArcPoints(0 To 2) As Double
            ArcPoints(0) = 13.5 : ArcPoints(1) = 9 : ArcPoints(2) = 0

            ' Set segment type of section line
            Dim segmentTypes(0 To 3) As McadSectionLineSegmentType
            segmentTypes(0) = McadSectionLineSegmentType.sbLineSegment
            segmentTypes(1) = McadSectionLineSegmentType.sbArcSegmentCenter
            segmentTypes(2) = McadSectionLineSegmentType.sbLineSegment
            segmentTypes(3) = McadSectionLineSegmentType.sbLineSegment

            sectionline.SetSectionPoints(points, ArcPoints, segmentTypes)

            ' Section side
            Dim sidePoint(0 To 2) As Double
            sidePoint(0) = 12 : sidePoint(1) = 10 : sidePoint(2) = 0
            sectionline.SectionSide = sidePoint

            ' Set label name
            sectionline.LabelName = "D"

            ' Get the number of label names
            Dim noOfNames As Integer
            noOfNames = sectionline.LabelNamesCount

            Dim labelPoint(0 To 2) As Double
            labelPoint(0) = 16 : labelPoint(1) = 11 : labelPoint(2) = 0
            ' Set origin of section view. This function must be invoked after posting section line to database.
            sectionline.SetSectionViewOrigin(labelPoint)

            sectionline.Update()

        End Sub

        Public Sub SectionLineStandard()
            'define and get the symbol manager
            Dim symbb As McadSymbolBBMgr = ThisDrawing.Application.GetInterfaceObject("SymBBAuto.McadSymbolBBMgr.27")
            Dim stdmgr As McadStandardMgr = symbb.StandardMgr
            Dim std As McadStandard = stdmgr.CurrentStandard
            ' section line standard
            Dim sectionStd As McadSectionLineStandard = std.SectionLineStandard

            ' Set label properties
            sectionStd.LabelVisibility = True
            sectionStd.PlaneSymbolsVisibility = True
            sectionStd.MultipleNamesSupported = False

            ' Set plane view properties
            sectionStd.LabelPattern = "=SECTION <SECTION_LABEL_FIRST>-<SECTION_LABEL_FIRST>"
            sectionStd.LabelAbove = False

            ' Set line properties
            sectionStd.LineWeight = ACAD_LWEIGHT.acLnWt018
            sectionStd.LineColor = ACAD_COLOR.acByLayer
            sectionStd.LineVisibility = McadLineVisibility.sbBetweenPlanes

            sectionStd.ArrowVisibility = True

            'Update all section lines in drawing
            ThisDrawing.Regen(acAllViewports)
        End Sub
    End Class

    Public Class CreateCommand

        ' Declaration of global variables
        Dim sl As New netSectionLine

        <Autodesk.AutoCAD.Runtime.CommandMethod("CREATESECTIONLINE")>
        Public Sub sectionline()
            ' Create new section line
            sl.createSectionLine()
        End Sub

        <Autodesk.AutoCAD.Runtime.CommandMethod("SECTIONLINESTD")>
        Public Sub SectionLineStandard()
            ' Edit section line standard by current standard
            sl.SectionLineStandard()
        End Sub
    End Class

End Namespace