.NET

Reply
Member
apatel
Posts: 5
Registered: ‎11-27-2012
Message 1 of 13 (249 Views)

Get Specific Name Layouts Name and Build a list

249 Views, 12 Replies
07-16-2013 05:16 AM

I am trying to first get all the layouts name and add specfic layouts names to the list and call a specfic function. 

 

So far this what I got so far. 

 

I am able to get list all the layouts in the drawing.

 

   ' List all the layouts in the current drawing
        <CommandMethod("ListLayouts")> _
        Public Shared Sub ListLayouts()
            ' Get the current document and database
            Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
            Dim acCurDb As Database = acDoc.Database

            Dim i As Integer = 0

            Do While (i < 10)

            Loop

            ' Get the layout dictionary of the current database
            Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
                Dim lays As DBDictionary = _
                    acTrans.GetObject(acCurDb.LayoutDictionaryId, OpenMode.ForRead)

                acDoc.Editor.WriteMessage(vbLf & "Layouts:")

                ' Step through and list each named layout and Model
                For Each item As DBDictionaryEntry In lays
                    acDoc.Editor.WriteMessage(vbLf & "  " & item.Key)
                Next

                ' Abort the changes to the database
                acTrans.Abort()
            End Using
        End Sub

 

ADN Support Specialist
philippe.leefsma
Posts: 632
Registered: ‎06-02-2009
Message 2 of 13 (236 Views)

Re: Get Specific Name Layouts Name and Build a list

07-16-2013 07:06 AM in reply to: apatel

Hi Apatel,

 

Sorry but your request is a bit obscure, to say the least... What is it that you are trying to do exactly and are you having any issue with the code you pointed out?

 

Here are some samples that use the LayoutManager:

 

[CommandMethod("IterateLayouts")]
static public void IterateLayouts()
{
    Document doc = Application.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;
    Editor ed = doc.Editor;

    using (Transaction Tx = db.TransactionManager.StartTransaction())
    {
        using (DBDictionary layoutDict = Tx.GetObject(
            db.LayoutDictionaryId, 
            OpenMode.ForRead) as DBDictionary)
        {
            foreach (DBDictionaryEntry entry in layoutDict)
            {
                ed.WriteMessage("\n - Layout: " + entry.Key + 
                    " ObjectId: " + entry.Value.ToString());
            }   
        }

        Tx.Commit();
    }
}

 

[CommandMethod("NewLayout")]
static public void NewLayout()
{
    Document doc = Application.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;
    Editor ed = doc.Editor;

    string layoutName = "MyLayout";

    using (Transaction Tx = db.TransactionManager.StartTransaction())
    {
        LayoutManager layoutMgr = LayoutManager.Current;

        ObjectId layoutId = layoutMgr.CreateLayout(layoutName);

        Layout layout = Tx.GetObject(layoutId, OpenMode.ForWrite) 
            as Layout;
                
        layout.Initialize();

        Tx.Commit();
    }
}

 

Regards,

Philippe.



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Member
apatel
Posts: 5
Registered: ‎11-27-2012
Message 3 of 13 (231 Views)

Re: Get Specific Name Layouts Name and Build a list

07-16-2013 07:12 AM in reply to: philippe.leefsma

I am trying to search through the layouts and bring back only specific layouts names. 

 

Add to list if  layouts that begin with "Page #".

 

 

ADN Support Specialist
philippe.leefsma
Posts: 632
Registered: ‎06-02-2009
Message 4 of 13 (228 Views)

Re: Get Specific Name Layouts Name and Build a list

07-16-2013 07:15 AM in reply to: apatel

Ok... then what is the issue you are facing now? looking at the IterateLayout code I provided, this should be quite straighforward to build a list based on specific layout names...

 



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Valued Contributor
jaboone
Posts: 91
Registered: ‎12-05-2011
Message 5 of 13 (225 Views)

Re: Get Specific Name Layouts Name and Build a list

07-16-2013 07:19 AM in reply to: philippe.leefsma

Perhaps a c to vb converter.

http://www.developerfusion.com/tools/convert/csharp-to-vb/

 

Learning as I go
Member
apatel
Posts: 5
Registered: ‎11-27-2012
Message 6 of 13 (221 Views)

Re: Get Specific Name Layouts Name and Build a list

07-16-2013 07:21 AM in reply to: jaboone

I am using the convertor now.

 

Is while statement best to build a list.

Can you let me know the best approach?

ADN Support Specialist
philippe.leefsma
Posts: 632
Registered: ‎06-02-2009
Message 7 of 13 (211 Views)

Re: Get Specific Name Layouts Name and Build a list

07-16-2013 07:45 AM in reply to: apatel

It's not really a forum where we teach people the basics of programming. The conditional structure you are using, whether it's a While, foreach, or other kind of loop depends on several factors, one can be a personal preference, a performance criteria and so on... i would say on such a basic scenario, it doesn't really matter if you use a while or foreach loop, the execution time will be so neglectible that both approaches will work. I have a preference for a foreach loop in that case, since you want to iterate the whole collection of layouts anyway.

 

Regards,

Philippe.



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Member
apatel
Posts: 5
Registered: ‎11-27-2012
Message 8 of 13 (208 Views)

Re: Get Specific Name Layouts Name and Build a list

07-16-2013 07:49 AM in reply to: philippe.leefsma

Ok. can you point me a sample how this is created. 

ADN Support Specialist
philippe.leefsma
Posts: 632
Registered: ‎06-02-2009
Message 9 of 13 (206 Views)

Re: Get Specific Name Layouts Name and Build a list

07-16-2013 07:51 AM in reply to: apatel

You want to know how to build a list in VB.Net...? The easiest way is to type "using list vb.net" in your favorite search engine.



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Valued Contributor
jaboone
Posts: 91
Registered: ‎12-05-2011
Message 10 of 13 (205 Views)

Re: Get Specific Name Layouts Name and Build a list

07-16-2013 07:54 AM in reply to: philippe.leefsma

For a list there are many methods.  To check the list against a known value there are also many other methods.

You have to be more specific.

 

Learning as I go
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.