碧海听潮 发表于 2006-5-29 21:15:00

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

我用offset偏移多段线
offsetline = tmplwline.Offset(distance)然后
offsetpnt = offsetline.Coordinates
为什么系统识别offsetpnt,即得不到偏移后多段线得点?

碧海听潮 发表于 2006-5-29 21:22:00

sorry,是不识别offsetpnt

yuangw1234 发表于 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?

yuangw1234 发表于 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

xinghesnak 发表于 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


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

xinghesnak 发表于 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
页: [1]
查看完整版本: [求助]offset偏移后的对象得到