VBA: Rotate Selection Set

VBA: Rotate Selection Set

dialunau
Advocate Advocate
1,519 Views
2 Replies
Message 1 of 3

VBA: Rotate Selection Set

dialunau
Advocate
Advocate

Hello everyone, I'm trying to rotate a selection set, every section of the code seems to be sorking ok, but at the very end, when I try to rotate all of the drawing, it gives the following error:
"Compile error, Expected Function or variable"

Ay ideas how can I make my code work?
My code looks like this:

 

 

 

Sub Rotation()
Dim pointObj As AcadPoint
Dim location(0 To 2) As Double
location(0) = 0#: location(1) = 0#: location(2) = 0#
Set pointObj = ThisDrawing.ModelSpace.AddPoint(location)

Dim oObj(500) As AcadEntity
Dim oSelSet As AcadSelectionSet
Dim i As Integer
i = 0
Dim Angle As Double
Angle = 90

Dim tSelSet As AcadSelectionSet
On Error Resume Next
Set tSelSet = ThisDrawing.SelectionSets.Add("XX")
If tSelSet Is Nothing Then
Set tSelSet = ThisDrawing.SelectionSets.Item("XX")
tSelSet.Clear
End If

For i = 1 To 500
Set oObj(i) = ThisDrawing.ModelSpace.Item(i)
Next

oSelSet.AddItems (oObj)

For i = 1 To oSelSet.Count
Set oObj(i) = oSelSet.Item(i).Rotate(pointObj, Angle)
Next i
End Sub

 

0 Likes
Accepted solutions (2)
1,520 Views
2 Replies
Replies (2)
Message 2 of 3

norman.yuan
Mentor
Mentor
Accepted solution

I think you are confusing AcadPoint entity with a 3-dimension geometric data for a position/location, which we usually call it "point" to refer a location. 

 

When you call AcadEntity.Rotate() method, the first parameter you passed in is the geometric point, NOT A AcadPoint. That is why you got compiling error: you passed wrong data type.

 

So, in your case, you do not need to add a AcadPoint entity into the ModelSpace.  For the rotation to work, you do

 

For i = 1 To oSelSet.Count
  Set oObj(i) = oSelSet.Item(i).Rotate(location, Angle)
Next i

 

HTH

 

 

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 3

dialunau
Advocate
Advocate
Accepted solution

I corrected the point and location issue, now my code works just fine.
Thank you

0 Likes