+ Reply to Thread
Results 1 to 9 of 9
  1. #1
    Full Member Grenco's Avatar
    Computer Details
    Grenco's Computer Details
    Operating System:
    Vista
    Computer:
    Dell Precision T3400
    Using
    AutoCAD 2010
    Join Date
    Jan 2009
    Location
    Den Bosch, Holland
    Posts
    74

    Question VBA - How to edit in a not active layout

    Hello all, long time no see...

    I got a small problem.

    I've got a "template"-layout called Basis. This is a layout wich I want to copy and rename. So far so good.

    To copy:
    ThisDrawing.SendCommand "_layout" & vbCr & "C" & vbCr & "Basis" & vbCr & RSCheck.Fields("Object_ID") & vbCr
    (RSCheck.Fields... is a .mdb recordset wich contains the values I want to use, The Object_ID is the name of the new layout)

    Now I want to edit some attributes in the new copied layout.
    ThisDrawing.ActiveLayout = ThisDrawing.Layouts((RSCheck.Fields("Object_ID")))

    The layout I want to edit is now active and I'm able to edit everything I want.

    The problem is that I have to copy AND edit about 250 layouts. It's running a bit slow because I have to activate the layout. Is there a way in VBA to make changes in a layout without activating it?

    I hoped to use For Each Elem In ThisDrawing.Layouts(RSCheck.Fields("Object_ID")) but that doesnt work.

    Who can help me?

  2. #2
    Super Member fixo's Avatar
    Computer Details
    fixo's Computer Details
    Operating System:
    Windows 7
    Motherboard:
    E7500
    CPU:
    Intel(R)Core(TM)2 DUO CPU 2.93HGz
    RAM:
    4098 Gb
    Graphics:
    1024 Gb
    Using
    AutoCAD 2009
    Join Date
    Jul 2005
    Location
    Thanks God, I'm far enough from Hitleropa
    Posts
    1,697

    Default

    You can try to edit non activelayout like this

    Code:
     
    Dim actSpace as acadblock
    Set actSpace=thisdrawing.layouts("Object_ID").Block
    'then you can to do your things in there directly, eg.:
    Code:
     
    actspace.addline(p1,p2)
    actspace.addcircle(p3, radius) ETC...


    ~'J'~
    The soul is healed by being with children. - Fyodor Dostoyevsky, novelist (1821-1881)

  3. #3
    Full Member Grenco's Avatar
    Computer Details
    Grenco's Computer Details
    Operating System:
    Vista
    Computer:
    Dell Precision T3400
    Using
    AutoCAD 2010
    Join Date
    Jan 2009
    Location
    Den Bosch, Holland
    Posts
    74

    Default

    Thank you for your reply Fixo!

    actspace.add** is all about adding lines or other elements.
    But how can I read all the elements and modify that are inside of the copied layout?

    I want to modify a block with attributes in the layout called "KADER"

  4. #4
    Super Member fixo's Avatar
    Computer Details
    fixo's Computer Details
    Operating System:
    Windows 7
    Motherboard:
    E7500
    CPU:
    Intel(R)Core(TM)2 DUO CPU 2.93HGz
    RAM:
    4098 Gb
    Graphics:
    1024 Gb
    Using
    AutoCAD 2009
    Join Date
    Jul 2005
    Location
    Thanks God, I'm far enough from Hitleropa
    Posts
    1,697

    Default

    Something like this may helps, change to your suit:

    Code:
     
    Dim ent as acadentity
    Dim blkref as acadblockreference
    for each ent in actspace
     
    if typeof ent is acadblockreference then
    set blkref=ent
     
    if blkref.Effectivename="KADER" then
    dim atts as variant
    dim att as attributereference
    atts= blkref.getattributes
     
    for each att in atts
    if att.tagstring="MYTAG" then
    att.textstring="MYVALUE"
    exit for
    end if
    next att
     
    end if
     
    end if
     
    next ent

    ~'J'~
    The soul is healed by being with children. - Fyodor Dostoyevsky, novelist (1821-1881)

  5. #5
    Full Member Grenco's Avatar
    Computer Details
    Grenco's Computer Details
    Operating System:
    Vista
    Computer:
    Dell Precision T3400
    Using
    AutoCAD 2010
    Join Date
    Jan 2009
    Location
    Den Bosch, Holland
    Posts
    74

    Default

    You are the best!!

  6. #6
    Super Member fixo's Avatar
    Computer Details
    fixo's Computer Details
    Operating System:
    Windows 7
    Motherboard:
    E7500
    CPU:
    Intel(R)Core(TM)2 DUO CPU 2.93HGz
    RAM:
    4098 Gb
    Graphics:
    1024 Gb
    Using
    AutoCAD 2009
    Join Date
    Jul 2005
    Location
    Thanks God, I'm far enough from Hitleropa
    Posts
    1,697

    Default

    Glad I could help
    Cheers

    ~'J'~
    The soul is healed by being with children. - Fyodor Dostoyevsky, novelist (1821-1881)

  7. #7
    Full Member Grenco's Avatar
    Computer Details
    Grenco's Computer Details
    Operating System:
    Vista
    Computer:
    Dell Precision T3400
    Using
    AutoCAD 2010
    Join Date
    Jan 2009
    Location
    Den Bosch, Holland
    Posts
    74

    Default

    Because I want to improve the perfomance..... How can I replace this slow command:
    Code:
     
    ThisDrawing.SendCommand "_layout" & vbCr & "C" & vbCr & "Basis" & vbCr & RSCheck.Fields("Object_ID") & vbCr
    Is there a better way to copy a layout without using .SendCommand?

  8. #8
    Super Member fixo's Avatar
    Computer Details
    fixo's Computer Details
    Operating System:
    Windows 7
    Motherboard:
    E7500
    CPU:
    Intel(R)Core(TM)2 DUO CPU 2.93HGz
    RAM:
    4098 Gb
    Graphics:
    1024 Gb
    Using
    AutoCAD 2009
    Join Date
    Jul 2005
    Location
    Thanks God, I'm far enough from Hitleropa
    Posts
    1,697

    Default

    Not tried but maube CopyObjects method may helps
    Just an idea
    The soul is healed by being with children. - Fyodor Dostoyevsky, novelist (1821-1881)

  9. #9
    Super Member fixo's Avatar
    Computer Details
    fixo's Computer Details
    Operating System:
    Windows 7
    Motherboard:
    E7500
    CPU:
    Intel(R)Core(TM)2 DUO CPU 2.93HGz
    RAM:
    4098 Gb
    Graphics:
    1024 Gb
    Using
    AutoCAD 2009
    Join Date
    Jul 2005
    Location
    Thanks God, I'm far enough from Hitleropa
    Posts
    1,697

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by Grenco View Post
    Because I want to improve the perfomance..... How can I replace this slow command:
    Code:
     
    ThisDrawing.SendCommand "_layout" & vbCr & "C" & vbCr & "Basis" & vbCr & RSCheck.Fields("Object_ID") & vbCr
    Is there a better way to copy a layout without using .SendCommand?
    Try this way that I mentioned earlier

    Code:
     
    Option Explicit
    Public Sub CopyFromLayout()
        Dim oLayoutCopy As AcadLayout
        Dim oLayout As AcadLayout
        Dim objCollection() As Object
        Dim n
        Set oLayoutCopy = ThisDrawing.Layouts.Add("MyNewLayoutName") ' <---> 'ThisDrawing.Layouts.Add(RSCheck.Fields ("Object_ID"))
        Set oLayout = ThisDrawing.Layouts.Item("Basis")
        ThisDrawing.ActiveLayout = oLayoutCopy '<-- for the fast work
        With oLayout.Block
            If .count > 0 Then
            ReDim objCollection(0 To .count - 1)
            For n = 0 To .count - 1
                Set objCollection(n) = .Item(n)
            Next
            ThisDrawing.CopyObjects objCollection, oLayoutCopy.Block
        End If
       End With
       oLayoutCopy.CopyFrom oLayout '<-- to copy other things from "Basis": plot settings, etc
    End Sub
    ~'J'~
    The soul is healed by being with children. - Fyodor Dostoyevsky, novelist (1821-1881)

Similar Threads

  1. text edit in layout - problem
    By flopo in forum AutoCAD General
    Replies: 8
    Last Post: 3rd Mar 2011, 09:11 am
  2. layout lisp (help with edit)
    By lutcus in forum AutoLISP, Visual LISP & DCL
    Replies: 18
    Last Post: 30th Sep 2010, 10:02 pm
  3. Edit Table Layout
    By Bill Tillman in forum AutoCAD General
    Replies: 0
    Last Post: 14th Aug 2009, 12:08 am
  4. VB.Net question - active viewport in a layout
    By Tipo166 in forum AutoLISP, Visual LISP & DCL
    Replies: 1
    Last Post: 22nd Apr 2009, 03:56 pm
  5. Edit Layout Template Block Information
    By cbpack51 in forum AutoCAD Drawing Management & Output
    Replies: 4
    Last Post: 27th Mar 2009, 03:57 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts