一个画管道的程序,可有点问题,大家来帮我看看啊,救命的!!!!
<P> 是通过拉伸路径来画管道的,输入两个点时能画出管道,当输入三个及三个以上的点是就有问题了,对于三个和三个以上的点的思路是这样的:</P><P>1.取第一点,第二点,第三点分别赋给point1,point2,point3(在这里遇到一个问题,point1和point3的点是正确的,point2的点就不正确,不知道是为什么),</P>
<P>2.根据这三个点,确立用户坐标系,在用户坐标系中画出多段线,回复到WCS坐标系,</P>
<P>3.在point1处,生成管道的剖面,根据多段线来进行三维旋转,最后进行拉伸</P>
<P>基本思路就是这样,下面是程序,各位高手帮我看看哪要改,是毕业设计的东西,求助大家了</P>
<P>说明:p(i)是自定义类型,用来存放输入的点的XYZ坐标的</P>
<P>For i = 1 To (UBound(p) - 1)</P>
<P> point1(0) = p(i - 1).x: point1(1) = p(i - 1).y: point1(2) = p(i - 1).z<BR> point2(0) = p(i).x: point2(0) = p(i).y: point2(2) = p(i).z<BR> point3(0) = p(i + 1).x: point3(1) = p(i + 1).y: point3(2) = p(i + 1).z<BR> If p(i - 1).z = p(i).z & p(i).z = p(i + 1).z Then <BR> '设定坐标系<BR> '定义UCS参数<BR> UCSorigin(0) = 0:UCSorigin(1) = 0:UCSorigin(2) = p(i).z<BR> UCS1Point(0) = 10:UCS1Point(1) = 0:UCS1Point(2) = p(i).z<BR> UCS1Point(0) = 0:UCS1Point(1) = 10:UCS1Point(2) = p(i).z<BR> '创建UCS<BR> Set myUCS=ThisDrawing.UserCoordinateSystems.Add (UCSorigin, UCS1Point, UCS2Point, "新建UCS")</P>
<P> '设置当前UCS<BR> ThisDrawing.ActiveUCS = myUCS<BR> '画多段线<BR> point5(0) = point1(0): point5(1) = point1(1)<BR> point5(2) = point2(0): point5(3) = point2(1)<BR> point5(4) = point3(0): point5(5) = point3(1)<BR> Set polyObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(point5) <BR> '回复WCS<BR> ThisDrawing.SendCommand "UCS" & vbCr & vbCr<BR> <BR> ElseIf p(i - 1).y = p(i).y & p(i).y = p(i + 1).y Then<BR> '设定坐标系<BR> '定义UCS参数<BR> UCSorigin(0) = 0:UCSorigin(1) = p(i).y:UCSorigin(2) = 0<BR> UCS1Point(0) = 10:UCS1Point(1) = p(i).y:UCS1Point(2) = 0<BR> UCS2Point(0) = 0:UCS2Point(1) = p(i).y:UCS2Point(2) = 10 <BR> '创建UCS<BR> Set myUCS = ThisDrawing.UserCoordinateSystems.Add(UCSorigin, UCS1Point, UCS2Point, "新建UCS")</P>
<P> '设置当前UCS<BR> ThisDrawing.ActiveUCS = myUCS<BR> '画多段线<BR> point5(0) = point1(0): point5(1) = point1(2)<BR> point5(2) = point2(0): point5(3) = point2(2)<BR> point5(4) = point3(0): point5(5) = point3(2)<BR> Set polyObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(point5)<BR> '回复WCS<BR> ThisDrawing.SendCommand "UCS" & vbCr & vbCr<BR> <BR> ElseIf p(i - 1).x = p(i).x & p(i).x = p(i + 1).x Then <BR> '设定坐标系<BR> '定义UCS参数<BR> UCSorigin(0) = p(i).x:UCSorigin(1) = 0:UCSorigin(2) = 0<BR> UCS1Point(0) = p(i).x:UCS1Point(1) = 10:UCS1Point(2) = 0<BR> UCS1Point(0) = p(i).x:UCS1Point(1) = 0:UCS1Point(2) = 10<BR> '创建UCS<BR> Set myUCS = ThisDrawing.UserCoordinateSystems.Add(UCSorigin, UCS1Point, UCS2Point, "新建UCS")</P>
<P> '设置当前UCS<BR> ThisDrawing.ActiveUCS = myUCS<BR> '画多段线<BR> point5(0) = point1(1): point5(1) = point1(2)<BR> point5(2) = point2(1): point5(3) = point2(2)<BR> point5(4) = point3(1): point5(5) = point3(2)<BR> Set polyObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(point5)<BR> '回复WCS<BR> ThisDrawing.SendCommand "UCS" & vbCr & vbCr<BR> End If<BR> <BR> '创建面域<BR> Set circle1(0) = ThisDrawing.ModelSpace.AddCircle(point1, radius1)<BR> Set circle2(0) = ThisDrawing.ModelSpace.AddCircle(point1, radius2)<BR> regionObj1 = ThisDrawing.ModelSpace.AddRegion(circle1)<BR> regionObj2 = ThisDrawing.ModelSpace.AddRegion(circle2)<BR> <BR> '布尔运算<BR> regionObj1(0).Boolean acSubtraction, regionObj2(0)<BR> <BR> '三维旋转<BR> If point1(0) <> point2(0) & point1(1) = point2(1) & point1(2) = point2(2) Then<BR> point4(0) = point1(0)<BR> point4(1) = point1(1) + 10<BR> point4(2) = point1(2)<BR> Set line1 = ThisDrawing.ModelSpace.AddLine(point1, point4)<BR> regionObj1(0).Rotate3D point1, point4, rotateAngle<BR> line1.Delete<BR> circle1(0).Delete<BR> circle2(0).Delete<BR> ElseIf point1(0) = point2(0) & point1(1) <> point2(1) & point1(2) = point2(2) Then<BR> point4(0) = point1(0) + 10<BR> point4(1) = point1(1)<BR> point4(2) = point1(2)<BR> Set line1 = ThisDrawing.ModelSpace.AddLine(point1, point3)<BR> regionObj1(0).Rotate3D point1, point4, rotateAngle<BR> line1.Delete<BR> circle1(0).Delete<BR> circle2(0).Delete<BR> End If<BR> <BR> '拉伸<BR> Set regionObj1(0) = ThisDrawing.ModelSpace.AddExtrudedSolidAlongPath(regionObj1(0), polyObj)<BR> Next i</P> <P>我也在写管道的程序,我也遇到同样的问题,求高手帮忙吧~~</P> 搞不清楚你得P怎么定义的,还有一个FOR.......Next.能不能把前面缺的那段程序也贴上,也许问题就处在你的For.......Next上。 <P>下面是我全部的程序:</P>
<P>Option Explicit<BR>Private Type POINTAPI<BR>x As Double<BR>y As Double<BR>z As Double<BR>End Type<BR>Dim p() As POINTAPI</P>
<P><BR>Private Sub UserForm_Initialize()<BR>ReDim p(0) As POINTAPI<BR>End Sub</P>
<P><BR>Private Sub CommandButton1_Click() <BR> p(UBound(p)).x = Val(TextBox1.Text)<BR> p(UBound(p)).y = Val(TextBox2.Text)<BR> p(UBound(p)).z = Val(TextBox3.Text)<BR> ReDim Preserve p(UBound(p) + 1)</P>
<P> TextBox1.Text = ""<BR> TextBox2.Text = ""<BR> TextBox3.Text = ""</P>
<P> TextBox1.SetFocus<BR>End Sub</P>
<P> </P>
<P>Private Sub CommandButton2_Click() <BR> '存点<BR> p(UBound(p)).x = Val(TextBox1.Text)<BR> p(UBound(p)).y = Val(TextBox2.Text)<BR> p(UBound(p)).z = Val(TextBox3.Text) <BR> ' 定义变量 <BR> Dim i As Integer<BR> Dim j As Integer<BR> Dim rotateAngle As Double<BR> Dim point1(0 To 2) As Double, point2(0 To 2) As Double, point3(0 To 2) As Double, point4(0 To 2) As Double<BR> Dim point5(0 To 5) As Double<BR> Dim circle1(0) As AcadEntity, circle2(0) As AcadEntity<BR> Dim regionObj1 As Variant, regionObj2 As Variant<BR> Dim radius1 As Double, radius2 As Double<BR> Dim line1 As AcadLine<BR> Dim solidObj As Acad3DSolid<BR> Dim polyObj As AcadLWPolyline<BR> Dim myUCS As AcadUCS<BR> Dim UCSorigin(0 To 2) As Double<BR> Dim UCS1Point(0 To 2) As Double<BR> Dim UCS2Point(0 To 2) As Double<BR> radius1 = 10<BR> radius2 = 8<BR> rotateAngle = 90 * 3.141592 / 180<BR> i = UBound(p)<BR> j = UBound(p) - 1<BR> If i = 0 Then<BR> MsgBox "请输入两个以上定位点!"<BR> ElseIf i = 1 Then<BR> Call AddPipeline1<BR> Else<BR> For i = 1 To j<BR> point1(0) = p(i - 1).x: point1(1) = p(i - 1).y: point1(2) = p(i - 1).z<BR> point2(0) = p(i).x: point2(0) = p(i).y: point2(2) = p(i).z<BR> point3(0) = p(i + 1).x: point3(1) = p(i + 1).y: point3(2) = p(i + 1).z<BR> If p(i - 1).z = p(i).z And p(i).z = p(i + 1).z Then<BR> '设定坐标系<BR> '定义UCS参数<BR> UCSorigin(0) = 0:UCSorigin(1) = 0:UCSorigin(2) = p(i).z<BR> UCS1Point(0) = 10:UCS1Point(1) = 0:UCS1Point(2) = p(i).z<BR> UCS1Point(0) = 0:UCS1Point(1) = 10:UCS1Point(2) = p(i).z<BR> '创建UCS<BR> Set myUCS = ThisDrawing.UserCoordinateSystems.Add(UCSorigin, UCS1Point, UCS2Point, "新建UCS")</P>
<P> '设置当前UCS<BR> ThisDrawing.ActiveUCS = myUCS<BR> '画多段线<BR> point5(0) = point1(0): point5(1) = point1(1)<BR> point5(2) = point2(0): point5(3) = point2(1)<BR> point5(4) = point3(0): point5(5) = point3(1)<BR> Set polyObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(point5) <BR> '回复WCS<BR> ThisDrawing.SendCommand "UCS" & vbCr & vbCr <BR> ElseIf p(i - 1).y = p(i).y And p(i).y = p(i + 1).y Then<BR> '设定坐标系 <BR> '定义UCS参数<BR> UCSorigin(0) = 0:UCSorigin(1) = p(i).y:UCSorigin(2) = 0<BR> UCS1Point(0) = 10:UCS1Point(1) = p(i).y:UCS1Point(2) = 0<BR> UCS2Point(0) = 0:UCS2Point(1) = p(i).y:UCS2Point(2) = 10 <BR> '创建UCS<BR> Set myUCS = ThisDrawing.UserCoordinateSystems.Add(UCSorigin, UCS1Point, UCS2Point, "新建UCS")</P>
<P> '设置当前UCS<BR> ThisDrawing.ActiveUCS = myUCS<BR><BR> '画多段线<BR> point5(0) = point1(0) : point5(1) = point1(2)<BR> point5(2) = point2(0): point5(3) = point2(2)<BR> point5(4) = point3(0): point5(5) = point3(2)<BR> Set polyObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(point5)<BR> '回复WCS<BR> ThisDrawing.SendCommand "UCS" & vbCr & vbCr<BR> ElseIf p(i - 1).x = p(i).x And p(i).x = p(i + 1).x Then<BR> '设定坐标系<BR> '定义UCS参数<BR> UCSorigin(0) = p(i).x : UCSorigin(1) = 0 : UCSorigin(2) = 0<BR> UCS1Point(0) = p(i).x : UCS1Point(1) = 10 : UCS1Point(2) = 0<BR> UCS1Point(0) = p(i).x : UCS1Point(1) = 0 : UCS1Point(2) = 10<BR> '创建UCS<BR> Set myUCS = ThisDrawing.UserCoordinateSystems.Add(UCSorigin, UCS1Point, UCS2Point, "新建UCS")</P>
<P> '设置当前UCS<BR> ThisDrawing.ActiveUCS = myUCS<BR> '画多段线<BR> point5(0) = point1(1): point5(1) = point1(2)<BR> point5(2) = point2(1): point5(3) = point2(2)<BR> point5(4) = point3(1): point5(5) = point3(2)<BR> Set polyObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(point5)<BR> <BR> '回复WCS<BR> ThisDrawing.SendCommand "UCS" & vbCr & vbCr<BR> End If<BR> '创建面域<BR> Set circle1(0) = ThisDrawing.ModelSpace.AddCircle(point1, radius1)<BR> Set circle2(0) = ThisDrawing.ModelSpace.AddCircle(point1, radius2)<BR> regionObj1 = ThisDrawing.ModelSpace.AddRegion(circle1)<BR> regionObj2 = ThisDrawing.ModelSpace.AddRegion(circle2)<BR> '布尔运算<BR> regionObj1(0).Boolean acSubtraction, regionObj2(0)<BR> '三维旋转<BR> If point1(0) <> point2(0) And point1(1) = point2(1) And point1(2) = point2(2) Then<BR> point4(0) = point1(0)<BR> point4(1) = point1(1) + 10<BR> point4(2) = point1(2)<BR> Set line1 = ThisDrawing.ModelSpace.AddLine(point1, point4)<BR> regionObj1(0).Rotate3D point1, point4, rotateAngle<BR> line1.Delete<BR> circle1(0).Delete<BR> circle2(0).Delete<BR> ElseIf point1(0) = point2(0) And point1(1) <> point2(1) And point1(2) = point2(2) Then<BR> point4(0) = point1(0) + 10<BR> point4(1) = point1(1)<BR> point4(2) = point1(2)<BR> Set line1 = ThisDrawing.ModelSpace.AddLine(point1, point3)<BR> regionObj1(0).Rotate3D point1, point4, rotateAngle<BR> line1.Delete<BR> circle1(0).Delete<BR> circle2(0).Delete<BR> End If<BR> '拉伸<BR> Set regionObj1(0) = ThisDrawing.ModelSpace.AddExtrudedSolidAlongPath(regionObj1(0), polyObj)<BR> Next i<BR> End If<BR> End<BR>End Sub</P>
<P>Public Function AddPipeline1()</P>
<P> '定义变量<BR> Dim line1 As AcadLine<BR> Dim line2 As AcadLine<BR> Dim circle1(0) As AcadEntity<BR> Dim circle2(0) As AcadEntity<BR> Dim regionObj1 As Variant<BR> Dim regionObj2 As Variant<BR> Dim point1(0 To 2) As Double<BR> Dim point2(0 To 2) As Double<BR> Dim point3(0 To 2) As Double<BR> Dim radius1 As Double<BR> Dim radius2 As Double<BR> Dim solidObj As Acad3DSolid<BR> Dim rotateAngle As Double<BR> Dim LWPolyLine As AcadLWPolyline<BR> radius1 = 15<BR> radius2 = 10<BR> point1(0) = p(0).x: point1(1) = p(0).y: point1(2) = p(0).z<BR> point2(0) = p(1).x: point2(1) = p(1).y: point2(2) = p(1).z<BR> Set line1 = ThisDrawing.ModelSpace.AddLine(point1, point2)<BR> rotateAngle = 90 * 3.141592 / 180#<BR> '创建面域<BR> Set circle1(0) = ThisDrawing.ModelSpace.AddCircle(point1, radius1)<BR> Set circle2(0) = ThisDrawing.ModelSpace.AddCircle(point1, radius2)<BR> regionObj1 = ThisDrawing.ModelSpace.AddRegion(circle1)<BR> regionObj2 = ThisDrawing.ModelSpace.AddRegion(circle2)<BR> '布尔运算<BR> regionObj1(0).Boolean acSubtraction, regionObj2(0)<BR> '三维旋转<BR> If p(0).x <> p(1).x Then<BR> point3(0) = p(0).x<BR> point3(1) = p(0).y + 10<BR> point3(2) = p(0).z<BR> Set line2 = ThisDrawing.ModelSpace.AddLine(point1, point3)<BR> regionObj1(0).Rotate3D point1, point3, rotateAngle<BR> line2.Delete<BR> ElseIf p(0).y <> p(1).y Then<BR> point3(0) = p(0).x + 10<BR> point3(1) = p(0).y<BR> point3(2) = p(0).z<BR> Set line2 = ThisDrawing.ModelSpace.AddLine(point1, point3)<BR> regionObj1(0).Rotate3D point1, point3, rotateAngle<BR> line2.Delete<BR> End If<BR> circle1(0).Delete<BR> circle2(0).Delete <BR> '拉伸<BR> Set solidObj = ThisDrawing.ModelSpace.AddExtrudedSolidAlongPath(regionObj1(0), line1) <BR>End Function</P>
<P> </P> <P>高手们快来看看,帮帮我啊!!!!</P>
<P>谢谢各位啊!!!</P> <P>虽然不懂管道是怎么回事,不过说说</P>
<P>1 先回答你为什么第二个点不对的原因,这是你的程序:</P>
<P>point1(0) = p(i - 1).x: point1(1) = p(i - 1).y: point1(2) = p(i - 1).z<BR> point2(0) = p(i).x: point2(0) = p(i).y: point2(2) = p(i).z<BR> point3(0) = p(i + 1).x: point3(1) = p(i + 1).y: point3(2) = p(i + 1).z</P>
<P>point2(0) = p(i).y这句是你的笔误还是什么就不知道,直接导致了后面点的错误</P>
<P>2 ThisDrawing.ActiveUCS = myUCS这种方法好像转不动坐标系吧,不如</P>
<P> ThisDrawing.SendCommand "ucs" & vbCr & "r" & vbCr & myUCS.Name & vbCr<BR></P>
<P>你这种写法好像处理的情况考虑的太少了,也可能我不懂这方面,比如说圆环截面到底是沿哪个方向我也没看懂,随便写了几个数,到这就卡住了</P>
<P>Set solidObj = ThisDrawing.ModelSpace.AddExtrudedSolidAlongPath(regionObj1(0), line1) </P>
<P>一看截面和拉伸路径在一个平面上。。。呵呵!真是门外汉啊^_^</P>
页:
[1]