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

Get Specific Name Layouts Name and Build a list

12 REPLIES 12
Reply
Message 1 of 13
apatel
1210 Views, 12 Replies

Get Specific Name Layouts Name and Build a list

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

 

12 REPLIES 12
Message 2 of 13
philippe.leefsma
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

Message 3 of 13
apatel
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 #".

 

 

Message 4 of 13
philippe.leefsma
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

Message 5 of 13
jaboone
in reply to: philippe.leefsma

Perhaps a c to vb converter.

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

 

Learning as I go
Message 6 of 13
apatel
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?

Message 7 of 13
philippe.leefsma
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

Message 8 of 13
apatel
in reply to: philippe.leefsma

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

Message 9 of 13
philippe.leefsma
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

Message 10 of 13
jaboone
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
Message 11 of 13
apatel
in reply to: jaboone

Search aganist a specfic layouts. 

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

Message 12 of 13
jaboone
in reply to: jaboone

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
Message 13 of 13
jaboone
in reply to: jaboone

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

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