.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

create layer - will now show in layermanager

2 REPLIES 2
Reply
Message 1 of 3
jan_tappenbeck
244 Views, 2 Replies

create layer - will now show in layermanager

hi!

 

know i try to create a layer by vb.net - there is no mistake, but the layer will not create!

 

could someone help me?

 

regards Jan

 

Public Function CreateLayer(ByVal sLayerName As String, Optional LyIdxColor As Integer = 7, _
                                                                Optional ByVal LWeight As DatabaseServices.LineWeight = DatabaseServices.LineWeight.ByLineWeightDefault, _
                                                                Optional ByVal LyOff As Boolean = False, _
                                                                Optional ByVal LyFrozen As Boolean = False, _
                                                                Optional ByVal lyLock As Boolean = False, _
                                                                Optional ByVal lyPlotable As Boolean = True, _
        Optional ByVal lyLType As String = "Continuous", _
                                                                Optional ByVal LayDescription As String = "") As Integer
        ' ------ http://ma22-wiki-001/eblwiki/index.php?title=Acad_(Klasse_von_EBL.MapService)#CreateLayer ------
        Dim Status As Integer = -1
        '' Get the current document and database
        Dim acDoc As Autodesk.AutoCAD.ApplicationServices.Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        Dim acCurDb As Database = acDoc.Database
        Dim LayerId As ObjectId

        If LyIdxColor < 1 Or LyIdxColor > 255 Then LyIdxColor = 7

        Try



            '' Start a transaction
            Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()

                '' Open the Layer table for read
                Dim acLyrTbl As LayerTable

                Using acDoc.LockDocument

                    acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead)

                    ' wenn der Layer vorhanden, dann passiert nichts
                    If acLyrTbl.Has(sLayerName) = True Then
                        Status = 0
                    Else
                        ' Layer anlegen
                        Dim ltr As New LayerTableRecord
                        ' Eigenschaften zuweisen
                        With ltr
                            .Color = Color.FromColorIndex(ColorMethod.ByAci, LyIdxColor)
                            .LineWeight = LWeight
                            .IsOff = LyOff
                            .IsFrozen = LyFrozen
                            .IsLocked = lyLock
                            .IsPlottable = lyPlotable
                            .Description = LayDescription
                            '    .LinetypeObjectId = GetLineTypeId(lyLType)

                        End With
                        acLyrTbl.UpgradeOpen()

                        LayerId = acLyrTbl.Add(ltr)

                        acTrans.AddNewlyCreatedDBObject(ltr, True)

                        '' Save the changes
                        acTrans.Commit()

                    End If
                End Using 'acDoc.LockDocument

                '' Dispose of the transaction
            End Using
        Catch ex As Exception

            Dim ErrorDetail As String = "sLayerName: " & sLayerName & vbCrLf & _
                            "LyIdxColor: " & LyIdxColor.ToString & vbCrLf & _
                                                                            "LWeight: " & LWeight.ToString & vbCrLf & _
                                                                            "LyOff: " & LyOff.ToString & vbCrLf & _
                                                                            "LyFrozen: " & LyFrozen.ToString & vbCrLf & _
                                                                            "lyLock: " & lyLock.ToString & vbCrLf & _
                                                                            "lyPlotable: " & lyPlotable.ToString & vbCrLf & _
                    "lyLType: " & lyLType & vbCrLf

            If LayDescription.Length = 0 Then
                LayDescription = LayDescription & "LayDescription: nicht angegeben!" & vbCrLf
            Else
                LayDescription = LayDescription & "LayDescription: " & LayDescription & vbCrLf
            End If

            _TryReport.Show("unerwarteter Fehler in EBL.MapService > acad > SetLayerCurrent", ex.ToString)
            Status = -1
        End Try

        Return Status
    End Function
2 REPLIES 2
Message 2 of 3
_gile
in reply to: jan_tappenbeck

Hi,

 

It seems to me you don't assign any value to the Name property of the newly created LayerTableRecord.

 

SymbolTableRecord.Name value is used as a key in the SymbolTable.

 

 

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 3
jan_tappenbeck
in reply to: _gile

hi !

 

thanks for fast help!

 

regards Jan

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report