乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 176|回复: 9

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

[复制链接]

4

主题

9

帖子

1

银币

初来乍到

Rank: 1

铜币
25
发表于 2006-5-29 21:15:00 | 显示全部楼层 |阅读模式
我用offset偏移多段线
offsetline = tmplwline.Offset(distance)然后
offsetpnt = offsetline.Coordinates
为什么系统识别offsetpnt,即得不到偏移后多段线得点?
回复

使用道具 举报

4

主题

9

帖子

1

银币

初来乍到

Rank: 1

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

使用道具 举报

68

主题

177

帖子

4

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
449
发表于 2006-5-29 21:22:00 | 显示全部楼层
coordinates是一个数组,里面有好多数
你可以用coordinate(0)表示第一个顶点的x坐标,coordinate(1)表示第一个的y坐标,后面依次
回复

使用道具 举报

4

主题

9

帖子

1

银币

初来乍到

Rank: 1

铜币
25
发表于 2006-5-30 08:40:00 | 显示全部楼层
offsetline = tmplwline.Offset(distance)的意思是否是tmplwline偏移后的线是offsetline?
回复

使用道具 举报

68

主题

177

帖子

4

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
449
发表于 2006-5-30 09:29:00 | 显示全部楼层
是,但offsetline是一個數組
回复

使用道具 举报

4

主题

9

帖子

1

银币

初来乍到

Rank: 1

铜币
25
发表于 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
回复

使用道具 举报

1

主题

157

帖子

2

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
161
发表于 2006-5-31 17:01:00 | 显示全部楼层
pnt1(0) = offsetobj(0)
前面是个DOUBLE,后面是个对象,这样赋值当然不行,提取offsetobj中的coordinates属性里的坐标吧!
回复

使用道具 举报

4

主题

9

帖子

1

银币

初来乍到

Rank: 1

铜币
25
发表于 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


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

使用道具 举报

1

主题

157

帖子

2

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
161
发表于 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)是为了去除你不想要的一些数值
最后,我运行完发现程序最后生成的线的位置不太对头,你再仔细调试一下。反正有思路就不难了!



回复

使用道具 举报

4

主题

9

帖子

1

银币

初来乍到

Rank: 1

铜币
25
发表于 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
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-7-5 19:56 , Processed in 0.571745 second(s), 72 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表