明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1080|回复: 4

求不规则多边形面域的程序。

[复制链接]
发表于 2014-10-25 16:32:03 | 显示全部楼层 |阅读模式
Public Function Updateregon()
   Dim p(7) As Double
   Dim lwpolyObj As AcadLWPolyline
   p(0) = 0.8: p(1) = 0
   p(2) = 1.3: p(3) = 1.1
   p(4) = 0.5:   p(5) = 1.1
   p(6) = 0.5: p(7) = 0
   Set lwpolyObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(p)
   lwpolyObj.Closed = True
'余下如下把lwpolyObj生成一个面域?请教

End Function

发表于 2014-10-25 17:32:29 | 显示全部楼层
  1. Public Function Updateregon()
  2.    Dim p(7) As Double
  3.    Dim lwpolyObj As AcadLWPolyline
  4.    p(0) = 0.8: p(1) = 0
  5.    p(2) = 1.3: p(3) = 1.1
  6.    p(4) = 0.5:   p(5) = 1.1
  7.    p(6) = 0.5: p(7) = 0
  8.    Set lwpolyObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(p)
  9.    lwpolyObj.Closed = True
  10.     '余下如下把lwpolyObj生成一个面域?请教
  11.     Dim curves(0) As AcadEntity

  12.     Set curves(0) = lwpolyObj
  13.    
  14.       
  15.     ' 创建面域
  16.     Dim regionObj As Variant
  17.     regionObj = ThisDrawing.ModelSpace.AddRegion(curves)
  18.     ZoomAll

  19. End Function
 楼主| 发表于 2014-10-26 11:08:49 | 显示全部楼层
zzyong00 发表于 2014-10-25 17:32

多谢高手,请继续赐教。
实现这个,我的问题就解决了。下一步把这几个数据搞到窗体中去折腾一下。
Sub bb()
   Dim p(7) As Double
   Dim lwpolyObj As AcadLWPolyline
   p(0) = 0.8: p(1) = 0
   p(2) = 1.3: p(3) = 2.1
   p(4) = 0.5:   p(5) = 2.1
   p(6) = 0#: p(7) = 0.3
   Set lwpolyObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(p)
   lwpolyObj.Closed = True
    Dim curves(0) As AcadEntity
    Set curves(0) = lwpolyObj
    Dim regionObj(0) As Variant
    regionObj(0) = ThisDrawing.ModelSpace.AddRegion(curves)
    '改变其图层及颜色,并求x质心
    Dim reg As AcadRegion
    Set reg = regionObj(0)  '为何转化不成功?或者直接用
    reg.Layer = "MMM"
    reg.color = acRed
    msbox "x质心为:" & reg.Centroid(0)
  End Sub
发表于 2014-10-26 15:15:39 | 显示全部楼层
ThisDrawing.ModelSpace.AddRegion(curves) 返回数组!
Set reg = regionObj(0)(0)'试
 楼主| 发表于 2014-10-26 15:50:33 | 显示全部楼层
谢谢了。大致明白意思了。
个数组,还以为Variant是任一。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-29 02:59 , Processed in 0.148824 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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