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
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.
I am trying to search through the layouts and bring back only specific layouts names.
Add to list if layouts that begin with "Page #".
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...
Perhaps a c to vb converter.
http://www.developerfusion.com/tools/convert/csharp-to-vb/
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.
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.
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.
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
of course the lines of code in sub 'fix' will have to be integrated into your while, but it gives the idea.
Can't find what you're looking for? Ask the community or share your knowledge.