明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1072|回复: 0

刚找了一段VBA程序不能编译,大侠给修改一下吧

[复制链接]
发表于 2008-6-14 11:16:00 | 显示全部楼层 |阅读模式
本帖最后由 作者 于 2008-6-14 11:20:07 编辑

本人新手,刚在本版找了一段VBA程序编译不了,请大侠帮忙解决!谢谢

本段程序是关于求解多个不规则封闭图形的总面积、总周长、个数的

Public Sub GetTolArea()
     ThisDrawing.SendCommand "(vl-load-com)" & vbCr
     Dim CurveObj As cruve
     Set CurveObj = New cruve
     Dim VlaxObj As VLAX
     Set VlaxObj = New VLAX
     Dim OutEnt As AcadEntity
     Dim Pnt As Variant
     ThisDrawing.Utility.GetEntity OutEnt, Pnt, "选择外框:"
     Dim MinBox As Variant
     Dim MaxBox As Variant
     Dim OutArea As Double
     Dim OutLeng As Double
     OutEnt.GetBoundingBox MinBox, MaxBox
     If OutEnt.ObjectName = "AcDbRegion" Then
         OutArea = OutEnt.Area
         OutLeng = OutEnt.Perimeter
     Else
         Set CurveObj.Entity = OutEnt
         OutArea = CurveObj.Area
         OutLeng = CurveObj.Length
     End If
     'Set CurveObj.Entity = OutEnt
     Dim ss As AcadSelectionSet
     Set ss = CreatSSet
     Dim FType(0)  As Integer
     Dim FData(0)  As Variant
     FType(0) = 0
     FData(0) = "SPLINE"
     ss.Select acSelectionSetWindow, MinBox, MaxBox, FType, FData
     'Debug.Print ss.Count
     Dim i As Integer
     Dim InArea()  As Double
     Dim InLeng()  As Double
     Dim j As Integer
     Dim Ent As AcadEntity
     ReDim Preserve InArea(0) As Double
     ReDim Preserve InLeng(0) As Double
     For i = 0 To ss.Count - 1
         If ss.Item(i).ObjectID > OutEnt.ObjectID Then
             Set Ent = ss(i)
             Set CurveObj.Entity = Ent
             VlaxObj.EvalLispExpression "(gc)"
             If i > 0 Then
                 j = UBound(InArea) + 1
                 ReDim Preserve InArea(j) As Double
                 ReDim Preserve InLeng(j) As Double
                 InArea(j) = CurveObj.Area
                 InLeng(j) = CurveObj.Length
             Else
                 InArea(0) = CurveObj.Area
                 InLeng(0) = CurveObj.Length
             End If
         End If
     Next
     Dim TolArea As Double
     Dim TolLeng As Double
     Dim AreaPer As Double
     Dim dispMsg As String
     dispMsg = "外框的面积为:" & OutArea & ",周长为:" & OutLeng & vbCrLf & vbCrLf
     dispMsg = dispMsg & "内部曲线的面积及周长如下:" & vbCrLf
     For i = 0 To UBound(InArea)
         dispMsg = dispMsg & "曲线" & i & "面积:" & InArea(i) & ",周长:" & InLeng(i) & vbCrLf
        
         TolArea = TolArea + InArea(i)
         TolLeng = TolLeng + InLeng(i)
     Next
     dispMsg = dispMsg & vbCrLf
     dispMsg = dispMsg & "总面积为:" & TolArea & " 总周长为:" & TolLeng & vbCrLf & vbCrLf
     AreaPer = TolArea / OutArea * 100
     dispMsg = dispMsg & "内部曲线面积总各占外框面积的百分比:" & AreaPer & "%"
     'MsgBox dispMsg
     ThisDrawing.Utility.Prompt dispMsg
End Sub
Function CreatSSet()
     Dim ss As AcadSelectionSet
     On Error Resume Next
     Set ss = ThisDrawing.SelectionSets.Add("mccad")
     If Err Then
         Err.Clear
         Set ss = ThisDrawing.SelectionSets("mccad")
         ss.Clear
     End If
     Set CreatSSet = ss
End Function


您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-26 09:56 , Processed in 0.150858 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表