- 积分
- 3266
- 明经币
- 个
- 注册时间
- 2002-7-5
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2002-7-16 16:03:00
|
显示全部楼层
找到原因了,先这样解决
本帖最后由 作者 于 2002-7-16 16:03:03 编辑
找到原因了,Thisdrawing.ActiveUCS是活动UCS而不是系统UCS,计算转动惯量时以Thisdrawing.ActiveUCS的原点为中心,第一次运行时,以面域形心(注意:形心坐标非零,即不是系统UCS原点)为惯性中心;第二次运行时,形心坐标计算以Thisdrawing.ActiveUCS为参照,为零,惯性中心为(0,0)即系统UCS原点与面域形心不同。
解决办法:在修改Thisdrawing.ActiveUCS前保存原点,MsgBox后恢复。请参考以下代码。
Private Sub CommandButton1_Click()
UserForm1.Hide
Dim temp(0 To 2) As Double
Dim origin(0 To 2) As Double
Dim Centroid As Variant
Dim currUCS As AcadUCS
Dim momentOfInertia As Variant
Dim sset As AcadSelectionSet 'Define sset as a SelectionSet object
'Set sset to a new selection set named SS1 (the name doesn't matter here)
Set sset = ThisDrawing.SelectionSets.Add("SS1")
sset.SelectOnScreen 'Prompt user to select objects
'save current UCS origin
temp(0) = ThisDrawing.ActiveUCS.origin(0)
temp(1) = ThisDrawing.ActiveUCS.origin(1)
temp(2) = ThisDrawing.ActiveUCS.origin(2)
Dim ent As Object 'Define ent as an object
For Each ent In sset 'Loop through the SelectionSet collection
If ent.EntityName = "AcDbRegion" Then
Centroid = ent.Centroid
' Create a UCS and makes it current
Set currUCS = ThisDrawing.ActiveUCS
origin(0) = Centroid(0): origin(1) = Centroid(1): origin(2) = 0
currUCS.origin = origin
ThisDrawing.ActiveUCS = currUCS
momentOfInertia = ent.momentOfInertia
MsgBox "Ix=" & Format(momentOfInertia(0) / 10000, "######.00") & "mm^4;Iy=" & Format(momentOfInertia(1) / 10000, "######.00") & "mm^4", , "被选择物体的惯性矩"
End If
Next ent
currUCS.origin = temp
ThisDrawing.ActiveUCS = currUCS 'restore ActiveUCS origin
sset.Delete
UserForm1.Show
End Sub |
|