VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

7 REPLIES 7
Reply
Message 1 of 8
richardv24
2665 Views, 7 Replies

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

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

7 REPLIES 7
Message 2 of 8

Hi,

 

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

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 3 of 8

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

Message 4 of 8

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
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 5 of 8

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

Message 6 of 8

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
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 7 of 8

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

Message 8 of 8

You are very welcome! - alfred -

 

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost