[求助]offset偏移后的对象得到
<P>我用offset偏移多段线</P><P>offsetline = tmplwline.Offset(distance)然后</P>
<P>offsetpnt = offsetline.Coordinates</P>
<P>为什么系统识别offsetpnt,即得不到偏移后多段线得点?</P> sorry,是不识别offsetpnt <P>coordinates是一个数组,里面有好多数</P>
<P>你可以用coordinate(0)表示第一个顶点的x坐标,coordinate(1)表示第一个的y坐标,后面依次</P> <P>offsetline = tmplwline.Offset(distance)的意思是否是tmplwline偏移后的线是offsetline?</P> <P>是,但offsetline是一個數組</P> <P>谢谢yuangw1234,但我运行还有点错误,帮我看看</P>
<P>Sub Ch4_OffsetPolyline()<BR> ' 创建多段线<BR> Dim plineObj As AcadLWPolyline<BR> Dim points(0 To 11) As Double<BR> points(0) = 1: points(1) = 1<BR> points(2) = 1: points(3) = 2<BR> points(4) = 2: points(5) = 2<BR> points(6) = 3: points(7) = 2<BR> points(8) = 4: points(9) = 4<BR> points(10) = 4: points(11) = 1<BR> Set plineObj = ThisDrawing.ModelSpace. _<BR> AddLightWeightPolyline(points)<BR> plineObj.Closed = True<BR> ZoomAll<BR> <BR> ' 偏移多段线<BR> Dim offsetobj As Variant<BR> 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> <P>pnt1(0) = offsetobj(0)</P>
<P>前面是个DOUBLE,后面是个对象,这样赋值当然不行,提取offsetobj中的coordinates属性里的坐标吧!</P> <P>Sub Ch4_OffsetPolyline()<BR> ' 创建多段线<BR> Dim plineObj As AcadLWPolyline<BR> Dim points(0 To 11) As Double<BR> points(0) = 1: points(1) = 1<BR> points(2) = 1: points(3) = 2<BR> points(4) = 2: points(5) = 2<BR> points(6) = 3: points(7) = 2<BR> points(8) = 4: points(9) = 4<BR> points(10) = 4: points(11) = 1<BR> Set plineObj = ThisDrawing.ModelSpace. _<BR> AddLightWeightPolyline(points)<BR> plineObj.Closed = True<BR> <BR> ZoomAll<BR> <BR> ' 偏移多段线<BR> Dim offsetobj As AcadLWPolyline<BR> offsetobj = plineObj.Offset(0.25)<BR> </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> </P>
<P>这样还不行呀,帮帮忙呀,谢谢</P> <P>你的程序的问题出在了下面两处:</P>
<P>1,Dim offsetobj As AcadLWPolyline<BR> offsetobj = plineObj.Offset(0.25)</P>
<P> 对象Offset后返回的是一个对象数组,而你的offsetobj只定义成一种对象类型,那么在运行时回报错。所以改成</P>
<P> Dim offsetobj As Variant<BR> 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> </P>
<P> </P> <P>谢谢楼主,我已经明白了,这样改就好了。我是想得到偏移后线得没个点,现在得到了。</P>
<P> </P>
<P> </P>
<P> </P>
<P>Sub Ch4_OffsetPolyline()<BR> ' 创建多段线<BR> Dim plineObj As AcadLWPolyline<BR> Dim points(0 To 11) As Double<BR> points(0) = 1: points(1) = 1<BR> points(2) = 1: points(3) = 2<BR> points(4) = 2: points(5) = 2<BR> points(6) = 3: points(7) = 2<BR> points(8) = 4: points(9) = 4<BR> points(10) = 4: points(11) = 1<BR> Set plineObj = ThisDrawing.ModelSpace. _<BR> AddLightWeightPolyline(points)<BR> plineObj.Closed = True<BR> <BR> ZoomAll<BR> <BR> ' 偏移多段线<BR> Dim offsetobj As Variant<BR> Dim lineline As AcadLWPolyline<BR> offsetobj = plineObj.Offset(0.25)<BR> Set lineline = offsetobj(0)</P>
<P><BR> Dim pn1(2) As Double<BR> Dim pn2(2) As Double<BR> Dim line As AcadLine<BR> <BR> <BR> pn1(0) = lineline.Coordinates(0)<BR> pn1(1) = lineline.Coordinates(1)<BR> pn1(2) = 0<BR> pn2(0) = 20<BR> pn2(1) = 10<BR> pn2(2) = 0<BR> Set line = ThisDrawing.ModelSpace.AddLine(pn1, pn2)<BR> line.color = acRed</P>
<P>ZoomAll<BR>End Sub</P>
页:
[1]