圆的中心
这是我在AutoCAD中的第一个VBA。我试着把一张桌子的中心和直径放进去,但我可以#039;t处理点。有人能纠正我的代码吗Option Explicit
Private Sub cercuri_Click()
Dim SS As AcadSelectionSet
Dim coords As AcadTable
Dim i As Integer
Dim st As String
Dim p0 As AcadPoint
Dim Code(0) As Integer
Dim Val(0) As Variant
Dim insp(0 To 2) As Double
insp(0) = 0#
insp(1) = 0#
insp(2) = 0#
Code(0) = 0
Val(0) = "CIRCLE"
Set SS = ThisDrawing.SelectionSets.Add("ss")
UserForm1.hide
SS.SelectOnScreen Code, Val
Set coords = ThisDrawing.ModelSpace.AddTable(insp, SS.Count + 2, 5, 10, 30)
For i = 0 To SS.Count - 1
st = CStr(SS.Item(i).Diameter)
coords.SetText i + 2, 3, st
p0 = SS.Item(i).Center ' WHAT'S WRONG HERE?
Next i
SS.Delete
UserForm1.Show
End Sub
我将沿着这条路走Dim oEnt as Acadentity
Dim oCircle as acadcircle
For Each oEnt in SS
set oCircle =oEnt
st = CStr(oCircle.Diameter)
coords.SetText i + 2, 3, st
p0 = oCircle.Center
Next oEnt
(未测试);J#039~ 谢谢你的回答,菲索
明天早上我会试试——那是在12个小时后。 Fuccaro,
如果您查看帮助,您将看到Center返回一个数组,而不是像p0定义的那样返回一个AcadPoint ;尝试Dim P0作为变体,看看会发生什么。 Fixo代码p0=oCircle。中心不工作
Cathy说得对,Center返回一个数组。Dim p0作为变体并没有解决问题,但我最终找到了正确的代码:Dim p0(0到2)作为Double
谢谢booth的回答 ; 使用这段代码,当用户在屏幕上选择对象时,程序将只考虑圆
Dim Code(0) As Integer
Dim Val(0) As Variant
Code(0) = 0
Val(0) = "CIRCLE"
Set SS = ThisDrawing.SelectionSets.Add("ss")
UserForm1.hide
SS.SelectOnScreen Code, Val 通过扩展代码和Val数组,我还可以添加更多的过滤条件(比如层名称)
但是如何在SS中保留用户选择的圆和椭圆?
可以构建复杂过滤器(与lisp中的方法相同):
Dim ss As AcadSelectionSet
ReDim Code(3) As Integer
ReDim Val(3) As Variant
Code(0) = -4
Val(0) = ""
With ThisDrawing.SelectionSets
While .Count > 0
.Item(0).Delete
Wend
Set ss = .Add("mySet")
End With
UserForm1.hide
ss.SelectOnScreen Code, Val
或者这个:
ReDim Code(6) As Integer
ReDim Val(6) As Variant
Code(0) = -4
Val(0) = ""
Code(5) = 8
Val(5) = "MyLayer"
Code(6) = -4
Val(6) = "AND>"
~&039;J#039~ 哇!好消息,我非常熟悉Lisp选择集。再次感谢菲索
你能告诉我你为什么用ReDim吗?帮助文件不';t建议使用ReDim声明新变量,它仅用于更改现有变量。
很高兴为您提供帮助,我已经从我的一个现有代码中自动复制了这段代码,并将其更改为适合您的代码;J#039~
页:
[1]