明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1614|回复: 3

(求助)有关周长的问题,帮忙看一下代码

[复制链接]
发表于 2006-3-27 16:03:00 | 显示全部楼层 |阅读模式

想求多个面域的累加周长,怎么做?有一段代码是求多个面域的累加面积的,程序正确.我把其中的area必成list ,想求周长,但运行时出错.

求累加面积的正确代码:

 ublic Sub carea()

  On Error GoTo ErrorHandler

  Dim pt As Variant
  Dim spt As String
  Dim i As Integer
  Dim zarea As Double
  zarea = 0

  For i = 0 To 500
   pt = ThisDrawing.Utility.GetPoint(, vbCrLf & "输入要计算面积对象的内部一点:")

   spt = pt(0) & "," & pt(1)

   With ThisDrawing
     SendCommand "-boundary "
     SendCommand spt & " "
     SendCommand " "
     SendCommand "area "
     SendCommand "o "
     SendCommand "last "
     SendCommand "erase "
     SendCommand "last "
     SendCommand " "
   End With

   zarea = zarea + ThisDrawing.GetVariable("AREA")
   ThisDrawing.Utility.Prompt vbCrLf & "选定对象的总面积为: " & zarea & vbCrLf
  Next

ErrorHandler:
  Exit Sub
End Sub

我改后的代码:

Public Sub clist()
  Dim pt As Variant
  Dim spt As String
  Dim i As Integer
  Dim zlist As Double
  zlist = 0

  For i = 0 To ThisDrawing.ModelSpace.Count
   pt = ThisDrawing.Utility.GetPoint(, vbCrLf & "输入要计算周长对象的内部一点:")

   spt = pt(0) & "," & pt(1)

   With ThisDrawing
     SendCommand "-boundary "
     SendCommand spt & " "
     SendCommand " "
     SendCommand "list"
     SendCommand "last "
     SendCommand "erase "
     SendCommand "last "
     SendCommand " "
   End With

   zlist = ThisDrawing.GetVariable("list")
   ThisDrawing.Utility.Prompt vbCrLf & "选定对象的总面积为: " & zlist
  Next

ErrorHandler:
  Exit Sub
End Sub

请大家多多指教,不胜感激.

发表于 2006-3-27 16:42:00 | 显示全部楼层
  1. Public Sub clist()
  2.     Dim pt As Variant
  3.     Dim spt As String
  4.     Dim i As Integer
  5.     pt = ThisDrawing.Utility.getpoint(, vbCrLf & "输入要计算周长对象的内部一点:")
  6.     spt = pt(0) & "," & pt(1)
  7.     ThisDrawing.SendCommand "-boundary" & vbCr & "a" & vbCr & "o" & vbCr & "r" & vbCr & vbCr & spt & vbCr & vbCr
  8.     If (ThisDrawing.GetVariable("LASTPROMPT") <> "已创建 0 个面域。") Then
  9.         MsgBox ThisDrawing.ModelSpace(ThisDrawing.ModelSpace.Count - 1).Perimeter
  10.         ThisDrawing.ModelSpace(ThisDrawing.ModelSpace.Count - 1).Delete
  11.     End If
  12. End Sub
 楼主| 发表于 2006-3-27 22:11:00 | 显示全部楼层

我试过了,所有的内部面域都好用,但为什么最外的那个面域求得的结果不对呢,它的周长应该是最大的呀,可结果却是最小的

 楼主| 发表于 2006-3-27 22:13:00 | 显示全部楼层

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

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

本版积分规则

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

GMT+8, 2024-11-27 06:20 , Processed in 0.171446 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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