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

VBA: Rotate Selection Set

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
dialunau
1190 Views, 2 Replies

VBA: Rotate Selection Set

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

 

Labels (1)
2 REPLIES 2
Message 2 of 3
norman.yuan
in reply to: dialunau

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

Message 3 of 3
dialunau
in reply to: dialunau

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

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

Post to forums  

Forma Design Contest


Autodesk Design & Make Report