.NET

Reply
Member
pauline_liz
Posts: 4
Registered: ‎12-18-2012
Message 1 of 6 (378 Views)

how to save a layer group in autocad.net

378 Views, 5 Replies
12-18-2012 04:25 AM

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

Distinguished Mentor
gasty1001
Posts: 576
Registered: ‎04-11-2010
Message 2 of 6 (365 Views)

Re: how to save a layer group in autocad.net

12-18-2012 05:33 AM 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

Member
pauline_liz
Posts: 4
Registered: ‎12-18-2012
Message 3 of 6 (362 Views)

Re: how to save a layer group in autocad.net

12-18-2012 05:47 AM in reply to: gasty1001

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

Distinguished Mentor
gasty1001
Posts: 576
Registered: ‎04-11-2010
Message 4 of 6 (356 Views)

Re: how to save a layer group in autocad.net

12-18-2012 05:57 AM 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

Member
pauline_liz
Posts: 4
Registered: ‎12-18-2012
Message 5 of 6 (354 Views)

Re: how to save a layer group in autocad.net

12-18-2012 06:02 AM 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

Distinguished Mentor
gasty1001
Posts: 576
Registered: ‎04-11-2010
Message 6 of 6 (350 Views)

Re: how to save a layer group in autocad.net

12-18-2012 06:15 AM 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

 

 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!