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

how to save a layer group in autocad.net

5 REPLIES 5
Reply
Message 1 of 6
pauline_liz
974 Views, 5 Replies

how to save a layer group in autocad.net

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

5 REPLIES 5
Message 2 of 6
hgasty1001
in reply to: pauline_liz

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

Message 3 of 6
pauline_liz
in reply to: hgasty1001

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

Message 4 of 6
hgasty1001
in reply to: pauline_liz

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

Message 5 of 6
pauline_liz
in reply to: pauline_liz

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

Message 6 of 6
hgasty1001
in reply to: pauline_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

 

 

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost