Visual Basic Customization

Visual Basic Customization

Reply
Active Member
richardv24
Posts: 9
Registered: ‎08-13-2012
Message 1 of 8 (754 Views)

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

754 Views, 7 Replies
08-13-2012 11:17 AM

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

*Expert Elite*
Alfred.NESWADBA
Posts: 9,070
Registered: ‎06-29-2007
Message 2 of 8 (735 Views)

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

08-13-2012 01:00 PM in reply to: richardv24

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
-------------------------------------------------------------------------
Active Member
richardv24
Posts: 9
Registered: ‎08-13-2012
Message 3 of 8 (732 Views)

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

08-13-2012 01:27 PM in reply to: Alfred.NESWADBA

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

*Expert Elite*
Alfred.NESWADBA
Posts: 9,070
Registered: ‎06-29-2007
Message 4 of 8 (727 Views)

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

08-13-2012 01:39 PM in reply to: richardv24

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
-------------------------------------------------------------------------
Active Member
richardv24
Posts: 9
Registered: ‎08-13-2012
Message 5 of 8 (726 Views)

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

08-13-2012 01:48 PM in reply to: Alfred.NESWADBA

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

*Expert Elite*
Alfred.NESWADBA
Posts: 9,070
Registered: ‎06-29-2007
Message 6 of 8 (716 Views)

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

08-13-2012 02:18 PM in reply to: richardv24

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
-------------------------------------------------------------------------
Active Member
richardv24
Posts: 9
Registered: ‎08-13-2012
Message 7 of 8 (714 Views)

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

08-13-2012 02:26 PM in reply to: Alfred.NESWADBA

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

*Expert Elite*
Alfred.NESWADBA
Posts: 9,070
Registered: ‎06-29-2007
Message 8 of 8 (711 Views)

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

08-13-2012 02:28 PM in reply to: richardv24

You are very welcome! - alfred -

 

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.