<?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 Nested Copy in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/nested-copy/m-p/994575#M55507</link>
    <description>I wanted to write my own nested copy command in VBA that is like the NCOPY Express Tool except does not prompt for base and displacement points. (I also find NCOPY to be slow) I thought it would be quite simple but it doesn't seem to be simple enough for me. I can get a subentity a tell if it is nested one level down from a Block or XREF but can't work out how to copy it into modelspace. Any help will be greatly appreciated. This code is as far as I got:&lt;BR /&gt;
----------&lt;BR /&gt;
Option Explicit&lt;BR /&gt;
&lt;BR /&gt;
Public Sub test()&lt;BR /&gt;
Dim objEnt As AcadEntity&lt;BR /&gt;
Dim varPickedPoint As Variant&lt;BR /&gt;
Dim varTransMatrix As Variant&lt;BR /&gt;
Dim varContextData As Variant&lt;BR /&gt;
Dim objEntParent As AcadEntity&lt;BR /&gt;
On Error GoTo ErrorHandler&lt;BR /&gt;
ThisDrawing.Utility.GetSubEntity objEnt, varPickedPoint, varTransMatrix, varContextData&lt;BR /&gt;
On Error GoTo 0&lt;BR /&gt;
If IsEmpty(varContextData) = False Then&lt;BR /&gt;
    If UBound(varContextData) = 0 Then&lt;BR /&gt;
        Set objEntParent = ThisDrawing.ObjectIdToObject(varContextData(0))&lt;BR /&gt;
        If TypeOf objEntParent Is AcadBlockReference Then&lt;BR /&gt;
           &lt;BR /&gt;
            &lt;BR /&gt;
        End If&lt;BR /&gt;
    End If&lt;BR /&gt;
End If&lt;BR /&gt;
Exit Sub&lt;BR /&gt;
ErrorHandler:&lt;BR /&gt;
Resume&lt;BR /&gt;
End Sub&lt;BR /&gt;
----------&lt;BR /&gt;
Regards - Nathan</description>
    <pubDate>Fri, 02 Apr 2004 07:37:05 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2004-04-02T07:37:05Z</dc:date>
    <item>
      <title>Nested Copy</title>
      <link>https://forums.autodesk.com/t5/vba-forum/nested-copy/m-p/994575#M55507</link>
      <description>I wanted to write my own nested copy command in VBA that is like the NCOPY Express Tool except does not prompt for base and displacement points. (I also find NCOPY to be slow) I thought it would be quite simple but it doesn't seem to be simple enough for me. I can get a subentity a tell if it is nested one level down from a Block or XREF but can't work out how to copy it into modelspace. Any help will be greatly appreciated. This code is as far as I got:&lt;BR /&gt;
----------&lt;BR /&gt;
Option Explicit&lt;BR /&gt;
&lt;BR /&gt;
Public Sub test()&lt;BR /&gt;
Dim objEnt As AcadEntity&lt;BR /&gt;
Dim varPickedPoint As Variant&lt;BR /&gt;
Dim varTransMatrix As Variant&lt;BR /&gt;
Dim varContextData As Variant&lt;BR /&gt;
Dim objEntParent As AcadEntity&lt;BR /&gt;
On Error GoTo ErrorHandler&lt;BR /&gt;
ThisDrawing.Utility.GetSubEntity objEnt, varPickedPoint, varTransMatrix, varContextData&lt;BR /&gt;
On Error GoTo 0&lt;BR /&gt;
If IsEmpty(varContextData) = False Then&lt;BR /&gt;
    If UBound(varContextData) = 0 Then&lt;BR /&gt;
        Set objEntParent = ThisDrawing.ObjectIdToObject(varContextData(0))&lt;BR /&gt;
        If TypeOf objEntParent Is AcadBlockReference Then&lt;BR /&gt;
           &lt;BR /&gt;
            &lt;BR /&gt;
        End If&lt;BR /&gt;
    End If&lt;BR /&gt;
End If&lt;BR /&gt;
Exit Sub&lt;BR /&gt;
ErrorHandler:&lt;BR /&gt;
Resume&lt;BR /&gt;
End Sub&lt;BR /&gt;
----------&lt;BR /&gt;
Regards - Nathan</description>
      <pubDate>Fri, 02 Apr 2004 07:37:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/nested-copy/m-p/994575#M55507</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2004-04-02T07:37:05Z</dc:date>
    </item>
    <item>
      <title>Re: Nested Copy</title>
      <link>https://forums.autodesk.com/t5/vba-forum/nested-copy/m-p/994576#M55508</link>
      <description>Refreshed after the weekend I worked out how to copy an object in a XREF in to modelspace. So if anyone was interested here is the code.&lt;BR /&gt;
----------&lt;BR /&gt;
Option Explicit&lt;BR /&gt;
&lt;BR /&gt;
Public Sub test()&lt;BR /&gt;
Dim objEnt As AcadEntity&lt;BR /&gt;
Dim varPickedPoint As Variant&lt;BR /&gt;
Dim varTransMatrix As Variant&lt;BR /&gt;
Dim varContextData As Variant&lt;BR /&gt;
Dim objEntParent As AcadEntity&lt;BR /&gt;
Dim objEnts(0) As AcadEntity&lt;BR /&gt;
Dim varReturned As Variant&lt;BR /&gt;
On Error GoTo ErrorHandler&lt;BR /&gt;
ThisDrawing.Utility.GetSubEntity objEnt, varPickedPoint, varTransMatrix, varContextData&lt;BR /&gt;
On Error GoTo 0&lt;BR /&gt;
If IsEmpty(varContextData) = False Then&lt;BR /&gt;
    If UBound(varContextData) = 0 Then&lt;BR /&gt;
        Set objEntParent = ThisDrawing.ObjectIdToObject(varContextData(0))&lt;BR /&gt;
        If TypeOf objEntParent Is AcadExternalReference Then&lt;BR /&gt;
            Set objEnts(0) = objEnt&lt;BR /&gt;
            varReturned = ThisDrawing.Blocks(objEntParent.Name).XRefDatabase.CopyObjects(objEnts, ThisDrawing.ModelSpace)&lt;BR /&gt;
        End If&lt;BR /&gt;
    End If&lt;BR /&gt;
End If&lt;BR /&gt;
Exit Sub&lt;BR /&gt;
ErrorHandler:&lt;BR /&gt;
Resume&lt;BR /&gt;
End Sub&lt;BR /&gt;
----------&lt;BR /&gt;
Regards - Nathan</description>
      <pubDate>Mon, 05 Apr 2004 00:12:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/nested-copy/m-p/994576#M55508</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2004-04-05T00:12:12Z</dc:date>
    </item>
    <item>
      <title>Re: Nested Copy</title>
      <link>https://forums.autodesk.com/t5/vba-forum/nested-copy/m-p/994577#M55509</link>
      <description>I spoke too soon. The CopyObjects method returns "Invalid owner object" when text is selected.&lt;BR /&gt;
Regards - Nathan</description>
      <pubDate>Mon, 05 Apr 2004 00:30:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/nested-copy/m-p/994577#M55509</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2004-04-05T00:30:43Z</dc:date>
    </item>
    <item>
      <title>Re: Nested Copy</title>
      <link>https://forums.autodesk.com/t5/vba-forum/nested-copy/m-p/994578#M55510</link>
      <description>Just in case anyone is interested here is what I ended up with. I find it quicker and easier than NCOPY but it does not copy multiply nested objects or objects containing nested objects.&lt;BR /&gt;
--------------------&lt;BR /&gt;
Option Explicit&lt;BR /&gt;
Private Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Long) As Integer&lt;BR /&gt;
&lt;BR /&gt;
Public Sub XCopy()&lt;BR /&gt;
Dim objSSet As AcadSelectionSet&lt;BR /&gt;
Dim blnError As Boolean&lt;BR /&gt;
Dim objEnt As AcadEntity&lt;BR /&gt;
Dim varPickedPoint As Variant&lt;BR /&gt;
Dim varTransMatrix As Variant&lt;BR /&gt;
Dim varContextData As Variant&lt;BR /&gt;
Dim objEntParent As AcadEntity&lt;BR /&gt;
Dim objEnts(0) As AcadEntity&lt;BR /&gt;
Dim varReturned As Variant&lt;BR /&gt;
Dim intIndex As Integer&lt;BR /&gt;
Dim strLType As String&lt;BR /&gt;
Dim strTStyle As String&lt;BR /&gt;
GetAsyncKeyState (&amp;amp;H2)&lt;BR /&gt;
GetAsyncKeyState (&amp;amp;H1B)&lt;BR /&gt;
GetAsyncKeyState (&amp;amp;HD)&lt;BR /&gt;
If ThisDrawing.Layers("0").Freeze = True Then ThisDrawing.Layers("0").Freeze = False&lt;BR /&gt;
Set objSSet = CreateSSet.CreateEmptySSet&lt;BR /&gt;
Do&lt;BR /&gt;
    blnError = False&lt;BR /&gt;
    On Error GoTo ErrorHandler&lt;BR /&gt;
    ThisDrawing.Utility.GetSubEntity objEnt, varPickedPoint, varTransMatrix, varContextData&lt;BR /&gt;
    On Error GoTo 0&lt;BR /&gt;
    If blnError = True Then&lt;BR /&gt;
        If GetAsyncKeyState(&amp;amp;H2) Then Exit Do 'Right Button Click&lt;BR /&gt;
        If GetAsyncKeyState(&amp;amp;HD) Then Exit Do  'Enter Key Press&lt;BR /&gt;
        If GetAsyncKeyState(&amp;amp;H1B) Then 'Esc Key Press&lt;BR /&gt;
            objSSet.Erase&lt;BR /&gt;
            objSSet.Delete&lt;BR /&gt;
            Exit Sub&lt;BR /&gt;
        End If&lt;BR /&gt;
    Else&lt;BR /&gt;
        If IsEmpty(varContextData) = False Then&lt;BR /&gt;
            If UBound(varContextData) = 0 Then&lt;BR /&gt;
                Set objEntParent = ThisDrawing.ObjectIdToObject(varContextData(0))&lt;BR /&gt;
                If TypeOf objEntParent Is AcadExternalReference Then&lt;BR /&gt;
                    Set objEnts(0) = objEnt&lt;BR /&gt;
                    strLType = objEnt.Linetype&lt;BR /&gt;
                    objEnt.Linetype = "ByLayer"&lt;BR /&gt;
                    If TypeOf objEnt Is AcadText Then&lt;BR /&gt;
                        strTStyle = objEnt.StyleName&lt;BR /&gt;
                        objEnt.StyleName = "State|Standard"&lt;BR /&gt;
                    End If&lt;BR /&gt;
                    varReturned = ThisDrawing.Blocks(objEntParent.Name).XRefDatabase.CopyObjects(objEnts, ThisDrawing.ModelSpace)&lt;BR /&gt;
                    If TypeOf objEnt Is AcadText Then&lt;BR /&gt;
                        objEnt.StyleName = strTStyle&lt;BR /&gt;
                    End If&lt;BR /&gt;
                    objEnt.Linetype = strLType&lt;BR /&gt;
                    varReturned(0).Layer = "0"&lt;BR /&gt;
                    varReturned(0).Highlight (True)&lt;BR /&gt;
                    Set objEnts(0) = varReturned(0)&lt;BR /&gt;
                    objSSet.AddItems (objEnts)&lt;BR /&gt;
                End If&lt;BR /&gt;
            End If&lt;BR /&gt;
        End If&lt;BR /&gt;
    End If&lt;BR /&gt;
Loop&lt;BR /&gt;
For Each objEnt In objSSet&lt;BR /&gt;
    objEnt.Highlight (False)&lt;BR /&gt;
Next objEnt&lt;BR /&gt;
objSSet.Delete&lt;BR /&gt;
Exit Sub&lt;BR /&gt;
ErrorHandler:&lt;BR /&gt;
blnError = True&lt;BR /&gt;
Resume Next&lt;BR /&gt;
End Sub&lt;BR /&gt;
--------------------&lt;BR /&gt;
Regards - Nathan</description>
      <pubDate>Thu, 13 May 2004 06:51:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/nested-copy/m-p/994578#M55510</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2004-05-13T06:51:55Z</dc:date>
    </item>
  </channel>
</rss>

