Find Last Layout

Find Last Layout

Anonymous
Not applicable
449 Views
5 Replies
Message 1 of 6

Find Last Layout

Anonymous
Not applicable
In order to create a new layout in my drawing, I'm trying to copy the last layout in my drawing...with the following code...

objAcad.ActiveDocument.SendCommand("layout" & vbCr & "c" & vbCr & _ objAcad.ActiveDocument.Layouts.Item(objAcad.ActiveDocument.Layouts.Count).Name & vbCr)

Code which quickly returns the error message..."Value does not fall within the expected range."

I'm trying to somehow refer to the last layout in my drawing...

Could anyone lend a hand please??

Thanks!

Pete
0 Likes
450 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
The Layouts.Count will give the the amount of Layouts but Item starts counting from 0 not 1 so try

objAcad.ActiveDocument.Layouts.Item(objAcad.ActiveDocument.Layouts.Count-1).Name & vbCr)

and see how that works for you
0 Likes
Message 3 of 6

mdhutchinson
Advisor
Advisor
Hi PellaCAD... you back at working solo?
0 Likes
Message 4 of 6

Anonymous
Not applicable
Hi ya' hutch...

Naw...I'm still gainfully employed...and lovin' it! (Still got my "second job" that I do in my "spare time"...and lovin' that too!)

I'm puttin' the finishing touches (yeah right, like that'll ever happen...) on this latest VB.NET effort...getting better and better at this...

(This VB user group seriously rocks!)

Anyways, I'm climbin' back in under the hood...say "hey" via email sometime...later!

Pedro

(Thanks Rednut...your reply confirmed that I had forgotten to specify the name of the new layout tab!!! DOH!!!)
0 Likes
Message 5 of 6

Anonymous
Not applicable
I've tested this about 4 different ways...

I still can not make the last layout tab the active tab.

There is obviously something fundaMENTAL about how one is expected to work with layout tabs...

Does anyone have any clues??

I want to add a new layout by copying the last layout in a drawing.
0 Likes
Message 6 of 6

Anonymous
Not applicable
Hi Pete, how about doing it with code instead of SendCommand?

Sub CreateLayoutFromLastLayout()
Dim oLayouts As AcadLayouts
Dim oLayout As AcadLayout
Dim oLayout2Copy As AcadLayout
Dim i As Integer

Set oLayouts = ThisDrawing.Layouts
i = oLayouts.Count - 1
'Find the last Layout as shown in the Layout bar
For Each oLayout In oLayouts
If oLayout.TabOrder = i Then Set oLayout2Copy = oLayout
Next

'Create the Layout
Dim oCopiedLayout As AcadLayout
Set oCopiedLayout = oLayouts.Add("MyNewLayout")

'Now copy all of the objects from the original to the new
Dim oArray() As AcadEntity
ReDim oArray(oLayout2Copy.Block.Count - 1)
For i = 0 To oLayout2Copy.Block.Count - 1
Set oArray(i) = oLayout2Copy.Block(i)
Next
ThisDrawing.CopyObjects oArray, oCopiedLayout.Block

'Finally, copy the PlotConfig Settings
oCopiedLayout.CopyFrom oLayout2Copy

End Sub

"PellaCAD" wrote in message news:5828516@discussion.autodesk.com...
In order to create a new layout in my drawing, I'm trying to copy the last
layout in my drawing...with the following code...

objAcad.ActiveDocument.SendCommand("layout" & vbCr & "c" & vbCr & _
objAcad.ActiveDocument.Layouts.Item(objAcad.ActiveDocument.Layouts.Count).Name
& vbCr)

Code which quickly returns the error message..."Value does not fall within
the expected range."

I'm trying to somehow refer to the last layout in my drawing...

Could anyone lend a hand please??

Thanks!

Pete
0 Likes