明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 645|回复: 3

无法修改多段线的坐标???

[复制链接]
发表于 2019-2-18 21:32 | 显示全部楼层 |阅读模式


问题描述:写了个类模块OceDoor,图中选择一个矩形多段线后,发现修改多段线坐标后没有反应......


1)以下是 ThisDrawing 里面的代码:
==========================================================================================
Public Sub BBB_GoTestHere()    这个是运行的主过程

Dim SeleObjts As AcadSelectionSet
Dim Objt As Object
Dim Door As New OceDoor

Call CreateSelectionSet(SeleObjts, "Doors"):   SeleObjts.SelectOnScreen

For Each Objt In SeleObjts
  If TypeOf Objt Is AcadLWPolyline Then Set Door.OutLine = Objt
Next Objt

Set SeleObjts = Nothing

Let Door.Width = 5000    这设置宽度,原来宽度是 1200,运行后矩形没变大

End Sub

==========================================================================================
Sub CreateSelectionSet(SeleObjts As AcadSelectionSet, Name As String)

On Error Resume Next

If Not IsNull(ThisDrawing.SelectionSets.Item(Name)) Then
  Set SeleObjts = ThisDrawing.SelectionSets.Item(Name)
  SeleObjts.Delete
End If

Set SeleObjts = ThisDrawing.SelectionSets.Add(Name)

End Sub
==========================================================================================


2)以下是 OceDoor 里面的代码:

Dim Rect As AcadLWPolyline
Dim b0 As Double:  Dim Xc As Double

==========================================================================================
Public Property Set OutLine(ByVal NewValue As AcadLWPolyline)
    Set Rect = NewValue:  Call DataUpdate
End Property
==========================================================================================
Public Property Get OutLine() As AcadLWPolyline
    Set OutLine = Rect
End Property
==========================================================================================
Private Sub DataUpdate()   数据更新
    b0 = Abs(Rect.Coordinate(1)(0) - Rect.Coordinate(3)(0))
    h0 = Abs(Rect.Coordinate(1)(1) - Rect.Coordinate(3)(1))
    Xc = 0.5 * (Rect.Coordinate(1)(0) + Rect.Coordinate(3)(0))
    Yc = 0.5 * (Rect.Coordinate(1)(1) + Rect.Coordinate(3)(1))  
    Rect.Update
End Sub
==========================================================================================
Public Property Get Width() As Double    宽度属性取值
    Width = b0
End Property
==========================================================================================
Public Property Let Width(ByVal NewValue As Double)     宽度属性赋值
    Dim Xmax As Double:  Xmax = Xc + 0.5 * NewValue
    Dim Xmin As Double:  Xmin = Xc - 0.5 * NewValue

    Rect.Coordinate(0)(0) = Xmin:    Rect.Coordinate(2)(0) = Xmax
    Rect.Coordinate(1)(0) = Xmax:   Rect.Coordinate(3)(0) = Xmin

    Call DataUpdate
End Property


 楼主| 发表于 2019-2-19 14:03 | 显示全部楼层
简化下代码,这样也无法修改坐标:

Option Explicit

Public Sub BBB_GoTestHere()

Dim SeleObjts As AcadSelectionSet
Dim Objt As Object

Dim Rect As AcadPolyline

Call CreateSelectionSet(SeleObjts, "Polys")

SeleObjts.SelectOnScreen

For Each Objt In SeleObjts
  If TypeOf Objt Is AcadPolyline Then Set Rect = Objt
Next Objt

Set SeleObjts = Nothing

Rect.Coordinates(0) = 5000  '就是这里,根本改不了坐标

End Sub

Sub CreateSelectionSet(SeleObjts As AcadSelectionSet, Name As String)

On Error Resume Next

If Not IsNull(ThisDrawing.SelectionSets.Item(Name)) Then
Set SeleObjts = ThisDrawing.SelectionSets.Item(Name)
SeleObjts.Delete
End If

Set SeleObjts = ThisDrawing.SelectionSets.Add(Name)

End Sub
发表于 2019-2-21 14:02 | 显示全部楼层
本帖最后由 woaishuijia 于 2019-2-21 14:14 编辑
  1. Public Property Let Width(ByVal NewValue As Double)   
  2.     Dim Xmax As Double:  Xmax = Xc + 0.5 * NewValue
  3.     Dim Xmin As Double:  Xmin = Xc - 0.5 * NewValue
  4.    
  5.     Dim V(7) As Double
  6.     V(0) = Xmin
  7.     V(1) = Rect.Coordinates(1)
  8.     V(2) = Xmax
  9.     V(3) = Rect.Coordinates(3)
  10.     V(4) = Xmax
  11.     V(5) = Rect.Coordinates(5)
  12.     V(6) = Xmin
  13.     V(7) = Rect.Coordinates(7)
  14.     Rect.Coordinates = V

  15.     Call DataUpdate
  16. End Property


  1. Public Property Let Width(ByVal NewValue As Double)
  2.     Dim Xmax As Double:  Xmax = Xc + 0.5 * NewValue
  3.     Dim Xmin As Double:  Xmin = Xc - 0.5 * NewValue
  4.    
  5.     Dim V(1) As Double
  6.     V(0) = Xmin
  7.     V(1) = Rect.Coordinates(1)
  8.     Rect.Coordinate(0) = V
  9.     V(1) = Rect.Coordinates(7)
  10.     Rect.Coordinate(3) = V
  11.     V(0) = Xmax
  12.     V(1) = Rect.Coordinates(3)
  13.     Rect.Coordinate(1) = V
  14.     V(1) = Rect.Coordinates(5)
  15.     Rect.Coordinate(2) = V

  16.     Call DataUpdate
  17. End Property



评分

参与人数 1金钱 +20 收起 理由
Oceanable + 20 很给力!

查看全部评分

 楼主| 发表于 2019-2-21 20:30 | 显示全部楼层
就是不能单个坐标这样修改,,,

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

本版积分规则

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

GMT+8, 2024-4-20 06:14 , Processed in 0.174169 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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