'
'  (C) Copyright 2008 by Autodesk, Inc.  All rights reserved.
'
' Permission to use, copy, modify, and distribute this software in
' object code form for any purpose and without fee is hereby granted, 
' provided that the above copyright notice appears in all copies and 
' that both that copyright notice and the limited warranty and
' restricted rights notice below appear in all supporting 
' documentation.
'
' AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS. 
' AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
' MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK, INC. 
' DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
' UNINTERRUPTED OR ERROR FREE.
'
' Use, duplication, or disclosure by the U.S. Government is subject to 
' restrictions set forth in FAR 52.227-19 (Commercial Computer
' Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
' (Rights in Technical Data and Computer Software), as applicable.
'
' This sample application shows how to create section line using COM API in SymBBAuto.
' To start the application, run CREATESECTIONLINE command.
'

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

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common.AcRegenType
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Interop.Common

Imports SymBBAuto.McadOrientation
Imports SymBBAuto.McadWeldSymbolType
Imports AcadmAuto.McadObjectType
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 = System.Runtime.InteropServices.Marshal.GetActiveObject("AutoCAD.Application.18")
        Dim ThisDrawing As AcadDocument = acadApp.ActiveDocument

        Public Sub Initialize() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Initialize

        End Sub

        Public Sub Terminate() Implements Autodesk.AutoCAD.Runtime.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")
            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
