Help Copy and paste a created selection set to a point X distance away

Help Copy and paste a created selection set to a point X distance away

Anonymous
Not applicable
3,600 Views
7 Replies
Message 1 of 8

Help Copy and paste a created selection set to a point X distance away

Anonymous
Not applicable

Hi guys,

 

I am fairly new to both autocad and VBA, so I would appreciate if you guys work with me a little.  I was wable to write some code that makes some already drawn objects on autocad into a selection set.  What I need to do next is copy the selected objects and move them over like a distance of 50 to the right.  I have been struggling with this for a long time now and would appreciate some help.

 

Thanks in advance

0 Likes
3,601 Views
7 Replies
Replies (7)
Message 2 of 8

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

show that code-parts you have, that makes it easier for helpers to know where to start.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 3 of 8

Anonymous
Not applicable

ok here is my code.  Now remember I am new so please dont laugh >.> I have a lot of comments from it removed as they were things I was trying so I hope I didnt delete any of my regular code.  The code I have on the bottom actually selects the items from 0,500 to 500,0 crossing.  I can confrim this by highlighting it.  In the end, I put a move command in which I thought would move my entire selection, but only moves one line from a bunch of lines that it selected (not sure why).  Anyway, my ultimate goal is to get the selected lines or objects to be copied a distance away.

 

Thanks for the quick reply. (my code was partially taken from a book I have with me)

 

 

 

      Dim varPnt1(0 To 2) As Double
      Dim varPnt2(0 To 2) As Double    
      Dim test1(0 To 2) As Double
      Dim test2(0 To 2) As Double    
      Dim objSS As AcadSelectionSet
      Dim str0pt As String
      Dim lngMode As Long
      
      With ThisDrawing.Utility
      
      .InitializeUserInput 1, "Window Crossing Previous Last All"
      str0pt = .GetKeyword(vbCr & _
      "Select [Window/Crossing/Previous/Last/All]: ")
      
      Select Case str0pt
      Case "Crossing": lngMode = acSelectionSetCrossing
      End Select
      
      
      
     Set objSS = ThisDrawing.SelectionSets.Add("Test11")
      
    
    varPnt1(0) = 0: varPnt1(1) = 500: varPnt1(2) = 0
    varPnt2(0) = 500: varPnt2(1) = 0: varPnt2(2) = 0
     
      objSS.Select acSelectionSetCrossing, varPnt1, varPnt2
      
      
      test1(0) = 0: test1(1) = 0: test1(2) = 0
    test2(0) = 500: test2(1) = 0: test2(2) = 0
   

        objSS.Item(Test11).Move test1, test2
       
        
        
    
      
    
      End With

0 Likes
Message 4 of 8

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> Now remember I am new so please dont laugh

Never, I have no reason to laugh if someone puts a question here!

 

I have not tried the code, the only one I see is the variable Test11 is missing that you tried to use to get an item from the selection set. That has to be repaired, then it should work. Try to modify the last lines (after creating the selection set):

 

dim i as integer

'for each item in the selection set:

for i = 0 to objSS.count - 1

   'move the item

   call objSS.Item(i).Move(test1, test2)

next   'next item in the selection set

 

Let me know if that works now as you like.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
Message 5 of 8

Anonymous
Not applicable

THAT WORKED BRILLIANTLY.

 

Just one more question.  Instead of moving the items, how would I go about copying them so the original stays in place as well.

 

Thanks a buch

0 Likes
Message 6 of 8

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> how would I go about copying them so the original stays in place as well.

Within the loop change the move to this lines:

 

dim tSourceEnt as AcadEntity

set tSourceEnt = objSS.Item(i)

'copy the original entity

dim tCopyEnt as AcadEntity

set tCopyEnt = tSourceEnt.Copy

'now move the copied entity

call tCopyEnt.Move(test1,test2)

 

HTH, -alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 7 of 8

Anonymous
Not applicable

fantastic.  Wish I had asked this question yesterday.  You saved me many many hours of harship.  Thanks so much

0 Likes
Message 8 of 8

Alfred.NESWADBA
Consultant
Consultant

You are very welcome! - alfred -

 

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes