Jump to content

VBA - How to edit in a not active layout


Grenco

Recommended Posts

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?

Link to comment
Share on other sites

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'~

Link to comment
Share on other sites

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"

Link to comment
Share on other sites

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'~

Link to comment
Share on other sites

  • 2 weeks later...

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?

Link to comment
Share on other sites

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'~

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...