明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2670|回复: 9

[求助]offset偏移后的对象得到

[复制链接]
发表于 2006-5-29 21:15:00 | 显示全部楼层 |阅读模式

我用offset偏移多段线

offsetline = tmplwline.Offset(distance)然后

offsetpnt = offsetline.Coordinates

为什么系统识别offsetpnt,即得不到偏移后多段线得点?

 楼主| 发表于 2006-5-29 21:22:00 | 显示全部楼层
sorry,是不识别offsetpnt
发表于 2006-5-29 21:22:00 | 显示全部楼层

coordinates是一个数组,里面有好多数

你可以用coordinate(0)表示第一个顶点的x坐标,coordinate(1)表示第一个的y坐标,后面依次

 楼主| 发表于 2006-5-30 08:40:00 | 显示全部楼层

offsetline = tmplwline.Offset(distance)的意思是否是tmplwline偏移后的线是offsetline?

发表于 2006-5-30 09:29:00 | 显示全部楼层

是,但offsetline是一個數組

 楼主| 发表于 2006-5-30 20:45:00 | 显示全部楼层

谢谢yuangw1234,但我运行还有点错误,帮我看看

Sub Ch4_OffsetPolyline()
    ' 创建多段线
    Dim plineObj As AcadLWPolyline
    Dim points(0 To 11) As Double
    points(0) = 1: points(1) = 1
    points(2) = 1: points(3) = 2
    points(4) = 2: points(5) = 2
    points(6) = 3: points(7) = 2
    points(8) = 4: points(9) = 4
    points(10) = 4: points(11) = 1
    Set plineObj = ThisDrawing.ModelSpace. _
                   AddLightWeightPolyline(points)
    plineObj.Closed = True
    ZoomAll
               
    ' 偏移多段线
    Dim offsetobj As Variant
    offsetobj = plineObj.Offset(0.25)
Dim line As AcadLine
Dim pnt1(2) As Double
Dim pnt2(2) As Double
'这里出问题了
pnt1(0) = offsetobj(0)
pnt1(1) = offsetobj(0)
pnt1(2) = 0
pnt2(0) = 10
pnt2(1) = 10
pnt2(2) = 0
Set line = ThisDrawing.ModelSpace.AddLine(pnt1, pnt2)
line.color = acBlue
ZoomAll
End Sub

发表于 2006-5-31 17:01:00 | 显示全部楼层

pnt1(0) = offsetobj(0)

前面是个DOUBLE,后面是个对象,这样赋值当然不行,提取offsetobj中的coordinates属性里的坐标吧!

 楼主| 发表于 2006-6-2 19:51:00 | 显示全部楼层

Sub Ch4_OffsetPolyline()
    ' 创建多段线
    Dim plineObj As AcadLWPolyline
    Dim points(0 To 11) As Double
    points(0) = 1: points(1) = 1
    points(2) = 1: points(3) = 2
    points(4) = 2: points(5) = 2
    points(6) = 3: points(7) = 2
    points(8) = 4: points(9) = 4
    points(10) = 4: points(11) = 1
    Set plineObj = ThisDrawing.ModelSpace. _
                   AddLightWeightPolyline(points)
    plineObj.Closed = True
   
    ZoomAll
               
    ' 偏移多段线
    Dim offsetobj As AcadLWPolyline
    offsetobj = plineObj.Offset(0.25)
   

Dim line As AcadLine
Dim pnt1(2) As Double
Dim pnt2(2) As Double
'这里出问题了
pnt1(0) = offsetobj.Coordinates(0)
pnt1(1) = offsetobj.Coordinates(1)
pnt1(2) = 0
pnt2(0) = 10
pnt2(1) = 5
pnt2(2) = 0
Set line = ThisDrawing.ModelSpace.AddLine(pnt1, pnt2)
line.color = acBlue
ZoomAll
End Sub

 

这样还不行呀,帮帮忙呀,谢谢

发表于 2006-6-3 08:39:00 | 显示全部楼层

你的程序的问题出在了下面两处:

1,Dim offsetobj As AcadLWPolyline
    offsetobj = plineObj.Offset(0.25)

    对象Offset后返回的是一个对象数组,而你的offsetobj只定义成一种对象类型,那么在运行时回报错。所以改成

 Dim offsetobj As Variant
    offsetobj = plineObj.Offset(0.25)

2,下面的这一段

Dim line As AcadLine
Dim pnt1(2) As Double
Dim pnt2(2) As Double

pnt1(0) = offsetobj.Coordinates(0)
pnt1(1) = offsetobj.Coordinates(1)
pnt1(2) = 0

Coordinates属性不支持Coordinates(0)这种获取数值的方法,需要一个中间变量来过渡一下。所以改成如下

Dim line As AcadLine
Dim pnt1 As Variant
Dim pnt2(2) As Double

pnt1 = offsetobj(0).Coordinates
ReDim Preserve pnt1(2)
pnt1(2) = 0

ReDim Preserve pnt1(2)是为了去除你不想要的一些数值

最后,我运行完发现程序最后生成的线的位置不太对头,你再仔细调试一下。反正有思路就不难了!

 

 

 楼主| 发表于 2006-6-3 12:52:00 | 显示全部楼层

谢谢楼主,我已经明白了,这样改就好了。我是想得到偏移后线得没个点,现在得到了。

 

 

 

Sub Ch4_OffsetPolyline()
    ' 创建多段线
    Dim plineObj As AcadLWPolyline
    Dim points(0 To 11) As Double
    points(0) = 1: points(1) = 1
    points(2) = 1: points(3) = 2
    points(4) = 2: points(5) = 2
    points(6) = 3: points(7) = 2
    points(8) = 4: points(9) = 4
    points(10) = 4: points(11) = 1
    Set plineObj = ThisDrawing.ModelSpace. _
                   AddLightWeightPolyline(points)
    plineObj.Closed = True
   
    ZoomAll
               
    ' 偏移多段线
    Dim offsetobj As Variant
         Dim lineline As AcadLWPolyline
     offsetobj = plineObj.Offset(0.25)
      Set lineline = offsetobj(0)


    Dim pn1(2) As Double
    Dim pn2(2) As Double
   Dim line As AcadLine
  
   
   pn1(0) = lineline.Coordinates(0)
   pn1(1) = lineline.Coordinates(1)
   pn1(2) = 0
   pn2(0) = 20
   pn2(1) = 10
   pn2(2) = 0
   Set line = ThisDrawing.ModelSpace.AddLine(pn1, pn2)
   line.color = acRed

ZoomAll
End Sub

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

本版积分规则

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

GMT+8, 2024-11-27 02:35 , Processed in 0.168270 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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