Keith™ 发表于 2007-5-4 16:33:38

创建区域

让我感到困惑的是,如果帮助文件说一个区域是从LWPolyline创建的,为什么这不起作用?
Public Sub wall()
      Dim dblLength As Double, dblWidth As Double, dblHeight As Double
      Dim inspt(2) As Double, endpt(2) As Double
      inspt(0) = 120: inspt(1) = 120: inspt(2) = 0
      Dim oLayer As AcadLayer, oCurrLayeR As AcadLayer, oBlock As AcadBlockReference, _
          oEntity As AcadEntity, newObjs As Variant      ', InsPT As Variant
      Set oCurrLayeR = ThisDrawing.ActiveLayer
      Set oLayer = ThisDrawing.Layers.Add("SITE-WALL")
      oLayer.color = 1
      ThisDrawing.ActiveLayer = oLayer
'      dblLength = CDbl(txtLength.Value)
'      dblWidth = CDbl(txtWidth.Value)
'      dblHeight = CDbl(txtHeight.Value)
      dblLength = 144
      dblWidth = 72
      dblHeight = 60
Dim WallCoords(9) As Double
WallCoords(0) = inspt(0) - (dblLength / 2): WallCoords(1) = inspt(1) + (dblWidth / 2)
WallCoords(2) = inspt(0) + (dblLength / 2): WallCoords(3) = inspt(1) + (dblWidth / 2)
WallCoords(4) = inspt(0) + (dblLength / 2): WallCoords(5) = inspt(1) - (dblWidth / 2)
WallCoords(6) = inspt(0) - (dblLength / 2): WallCoords(7) = inspt(1) - (dblWidth / 2)
WallCoords(8) = inspt(0) - (dblLength / 2): WallCoords(9) = inspt(1) + (dblWidth / 2)
Dim plineObj As AcadLWPolyline
Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(WallCoords)
plineObj.Closed = True
Dim regionObj As Variant
Set regionObj = ThisDrawing.ModelSpace.AddRegion(plineObj)
    ZoomAll
      ThisDrawing.ActiveLayer = oCurrLayeR
End Sub
**** Hidden Message *****

Fatty 发表于 2007-5-4 16:54:08

您传递的项目必须是对象数组...
Public Sub wall()
      Dim dblLength As Double, dblWidth As Double, dblHeight As Double
      Dim inspt(2) As Double, endpt(2) As Double
      inspt(0) = 120: inspt(1) = 120: inspt(2) = 0
      Dim oLayer As AcadLayer, oCurrLayeR As AcadLayer, oBlock As AcadBlockReference, _
          oEntity As AcadEntity, newObjs As Variant      ', InsPT As Variant
      Set oCurrLayeR = ThisDrawing.ActiveLayer
      Set oLayer = ThisDrawing.layers.Add("SITE-WALL")
      oLayer.Color = 1
      ThisDrawing.ActiveLayer = oLayer
'      dblLength = CDbl(txtLength.Value)
'      dblWidth = CDbl(txtWidth.Value)
'      dblHeight = CDbl(txtHeight.Value)
      dblLength = 144
      dblWidth = 72
      dblHeight = 60
Dim WallCoords(9) As Double
WallCoords(0) = inspt(0) - (dblLength / 2): WallCoords(1) = inspt(1) + (dblWidth / 2)
WallCoords(2) = inspt(0) + (dblLength / 2): WallCoords(3) = inspt(1) + (dblWidth / 2)
WallCoords(4) = inspt(0) + (dblLength / 2): WallCoords(5) = inspt(1) - (dblWidth / 2)
WallCoords(6) = inspt(0) - (dblLength / 2): WallCoords(7) = inspt(1) - (dblWidth / 2)
WallCoords(8) = inspt(0) - (dblLength / 2): WallCoords(9) = inspt(1) + (dblWidth / 2)
Dim objArray(0) As AcadEntity
Set objArray(0) = ThisDrawing.ModelSpace.AddLightWeightPolyline(WallCoords)
    objArray(0).Closed = True
ThisDrawing.ModelSpace.AddRegion objArray
ZoomAll
ThisDrawing.ActiveLayer = oCurrLayeR
End Sub

Keith™ 发表于 2007-5-4 16:55:27

反正我又迟到了
Public Sub wall()
      Dim dblLength As Double, dblWidth As Double, dblHeight As Double
      Dim inspt(2) As Double, endpt(2) As Double
      inspt(0) = 120: inspt(1) = 120: inspt(2) = 0
      Dim oLayer As AcadLayer, oCurrLayeR As AcadLayer, oBlock As AcadBlockReference, _
          oEntity As AcadEntity, newObjs As Variant      ', InsPT As Variant
      Set oCurrLayeR = ThisDrawing.ActiveLayer
      Set oLayer = ThisDrawing.Layers.Add("SITE-WALL")
      oLayer.color = 1
      ThisDrawing.ActiveLayer = oLayer
'      dblLength = CDbl(txtLength.Value)
'      dblWidth = CDbl(txtWidth.Value)
'      dblHeight = CDbl(txtHeight.Value)
      dblLength = 144
      dblWidth = 72
      dblHeight = 60
Dim WallCoords(9) As Double
WallCoords(0) = inspt(0) - (dblLength / 2): WallCoords(1) = inspt(1) + (dblWidth / 2)
WallCoords(2) = inspt(0) + (dblLength / 2): WallCoords(3) = inspt(1) + (dblWidth / 2)
WallCoords(4) = inspt(0) + (dblLength / 2): WallCoords(5) = inspt(1) - (dblWidth / 2)
WallCoords(6) = inspt(0) - (dblLength / 2): WallCoords(7) = inspt(1) - (dblWidth / 2)
WallCoords(8) = inspt(0) - (dblLength / 2): WallCoords(9) = inspt(1) + (dblWidth / 2)
Dim plineObj As AcadLWPolyline
Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(WallCoords)
plineObj.Closed = True
Dim bound(0) As AcadEntity
Set bound(0) = plineObj
Dim regionObj As Variant
regionObj = ThisDrawing.ModelSpace.AddRegion(bound)
plineObj.Delete
    ZoomAll
      ThisDrawing.ActiveLayer = oCurrLayeR
End Sub

Atook 发表于 2007-5-4 17:25:34

让我看看我是否理解,我们正在使用通用的AcadEntity,创建一个LWP作为所述实体,并将其传递给region命令?

Matersammichman 发表于 2007-5-4 17:38:58

基本上。。除了 AddRegion 方法的参数必须是实体数组...

Dim NumberOfEntities, X As Integer
NumberOfEntities = 10
Dim EntityArray(0 to NumberOfEntities) As AcadEntity
For X = 0 to NumberOfEntities
Set EntityArray(X) = MakePline() <--- dummy function returning a LWpolyline
Next X
ThisDrawing.ModelSpace.AddRegion(EntityArray)

Fatty 发表于 2007-5-4 17:41:22

不,您创建LWP,并将其放入数组中。将数组传递给.addregion命令。如果只传递一个对象,这有点傻,但是如果使用3个对象来定义区域,这是有意义的
总结起来:
LWP=addlwpoly(blah)
dim arregionbound(0)作为变体
arregionBound(零)=LWP
regionObj=ThisDrawing.ModelSpace。AddRegion(arrRegionBound)
编辑:正如quickfingersKeith所说。

Fatty 发表于 2007-5-8 08:19:16

沿着同样的路线...
你怎么能找到一个区域的中心?

Keith™ 发表于 2007-5-8 09:27:13

也许这会有帮助?
页: [1]
查看完整版本: 创建区域