actually there is afuntionality provided to save a layer and load a layer but i need to save a layer group and load a layer group
Hi,
I think this is a translation from C# to VB from the Kean's blog, it creates a layer group:
Imports Autodesk.AutoCAD.LayerManager
Public Function GetLayerId(ByVal LayerName As String) As ObjectId Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument Dim acCurDb As Database = acDoc.Database Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor Dim ret As ObjectId Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction() Dim acLyrTbl As LayerTable acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId, OpenMode.ForRead) If acLyrTbl.Has(LayerName) Then For Each objId As ObjectId In acLyrTbl Dim LyrTblRec As LayerTableRecord = acTrans.GetObject(objId, OpenMode.ForRead) If LyrTblRec.Name.ToUpper = LayerName.ToUpper Then ret = objId Exit For End If Next End If End Using Return ret End Function Public Sub CreateLayerGroup(ByVal LayerList As List(Of String), ByVal groupName As string) Dim ObjIdList As New ObjectIdCollection Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument Dim Db As Database = acDoc.Database Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor For Each Lyr As String In LayerList Dim ObjId As ObjectId = GetLayerId(Lyr) If Not ObjId.IsNull Then ObjIdList.Add(ObjId) End If Next Dim lft As LayerFilterTree = Db.LayerFilters Dim lfc As LayerManager.LayerFilterCollection = lft.Root.NestedFilters ' Create a new layer group Dim lg As New LayerGroup() lg.Name = groupName ' Add our layers' IDs to the list For Each id As ObjectId In ObjIdList lg.LayerIds.Add(id) Next ' Add the group to the collection Dim LgExists As Boolean = False For i As Integer = 0 To lfc.Count - 1 Dim lf As LayerFilter = lfc(i) If lf.Name = lg.Name Then LgExists = True Exit For End If Next If Not LgExists Then lfc.Add(lg) End If ' Set them back on the Database Db.LayerFilters = lft End Sub
Gaston Nunez
hi,
Thanks for ur reply but i want to save a layer group not to create a layer group can u please help me in this
Hi,
Sorry, can you please explain what do you mean with "save a layer group", or what is the difference with create one?
Gaston Nunez
Hi,
actually m new to autocad. when we rightclick on a single FDO layer we can save that layer in our local system in such a way i want to save a layer group.
more over if u dont mind can u pls help in c#
Regards,
liz
Hi,
As you are talking about FDO, I guess you are working in AutoCAD MAP (or Civil 3D), and that is a complete different animal, FDO has his own API (documentation here: Map API), you can get more help posting in the : Map Developers Group
It helps a lot ( both, you and the guys trying to help) to post your exact platform (Map 3D 2012 for example) , 32/64 bits, .NET Framework, OS, and a clear explanation of your intended workflow or aim.
Gaston Nunez