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
show that code-parts you have, that makes it easier for helpers to know where to start.
- alfred -
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
.InitializeUserInput 1, "Window Crossing Previous Last All"
str0pt = .GetKeyword(vbCr & _
"Select [Window/Crossing/Previous/Last/All]: ")
Select Case str0pt
Case "Crossing": lngMode = acSelectionSetCrossing
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
>> 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 -
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
>> 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
HTH, -alfred -
fantastic. Wish I had asked this question yesterday. You saved me many many hours of harship. Thanks so much
You are very welcome! - alfred -