Grenco Posted March 1, 2012 Share Posted March 1, 2012 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? Quote Link to comment Share on other sites More sharing options...
fixo Posted March 1, 2012 Share Posted March 1, 2012 You can try to edit non activelayout like this Dim actSpace as acadblock Set actSpace=thisdrawing.layouts("Object_ID").Block 'then you can to do your things in there directly, eg.: actspace.addline(p1,p2) actspace.addcircle(p3, radius) ETC... ~'J'~ Quote Link to comment Share on other sites More sharing options...
Grenco Posted March 1, 2012 Author Share Posted March 1, 2012 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" Quote Link to comment Share on other sites More sharing options...
fixo Posted March 1, 2012 Share Posted March 1, 2012 Something like this may helps, change to your suit: 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'~ Quote Link to comment Share on other sites More sharing options...
Grenco Posted March 1, 2012 Author Share Posted March 1, 2012 You are the best!! Quote Link to comment Share on other sites More sharing options...
fixo Posted March 1, 2012 Share Posted March 1, 2012 Glad I could help Cheers ~'J'~ Quote Link to comment Share on other sites More sharing options...
Grenco Posted March 15, 2012 Author Share Posted March 15, 2012 Because I want to improve the perfomance..... How can I replace this slow command: 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? Quote Link to comment Share on other sites More sharing options...
fixo Posted March 15, 2012 Share Posted March 15, 2012 Not tried but maube CopyObjects method may helps Just an idea Quote Link to comment Share on other sites More sharing options...
fixo Posted March 15, 2012 Share Posted March 15, 2012 Because I want to improve the perfomance..... How can I replace this slow command: 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 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'~ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.