一个修测曲线(Vba开发)的例子
<P>Sub xcqx()<BR>On Error GoTo xu<BR>Dim mysel As AcadSelectionSet<BR>Dim xzd As Variant<BR>Dim addp As Variant<BR>Dim xzd1(0 To 2) As Double<BR>Dim bzuo As Variant<BR>Dim lin As AcadLWPolyline<BR>Dim lim As Acad3DPolyline<BR>If ThisDrawing.SelectionSets.Count = 0 Then<BR>Set mysel = ThisDrawing.SelectionSets.Add("mysel")<BR>AppActivate ThisDrawing.Application.Caption<BR>ThisDrawing.SetVariable "OSMODE", 512<BR>'ThisDrawing.ObjectSnapMode = True<BR>xzd = ThisDrawing.Utility.GetPoint(, "修测起点:")<BR>mysel.SelectAtPoint xzd<BR>Else<BR>ThisDrawing.SelectionSets.Item(0).Delete<BR>Set mysel = ThisDrawing.SelectionSets.Add("mysel")<BR>AppActivate ThisDrawing.Application.Caption<BR>ThisDrawing.SetVariable "OSMODE", 512<BR>'ThisDrawing.ObjectSnapMode = True<BR>xzd = ThisDrawing.Utility.GetPoint(, "修测起点:")<BR>mysel.SelectAtPoint xzd<BR>End If</P><P>xzd1(0) = xzd(0): xzd1(1) = xzd(1): xzd1(2) = xzd(2)<BR>If mysel.Count = 1 Then<BR>mysel(0).Highlight True<BR>ThisDrawing.ActiveLayer = ThisDrawing.Layers(mysel(0).Layer)<BR>If mysel(0).EntityType = 24 Then '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>二维线<BR>ReDim zuob1(0 To 1) As Double<BR>zuob1(0) = xzd(0): zuob1(1) = xzd(1)<BR>On Error GoTo we<BR>ThisDrawing.SetVariable "OSMODE", 0<BR>For i = 1 To 1000<BR>addp = ThisDrawing.Utility.GetPoint(xzd, "请输入")<BR>xzd(0) = addp(0): xzd(1) = addp(1): xzd(2) = addp(2)<BR>If Not lin Is Nothing Then<BR>lin.Delete<BR>End If</P>
<P>ReDim Preserve zuob1(0 To 2 * (i + 1) - 1) As Double<BR>zuob1(2 * (i + 1) - 2) = addp(0): zuob1(2 * (i + 1) - 1) = addp(1)<BR>Set lin = ThisDrawing.ModelSpace.AddLightWeightPolyline(zuob1)<BR>lin.Highlight True<BR>Next<BR>we:<BR>If Not lin Is Nothing Then<BR>bzuo = mysel(0).Coordinates<BR>For i = 0 To UBound(bzuo) - 2 Step 2<BR> dis1 = Sqr((bzuo(i) - bzuo(i + 2)) ^ 2 + (bzuo(i + 1) - bzuo(i + 3)) ^ 2)<BR> dis2 = Sqr((bzuo(i) - xzd1(0)) ^ 2 + (bzuo(i + 1) - xzd1(1)) ^ 2) + Sqr((bzuo(i + 2) - xzd1(0)) ^ 2 + (bzuo(i + 3) - xzd1(1)) ^ 2)<BR> If dis2 - dis1 <= 0.1 Then<BR> m = (i + 2) / 2<BR> End If<BR> dis1 = Sqr((bzuo(i) - bzuo(i + 2)) ^ 2 + (bzuo(i + 1) - bzuo(i + 3)) ^ 2)<BR> dis2 = Sqr((bzuo(i) - xzd(0)) ^ 2 + (bzuo(i + 1) - xzd(1)) ^ 2) + Sqr((bzuo(i + 2) - xzd(0)) ^ 2 + (bzuo(i + 3) - xzd(1)) ^ 2)<BR> If dis2 - dis1 <= 0.1 Then<BR> n = (i + 2) / 2<BR> End If<BR>Next</P>
<P>ReDim zuob(0 To UBound(zuob1) + 2 * (-Abs(m - n)) + UBound(bzuo) + 1) As Double<BR>If m > n Then<BR> lk = 0<BR> For j = 0 To UBound(bzuo) Step 2<BR> If j / 2 + 1 <= n Then<BR> zuob(lk) = bzuo(j): zuob(lk + 1) = bzuo(j + 1)<BR> lk = lk + 2<BR> ElseIf j / 2 + 1 = n + 1 Then<BR> For k = UBound(zuob1) To 0 Step -2<BR> zuob(lk) = zuob1(k - 1): zuob(lk + 1) = zuob1(k)<BR> lk = lk + 2<BR> Next<BR> ElseIf j / 2 + 1 > m Then<BR> zuob(lk) = bzuo(j): zuob(lk + 1) = bzuo(j + 1)<BR> lk = lk + 2<BR> End If<BR> Next</P>
<P>ElseIf n > m Then<BR> lk = 0<BR> For j = 0 To UBound(bzuo) Step 2<BR> If j / 2 + 1 <= m Then<BR> zuob(lk) = bzuo(j): zuob(lk + 1) = bzuo(j + 1)<BR> lk = lk + 2<BR> ElseIf j / 2 + 1 = m + 1 Then<BR> For k = 0 To UBound(zuob1) Step 2<BR> zuob(lk) = zuob1(k): zuob(lk + 1) = zuob1(k + 1)<BR> lk = lk + 2<BR> Next<BR> ElseIf j / 2 + 1 > n Then<BR> zuob(lk) = bzuo(j): zuob(lk + 1) = bzuo(j + 1)<BR> lk = lk + 2<BR> End If<BR> Next</P>
<P>ElseIf n = m Then<BR>ReDim zuob(0 To UBound(zuob1) + UBound(bzuo) + 1) As Double<BR>lk = 0<BR>For j = 0 To UBound(bzuo) Step 2<BR> If j / 2 + 1 < m Then<BR> zuob(lk) = bzuo(j): zuob(lk + 1) = bzuo(j + 1)<BR> lk = lk + 2<BR> ElseIf j / 2 + 1 = m Then<BR> zuob(lk) = bzuo(j): zuob(lk + 1) = bzuo(j + 1)<BR> lk = lk + 2<BR> dis01 = Sqr((bzuo(j) - zuob1(0)) ^ 2 + (bzuo(j + 1) - zuob1(1)) ^ 2)<BR> dis02 = Sqr((bzuo(j) - zuob1(UBound(zuob1) - 1)) ^ 2 + (bzuo(j + 1) - zuob1(UBound(zuob1))) ^ 2)<BR> If dis01 < dis02 Then<BR> For k = 0 To UBound(zuob1) Step 2<BR> zuob(lk) = zuob1(k): zuob(lk + 1) = zuob1(k + 1)<BR> lk = lk + 2<BR> Next<BR> Else<BR> For k = UBound(zuob1) To 0 Step -2<BR> zuob(lk) = zuob1(k - 1): zuob(lk + 1) = zuob1(k)<BR> lk = lk + 2<BR> Next<BR> End If<BR> ElseIf j / 2 + 1 > m Then<BR> zuob(lk) = bzuo(j): zuob(lk + 1) = bzuo(j + 1)<BR> lk = lk + 2<BR> End If<BR>Next<BR>End If<BR>If mysel(0).Closed = True Then<BR>Set lin1 = ThisDrawing.ModelSpace.AddLightWeightPolyline(zuob)<BR>lin1.Elevation = mysel(0).Elevation<BR>lin1.Closed = True<BR>lin1.Update<BR>Else<BR>Set lin1 = ThisDrawing.ModelSpace.AddLightWeightPolyline(zuob)<BR>lin1.Elevation = mysel(0).Elevation<BR>lin1.Update<BR>End If<BR>mysel(0).Delete<BR>lin.Delete<BR>End If</P>
<P>ElseIf mysel(0).EntityType = 2 Then '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>三维线<BR>ReDim zuob1(0 To 2) As Double<BR>zuob1(0) = xzd(0): zuob1(1) = xzd(1): zuob1(2) = xzd(2)<BR>On Error GoTo we1<BR>ThisDrawing.SetVariable "OSMODE", 0<BR>For i = 1 To 1000<BR>addp = ThisDrawing.Utility.GetPoint(xzd, "请输入")<BR>xzd(0) = addp(0): xzd(1) = addp(1): xzd(2) = xzd1(2)</P>
<P>If Not lim Is Nothing Then<BR>lim.Delete<BR>End If</P>
<P>ReDim Preserve zuob1(0 To 3 * (i + 1) - 1) As Double<BR>zuob1(3 * (i + 1) - 3) = addp(0): zuob1(3 * (i + 1) - 2) = addp(1): zuob1(3 * (i + 1) - 1) = xzd1(2)<BR>Set lim = ThisDrawing.ModelSpace.Add3DPoly(zuob1)<BR>lim.Highlight True<BR>Next<BR>we1:<BR>If Not lim Is Nothing Then<BR>bzuo = mysel(0).Coordinates<BR>For i = 0 To UBound(bzuo) - 3 Step 3<BR> dis1 = Sqr((bzuo(i) - bzuo(i + 3)) ^ 2 + (bzuo(i + 1) - bzuo(i + 4)) ^ 2)<BR> dis2 = Sqr((bzuo(i) - xzd1(0)) ^ 2 + (bzuo(i + 1) - xzd1(1)) ^ 2) + Sqr((bzuo(i + 3) - xzd1(0)) ^ 2 + (bzuo(i + 4) - xzd1(1)) ^ 2)<BR> If dis2 - dis1 <= 0.1 Then<BR> m = (i + 3) / 3<BR> End If<BR> dis1 = Sqr((bzuo(i) - bzuo(i + 3)) ^ 2 + (bzuo(i + 1) - bzuo(i + 4)) ^ 2)<BR> dis2 = Sqr((bzuo(i) - xzd(0)) ^ 2 + (bzuo(i + 1) - xzd(1)) ^ 2) + Sqr((bzuo(i + 3) - xzd(0)) ^ 2 + (bzuo(i + 4) - xzd(1)) ^ 2)<BR> If dis2 - dis1 <= 0.1 Then<BR> n = (i + 3) / 3<BR> End If<BR>Next</P>
<P>ReDim zuob(0 To UBound(zuob1) + 3 * (-Abs(m - n)) + UBound(bzuo) + 1) As Double<BR>If m > n Then<BR> lk = 0<BR> For j = 0 To UBound(bzuo) Step 3<BR> If j / 3 + 1 <= n Then<BR> zuob(lk) = bzuo(j): zuob(lk + 1) = bzuo(j + 1): zuob(lk + 2) = bzuo(j + 2)<BR> lk = lk + 3<BR> ElseIf j / 3 + 1 = n + 1 Then<BR> For k = UBound(zuob1) To 0 Step -3<BR> zuob(lk) = zuob1(k - 2): zuob(lk + 1) = zuob1(k - 1): zuob(lk + 2) = zuob1(k)<BR> lk = lk + 3<BR> Next<BR> ElseIf j / 3 + 1 > m Then<BR> zuob(lk) = bzuo(j): zuob(lk + 1) = bzuo(j + 1): zuob(lk + 2) = bzuo(j + 2)<BR> lk = lk + 3<BR> End If<BR> Next</P>
<P>ElseIf n > m Then<BR> lk = 0<BR> For j = 0 To UBound(bzuo) Step 3<BR> If j / 3 + 1 <= m Then<BR> zuob(lk) = bzuo(j): zuob(lk + 1) = bzuo(j + 1): zuob(lk + 2) = bzuo(j + 2)<BR> lk = lk + 3<BR> ElseIf j / 3 + 1 = m + 1 Then<BR> For k = 0 To UBound(zuob1) Step 3<BR> zuob(lk) = zuob1(k): zuob(lk + 1) = zuob1(k + 1): zuob(lk + 2) = zuob1(k + 2)<BR> lk = lk + 3<BR> Next<BR> ElseIf j / 3 + 1 > n Then<BR> zuob(lk) = bzuo(j): zuob(lk + 1) = bzuo(j + 1): zuob(lk + 2) = bzuo(j + 2)<BR> lk = lk + 3<BR> End If<BR> Next</P>
<P>ElseIf n = m Then<BR>ReDim zuob(0 To UBound(zuob1) + UBound(bzuo) + 1) As Double<BR>lk = 0<BR>For j = 0 To UBound(bzuo) Step 3<BR> If j / 3 + 1 < m Then<BR> zuob(lk) = bzuo(j): zuob(lk + 1) = bzuo(j + 1): zuob(lk + 2) = bzuo(j + 2)<BR> lk = lk + 3<BR> ElseIf j / 3 + 1 = m Then<BR> zuob(lk) = bzuo(j): zuob(lk + 1) = bzuo(j + 1): zuob(lk + 2) = bzuo(j + 2)<BR> lk = lk + 3<BR> dis01 = Sqr((bzuo(j) - zuob1(0)) ^ 2 + (bzuo(j + 1) - zuob1(1)) ^ 2)<BR> dis02 = Sqr((bzuo(j) - zuob1(UBound(zuob1) - 2)) ^ 2 + (bzuo(j + 1) - zuob1(UBound(zuob1) - 1)) ^ 2)<BR> If dis01 < dis02 Then<BR> For k = 0 To UBound(zuob1) Step 3<BR> zuob(lk) = zuob1(k): zuob(lk + 1) = zuob1(k + 1): zuob(lk + 2) = zuob1(k + 2)<BR> lk = lk + 3<BR> Next<BR> Else<BR> For k = UBound(zuob1) To 0 Step -3<BR> zuob(lk) = zuob1(k - 2): zuob(lk + 1) = zuob1(k - 1): zuob(lk + 2) = zuob1(k)<BR> lk = lk + 3<BR> Next<BR> End If<BR> ElseIf j / 3 + 1 > m Then<BR> zuob(lk) = bzuo(j): zuob(lk + 1) = bzuo(j + 1): zuob(lk + 2) = bzuo(j + 2)<BR> lk = lk + 3<BR> End If<BR>Next<BR>End If<BR>If mysel(0).Closed = True Then<BR>Set lim1 = ThisDrawing.ModelSpace.Add3DPoly(zuob)<BR>lim1.Closed = True<BR>lim1.Update<BR>Else<BR>Set lim1 = ThisDrawing.ModelSpace.Add3DPoly(zuob)<BR>lim1.Update<BR>End If<BR>mysel(0).Delete<BR>lim.Delete<BR>End If<BR>End If<BR>If mysel.Count <> 0 Then<BR>mysel.Delete<BR>End If<BR>End If<BR>xu:<BR>End Sub<BR></P>
<P><FONT color=#ff0000 face=隶书> 与大家交流,提高自己的水平!!!!</FONT></P> 如果目标的是两条线,如何修测?
页:
[1]