Get Specific Name Layouts Name and Build a list

Get Specific Name Layouts Name and Build a list

Anonymous
Not applicable
1,819 Views
12 Replies
Message 1 of 13

Get Specific Name Layouts Name and Build a list

Anonymous
Not applicable

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

 

0 Likes
1,820 Views
12 Replies
Replies (12)
Message 2 of 13

philippe.leefsma
Alumni
Alumni

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

0 Likes
Message 3 of 13

Anonymous
Not applicable

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

 

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

 

 

0 Likes
Message 4 of 13

philippe.leefsma
Alumni
Alumni

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

0 Likes
Message 5 of 13

jaboone
Advocate
Advocate

Perhaps a c to vb converter.

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

 

Learning as I go
0 Likes
Message 6 of 13

Anonymous
Not applicable

I am using the convertor now.

 

Is while statement best to build a list.

Can you let me know the best approach?

0 Likes
Message 7 of 13

philippe.leefsma
Alumni
Alumni

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

0 Likes
Message 8 of 13

Anonymous
Not applicable

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

0 Likes
Message 9 of 13

philippe.leefsma
Alumni
Alumni

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

0 Likes
Message 10 of 13

jaboone
Advocate
Advocate

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
Message 11 of 13

Anonymous
Not applicable

Search aganist a specfic layouts. 

I am trying to bring back files with name starts with "Page #"

0 Likes
Message 12 of 13

jaboone
Advocate
Advocate

I like this method the best.  there are more.  if you think there are more than 50, increase the number.

 

<Serializable()> _
Public Class LayoutNames

#Region "Declarations"
Private _LayoutName(0 To 50) As String
Private _LayoutNumber(0 To 50) As Integer
#End Region

#Region "Layout General Properties"
Public Property LayoutName(ByVal x As Integer) As String
Get
Return _LayoutName(x)
End Get
Set(ByVal value As String)
_LayoutName(x) = value
End Set
End Property

Public Property LayoutNumber(ByVal x As Integer) As Integer
Get
Return _LayoutNumber(x)
End Get
Set(ByVal value As Integer)
_LayoutNumber(x) = value
End Set
End Property

#End Region
End Class


Private Sub fix()
Dim numberoflayouts As Integer
Dim LON As New LayoutNames
Dim x As Integer

numberoflayouts = 10
For x = 0 To numberoflayouts
LON.LayoutName(x) = "Name"
LON.LayoutNumber(x) = x
Next


End Sub

 

 

Learning as I go
0 Likes
Message 13 of 13

jaboone
Advocate
Advocate

of course the lines of code in sub 'fix' will have to be integrated into your while, but it gives the idea.

Learning as I go
0 Likes