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

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

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

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

sorry,是不识别offsetpnt

yuangw1234 发表于 2006-5-29 21:22:00

<P>coordinates是一个数组,里面有好多数</P>
<P>你可以用coordinate(0)表示第一个顶点的x坐标,coordinate(1)表示第一个的y坐标,后面依次</P>

碧海听潮 发表于 2006-5-30 08:40:00

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

yuangw1234 发表于 2006-5-30 09:29:00

<P>是,但offsetline是一個數組</P>

碧海听潮 发表于 2006-5-30 20:45:00

<P>谢谢yuangw1234,但我运行还有点错误,帮我看看</P>
<P>Sub Ch4_OffsetPolyline()<BR>&nbsp;&nbsp;&nbsp; ' 创建多段线<BR>&nbsp;&nbsp;&nbsp; Dim plineObj As AcadLWPolyline<BR>&nbsp;&nbsp;&nbsp; Dim points(0 To 11) As Double<BR>&nbsp;&nbsp;&nbsp; points(0) = 1: points(1) = 1<BR>&nbsp;&nbsp;&nbsp; points(2) = 1: points(3) = 2<BR>&nbsp;&nbsp;&nbsp; points(4) = 2: points(5) = 2<BR>&nbsp;&nbsp;&nbsp; points(6) = 3: points(7) = 2<BR>&nbsp;&nbsp;&nbsp; points(8) = 4: points(9) = 4<BR>&nbsp;&nbsp;&nbsp; points(10) = 4: points(11) = 1<BR>&nbsp;&nbsp;&nbsp; Set plineObj = ThisDrawing.ModelSpace. _<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AddLightWeightPolyline(points)<BR>&nbsp;&nbsp;&nbsp; plineObj.Closed = True<BR>&nbsp;&nbsp;&nbsp; ZoomAll<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; ' 偏移多段线<BR>&nbsp;&nbsp;&nbsp; Dim offsetobj As Variant<BR>&nbsp;&nbsp;&nbsp; offsetobj = plineObj.Offset(0.25)<BR>Dim line As AcadLine<BR>Dim pnt1(2) As Double<BR>Dim pnt2(2) As Double<BR>'这里出问题了<BR>pnt1(0) = offsetobj(0)<BR>pnt1(1) = offsetobj(0)<BR>pnt1(2) = 0<BR>pnt2(0) = 10<BR>pnt2(1) = 10<BR>pnt2(2) = 0<BR>Set line = ThisDrawing.ModelSpace.AddLine(pnt1, pnt2)<BR>line.color = acBlue<BR>ZoomAll<BR>End Sub</P>

xinghesnak 发表于 2006-5-31 17:01:00

<P>pnt1(0) = offsetobj(0)</P>
<P>前面是个DOUBLE,后面是个对象,这样赋值当然不行,提取offsetobj中的coordinates属性里的坐标吧!</P>

碧海听潮 发表于 2006-6-2 19:51:00

<P>Sub Ch4_OffsetPolyline()<BR>&nbsp;&nbsp;&nbsp; ' 创建多段线<BR>&nbsp;&nbsp;&nbsp; Dim plineObj As AcadLWPolyline<BR>&nbsp;&nbsp;&nbsp; Dim points(0 To 11) As Double<BR>&nbsp;&nbsp;&nbsp; points(0) = 1: points(1) = 1<BR>&nbsp;&nbsp;&nbsp; points(2) = 1: points(3) = 2<BR>&nbsp;&nbsp;&nbsp; points(4) = 2: points(5) = 2<BR>&nbsp;&nbsp;&nbsp; points(6) = 3: points(7) = 2<BR>&nbsp;&nbsp;&nbsp; points(8) = 4: points(9) = 4<BR>&nbsp;&nbsp;&nbsp; points(10) = 4: points(11) = 1<BR>&nbsp;&nbsp;&nbsp; Set plineObj = ThisDrawing.ModelSpace. _<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AddLightWeightPolyline(points)<BR>&nbsp;&nbsp;&nbsp; plineObj.Closed = True<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; ZoomAll<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; ' 偏移多段线<BR>&nbsp;&nbsp;&nbsp; Dim offsetobj As AcadLWPolyline<BR>&nbsp;&nbsp;&nbsp; offsetobj = plineObj.Offset(0.25)<BR>&nbsp;&nbsp;&nbsp; </P>
<P>Dim line As AcadLine<BR>Dim pnt1(2) As Double<BR>Dim pnt2(2) As Double<BR>'这里出问题了<BR>pnt1(0) = offsetobj.Coordinates(0)<BR>pnt1(1) = offsetobj.Coordinates(1)<BR>pnt1(2) = 0<BR>pnt2(0) = 10<BR>pnt2(1) = 5<BR>pnt2(2) = 0<BR>Set line = ThisDrawing.ModelSpace.AddLine(pnt1, pnt2)<BR>line.color = acBlue<BR>ZoomAll<BR>End Sub<BR></P>
<P>&nbsp;</P>
<P>这样还不行呀,帮帮忙呀,谢谢</P>

xinghesnak 发表于 2006-6-3 08:39:00

<P>你的程序的问题出在了下面两处:</P>
<P>1,Dim offsetobj As AcadLWPolyline<BR>&nbsp;&nbsp;&nbsp; offsetobj = plineObj.Offset(0.25)</P>
<P>&nbsp;&nbsp;&nbsp; 对象Offset后返回的是一个对象数组,而你的offsetobj只定义成一种对象类型,那么在运行时回报错。所以改成</P>
<P>&nbsp;Dim offsetobj As Variant<BR>&nbsp;&nbsp;&nbsp; offsetobj = plineObj.Offset(0.25)</P>
<P>2,下面的这一段</P>
<P>Dim line As AcadLine<BR>Dim pnt1(2) As Double<BR>Dim pnt2(2) As Double<BR><BR>pnt1(0) = offsetobj.Coordinates(0)<BR>pnt1(1) = offsetobj.Coordinates(1)<BR>pnt1(2) = 0</P>
<P>Coordinates属性不支持Coordinates(0)这种获取数值的方法,需要一个中间变量来过渡一下。所以改成如下</P>
<P>Dim line As AcadLine<BR>Dim pnt1 As Variant<BR>Dim pnt2(2) As Double</P>
<P>pnt1 = offsetobj(0).Coordinates<BR>ReDim Preserve pnt1(2)<BR>pnt1(2) = 0</P>
<P>ReDim Preserve pnt1(2)是为了去除你不想要的一些数值</P>
<P>最后,我运行完发现程序最后生成的线的位置不太对头,你再仔细调试一下。反正有思路就不难了!<BR></P>
<P>&nbsp;</P>
<P>&nbsp;</P>

碧海听潮 发表于 2006-6-3 12:52:00

<P>谢谢楼主,我已经明白了,这样改就好了。我是想得到偏移后线得没个点,现在得到了。</P>
<P>&nbsp;</P>
<P>&nbsp;</P>
<P>&nbsp;</P>
<P>Sub Ch4_OffsetPolyline()<BR>&nbsp;&nbsp;&nbsp; ' 创建多段线<BR>&nbsp;&nbsp;&nbsp; Dim plineObj As AcadLWPolyline<BR>&nbsp;&nbsp;&nbsp; Dim points(0 To 11) As Double<BR>&nbsp;&nbsp;&nbsp; points(0) = 1: points(1) = 1<BR>&nbsp;&nbsp;&nbsp; points(2) = 1: points(3) = 2<BR>&nbsp;&nbsp;&nbsp; points(4) = 2: points(5) = 2<BR>&nbsp;&nbsp;&nbsp; points(6) = 3: points(7) = 2<BR>&nbsp;&nbsp;&nbsp; points(8) = 4: points(9) = 4<BR>&nbsp;&nbsp;&nbsp; points(10) = 4: points(11) = 1<BR>&nbsp;&nbsp;&nbsp; Set plineObj = ThisDrawing.ModelSpace. _<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AddLightWeightPolyline(points)<BR>&nbsp;&nbsp;&nbsp; plineObj.Closed = True<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; ZoomAll<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; ' 偏移多段线<BR>&nbsp;&nbsp;&nbsp; Dim offsetobj As Variant<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim lineline As AcadLWPolyline<BR>&nbsp;&nbsp;&nbsp;&nbsp; offsetobj = plineObj.Offset(0.25)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set lineline = offsetobj(0)</P>
<P><BR>&nbsp;&nbsp;&nbsp; Dim pn1(2) As Double<BR>&nbsp;&nbsp;&nbsp; Dim pn2(2) As Double<BR>&nbsp;&nbsp; Dim line As AcadLine<BR>&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp; pn1(0) = lineline.Coordinates(0)<BR>&nbsp;&nbsp; pn1(1) = lineline.Coordinates(1)<BR>&nbsp;&nbsp; pn1(2) = 0<BR>&nbsp;&nbsp; pn2(0) = 20<BR>&nbsp;&nbsp; pn2(1) = 10<BR>&nbsp;&nbsp; pn2(2) = 0<BR>&nbsp;&nbsp; Set line = ThisDrawing.ModelSpace.AddLine(pn1, pn2)<BR>&nbsp;&nbsp; line.color = acRed</P>
<P>ZoomAll<BR>End Sub</P>
页: [1]
查看完整版本: [求助]offset偏移后的对象得到