<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: copy layers to new drawing in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/copy-layers-to-new-drawing/m-p/1730955#M31970</link>
    <description>Im hesitant to use any other object libraries than the included autocad ones as I am building a program to be used on many different machines with cad already installed, it would probably cause more problems to install new libraries than it would to just write the code without using them&lt;BR /&gt;
&lt;BR /&gt;
Ive pretty much worked out the part where i copy the entities to the other drawing, my problem is that since i am doing this multiple times i need to reset my active drawing to the drawing i had when i first ran my program.  currently it looks like this:&lt;BR /&gt;
&lt;BR /&gt;
Set origDWG = Application.ActiveDocument   'i set the original drawing here&lt;BR /&gt;
Application.ActiveDocument = origDWG  'then i recall the drawing later in the program&lt;BR /&gt;
&lt;BR /&gt;
The problem is obviously that since origDWG is set to Application.ActiveDocument when i go to reset the drawing it sets it to the current open drawing, not the original.  any ideas as to how this might be fixed?

Message was edited by: sryabinin</description>
    <pubDate>Thu, 10 Aug 2006 15:50:00 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2006-08-10T15:50:00Z</dc:date>
    <item>
      <title>copy layers to new drawing</title>
      <link>https://forums.autodesk.com/t5/vba-forum/copy-layers-to-new-drawing/m-p/1730953#M31968</link>
      <description>Ok so heres another thing i could use some input on &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
In the drawings im building this macro for all the layers are label "1-rest of the layer name", "2-", "3-", "4-" and so on.  What i need to do is write a procedure which takes everything on the "1-" and "2-" layers and copies them to a new drawing, then procedes with 3- and 4-, 5,6 and so on.  heres what i have so far&lt;BR /&gt;
&lt;BR /&gt;
Private Sub subCopyToNewDoc()&lt;BR /&gt;
 Dim objLayer As AcadLayer&lt;BR /&gt;
 Dim strLayer() As String&lt;BR /&gt;
 Dim i As Integer&lt;BR /&gt;
 Dim keepgoing As Boolean&lt;BR /&gt;
    Dim str1 As String&lt;BR /&gt;
    Dim str2 As String&lt;BR /&gt;
    &lt;BR /&gt;
    Dim origDWG As AcadDocument&lt;BR /&gt;
    Dim newDWG As AcadDocument&lt;BR /&gt;
    Set origDWG = ThisDrawing&lt;BR /&gt;
    &lt;BR /&gt;
    str1 = "1-"&lt;BR /&gt;
    str2 = "2-"&lt;BR /&gt;
    keepgoing = True&lt;BR /&gt;
    &lt;BR /&gt;
    While keepgoing&lt;BR /&gt;
        ReDim strLayer(100)&lt;BR /&gt;
        i = 0&lt;BR /&gt;
        For Each objLayer In ThisDrawing.Layers&lt;BR /&gt;
            If Left(objLayer.Name, 2) = str1 Or str2 Then&lt;BR /&gt;
                strLayer(i) = objLayer.Name&lt;BR /&gt;
                i = i + 1&lt;BR /&gt;
                objLayer.LayerOn = True&lt;BR /&gt;
            Else&lt;BR /&gt;
                objLayer.LayerOn = False&lt;BR /&gt;
            End If&lt;BR /&gt;
        Next&lt;BR /&gt;
        ReDim strLayer(i - 1)&lt;BR /&gt;
        &lt;BR /&gt;
        ThisDrawing.SendCommand ("copybase 0,0 c -10000,-10000 10000,1000" &amp;amp; vbCr &amp;amp; vbCr)&lt;BR /&gt;
        Set newDWG = Application.Documents.Add&lt;BR /&gt;
        newDWG.SendCommand ("pasteclip 0,0" &amp;amp; vbCr)&lt;BR /&gt;
        Application.ActiveDocument = origDWG  --------------error here----&lt;BR /&gt;
        &lt;BR /&gt;
        str1 = str(CInt(Left(str1, 1)) + 2) &amp;amp; "-"&lt;BR /&gt;
        str2 = str(CInt(Left(str2, 1)) + 2) &amp;amp; "-"&lt;BR /&gt;
        &lt;BR /&gt;
        keepgoing = False&lt;BR /&gt;
        For Each objLayer In ThisDrawing.Layers&lt;BR /&gt;
            If Left(objLayer.Name, 2) = str1 Or str2 Then keepgoing = True&lt;BR /&gt;
        Next&lt;BR /&gt;
    Wend&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
As it stands now the error says "Failed to get the Document Object" on the marked line where i try to reset the active drawing to the drawing i originally started with.</description>
      <pubDate>Wed, 09 Aug 2006 17:53:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/copy-layers-to-new-drawing/m-p/1730953#M31968</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-08-09T17:53:21Z</dc:date>
    </item>
    <item>
      <title>Re: copy layers to new drawing</title>
      <link>https://forums.autodesk.com/t5/vba-forum/copy-layers-to-new-drawing/m-p/1730954#M31969</link>
      <description>Here is another way with using of ObjecDBX&lt;BR /&gt;
I incuded to copy Xref's layers also&lt;BR /&gt;
&lt;BR /&gt;
Option Explicit&lt;BR /&gt;
'' Requires reference to:&lt;BR /&gt;
'' Visual Basic For Applications&lt;BR /&gt;
'' AutoCAD 2005 Type Library&lt;BR /&gt;
'' Ole Automation&lt;BR /&gt;
'' AutoCAD/ObjectDBX Common 16. Type Library&lt;BR /&gt;
'' AutoCAD/ObjectDBX Common 1.0 Type Library: -&amp;gt; not sure about&lt;BR /&gt;
'' Visual Lisp ActiveX module: -&amp;gt; not sure about&lt;BR /&gt;
Public Sub DBXCopyLayers(ByVal fname As String)&lt;BR /&gt;
Dim oDbx As Object&lt;BR /&gt;
Dim olayer As AcadLayer&lt;BR /&gt;
Dim i As Integer&lt;BR /&gt;
With ThisDrawing.Application&lt;BR /&gt;
Set oDbx = .GetInterfaceObject("ObjectDBX.AxDbDocument.16") '' or 17 for A2007&lt;BR /&gt;
End With&lt;BR /&gt;
&lt;BR /&gt;
oDbx.Open FileName:=fname&lt;BR /&gt;
&lt;BR /&gt;
Dim copyVar() As Object&lt;BR /&gt;
&lt;BR /&gt;
For Each olayer In oDbx.Layers&lt;BR /&gt;
If Not olayer.Name Like "0,Defpoints" Then&lt;BR /&gt;
ReDim Preserve copyVar(i)&lt;BR /&gt;
Set copyVar(i) = olayer&lt;BR /&gt;
i = i + 1&lt;BR /&gt;
End If&lt;BR /&gt;
Next&lt;BR /&gt;
Dim idPairs As Variant&lt;BR /&gt;
Dim copyObj As Variant&lt;BR /&gt;
copyObj = oDbx.CopyObjects(copyVar, ThisDrawing.Layers, idPairs)&lt;BR /&gt;
Set oDbx = Nothing&lt;BR /&gt;
&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
Sub TestCopyLayers()&lt;BR /&gt;
Dim fname As String&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
On Error GoTo WeHaveAProblem&lt;BR /&gt;
'' change full path name for the donor &lt;BR /&gt;
fname = "D:\MyFavouriteDwg.dwg"&lt;BR /&gt;
&lt;BR /&gt;
Call DBXCopyLayers(fname)&lt;BR /&gt;
&lt;BR /&gt;
WeHaveAProblem:&lt;BR /&gt;
If Err Then&lt;BR /&gt;
MsgBox "ObjectDBX CopyObjects method objects failed." &amp;amp; vbCr &amp;amp; Err.Number &amp;amp; " " &amp;amp; _&lt;BR /&gt;
Err.Description, vbCritical&lt;BR /&gt;
End If&lt;BR /&gt;
&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Fatty&lt;BR /&gt;
&lt;BR /&gt;
~'J'~</description>
      <pubDate>Wed, 09 Aug 2006 19:43:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/copy-layers-to-new-drawing/m-p/1730954#M31969</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-08-09T19:43:46Z</dc:date>
    </item>
    <item>
      <title>Re: copy layers to new drawing</title>
      <link>https://forums.autodesk.com/t5/vba-forum/copy-layers-to-new-drawing/m-p/1730955#M31970</link>
      <description>Im hesitant to use any other object libraries than the included autocad ones as I am building a program to be used on many different machines with cad already installed, it would probably cause more problems to install new libraries than it would to just write the code without using them&lt;BR /&gt;
&lt;BR /&gt;
Ive pretty much worked out the part where i copy the entities to the other drawing, my problem is that since i am doing this multiple times i need to reset my active drawing to the drawing i had when i first ran my program.  currently it looks like this:&lt;BR /&gt;
&lt;BR /&gt;
Set origDWG = Application.ActiveDocument   'i set the original drawing here&lt;BR /&gt;
Application.ActiveDocument = origDWG  'then i recall the drawing later in the program&lt;BR /&gt;
&lt;BR /&gt;
The problem is obviously that since origDWG is set to Application.ActiveDocument when i go to reset the drawing it sets it to the current open drawing, not the original.  any ideas as to how this might be fixed?

Message was edited by: sryabinin</description>
      <pubDate>Thu, 10 Aug 2006 15:50:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/copy-layers-to-new-drawing/m-p/1730955#M31970</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-08-10T15:50:00Z</dc:date>
    </item>
    <item>
      <title>Re: copy layers to new drawing</title>
      <link>https://forums.autodesk.com/t5/vba-forum/copy-layers-to-new-drawing/m-p/1730956#M31971</link>
      <description>Use the Documents collection to set origDWG.&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
R. Robert Bell</description>
      <pubDate>Thu, 10 Aug 2006 16:21:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/copy-layers-to-new-drawing/m-p/1730956#M31971</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-08-10T16:21:23Z</dc:date>
    </item>
    <item>
      <title>Re: copy layers to new drawing</title>
      <link>https://forums.autodesk.com/t5/vba-forum/copy-layers-to-new-drawing/m-p/1730957#M31972</link>
      <description>Assuming that only one drawing is open at the start would this work?&lt;BR /&gt;
&lt;BR /&gt;
Set origDWG = Documents.Item(0)&lt;BR /&gt;
&lt;BR /&gt;
Edit: Nevermind, i got it..thank you

Message was edited by: sryabinin</description>
      <pubDate>Thu, 10 Aug 2006 16:56:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/copy-layers-to-new-drawing/m-p/1730957#M31972</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-08-10T16:56:46Z</dc:date>
    </item>
    <item>
      <title>Re: copy layers to new drawing</title>
      <link>https://forums.autodesk.com/t5/vba-forum/copy-layers-to-new-drawing/m-p/1730958#M31973</link>
      <description>А не мог бы, ты мил человек, мне по-нашему растолмачить,&lt;BR /&gt;
а то мы по-аглицки не шибко....&lt;BR /&gt;
А и для практики мне бы польза &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
fixo@yandex.ru&lt;BR /&gt;
&lt;BR /&gt;
Fatty&lt;BR /&gt;
&lt;BR /&gt;
~'J'~</description>
      <pubDate>Fri, 11 Aug 2006 10:16:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/copy-layers-to-new-drawing/m-p/1730958#M31973</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-08-11T10:16:07Z</dc:date>
    </item>
  </channel>
</rss>

