• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    Visual Basic Customization

    Reply
    Active Member
    Posts: 9
    Registered: ‎08-13-2012

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

    255 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

    Please use plain text.
    *Expert Elite*
    Posts: 6,474
    Registered: ‎06-29-2007

    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
    -------------------------------------------------------------------------
    Please use plain text.
    Active Member
    Posts: 9
    Registered: ‎08-13-2012

    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

    Please use plain text.
    *Expert Elite*
    Posts: 6,474
    Registered: ‎06-29-2007

    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
    -------------------------------------------------------------------------
    Please use plain text.
    Active Member
    Posts: 9
    Registered: ‎08-13-2012

    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

    Please use plain text.
    *Expert Elite*
    Posts: 6,474
    Registered: ‎06-29-2007

    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
    -------------------------------------------------------------------------
    Please use plain text.
    Active Member
    Posts: 9
    Registered: ‎08-13-2012

    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

    Please use plain text.
    *Expert Elite*
    Posts: 6,474
    Registered: ‎06-29-2007

    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
    -------------------------------------------------------------------------
    Please use plain text.