[求助]多段线
一条多段线,如何等分。再在等分点上插入一个块 <P>看看这个帖子</P><P><A href="http://bbs.mjtd.com/forum.php?mod=viewthread&tid=11775" target="_blank" >http://bbs.mjtd.com/forum.php?mod=viewthread&tid=11775</A></P> <P> CommandSTR <FONT color=blue>=</FONT> <FONT color=#880000>"<FONT color=red>(</FONT>Handent "</FONT> <FONT color=#880000>"" & SsetObj.<FONT color=blue>Item</FONT><FONT color=red>(</FONT>i <FONT color=blue>-</FONT> 1<FONT color=red>)</FONT><FONT color=blue>.</FONT><FONT color=blue>Handle</FONT> & "</FONT> <FONT color=#880000>""<FONT color=red>)</FONT>"</FONT><BR> <FONT color=blue>ThisDrawing</FONT>.<FONT color=blue>SendCommand</FONT> <FONT color=#880000>"MEASURE"</FONT> & vbCr & CommandSTR & vbCr & <FONT color=blue>CStr</FONT><FONT color=red>(</FONT>ds<FONT color=red>)</FONT> & vbCr</P>
<P> 在我这怎么用不了啊。</P> <P> Sub GetPointOfPline()<BR> Const ds As Double = 50 '曲线上的取点间隔<BR> Const bb As String = "1" '块名<BR> <BR> <BR> Dim SsetObj As AcadSelectionSet '选择集对象<BR> Dim SsetPoint As AcadSelectionSet '点选择集<BR> Dim SsetName As String '选择集名称<BR> Dim PointObj As AcadPoint '点对象<BR> Dim CommandSTR As String<BR> Dim Pt() As Double '点坐标<BR> Dim i As Integer, j As Integer<BR> Dim Num1 As Integer, Num2 As Integer</P>
<P> Dim gpCode(0) As Integer<BR> Dim dataValue(0) As Variant<BR> Dim groupCode As Variant, dataCode As Variant<BR> <BR> '选择集名称<BR> SsetName = "SplineSet"<BR> '建立选择集<BR> On Error Resume Next<BR> Set SsetObj = ThisDrawing.SelectionSets.Add(SsetName)<BR> If Err Then<BR> Set SsetObj = ThisDrawing.SelectionSets.Item(SsetName)<BR> SsetObj.Clear<BR> Err.Clear<BR> End If<BR> On Error GoTo 0<BR> <BR> '将曲线添加到选择集<BR> gpCode(0) = 0<BR> dataValue(0) = "LWPOLYLINE"<BR> groupCode = gpCode<BR> dataCode = dataValue<BR> ' SsetObj.Select acSelectionSetAll, , , groupCode, dataCode<BR> <BR> SsetObj.SelectOnScreen groupCode, dataCode<BR> ' MsgBox SsetObj.Count<BR> '打开文件用于存储曲线离散化后的点的坐标<BR> ' Open "D:\curve.txt" For Output As #1<BR> Num1 = SsetObj.Count<BR> ' Print #1, "曲线数目:" & Num1<BR> <BR> '选择集名称<BR> SsetName = "PointSet"<BR> '建立选择集<BR> On Error Resume Next<BR> Set SsetPoint = ThisDrawing.SelectionSets.Add(SsetName)<BR> If Err Then<BR> Set SsetPoint = ThisDrawing.SelectionSets.Item(SsetName)<BR> SsetPoint.Clear<BR> Err.Clear<BR> End If<BR> On Error GoTo 0<BR> '将全部点添加到选择集<BR> gpCode(0) = 0<BR> dataValue(0) = "point"<BR> groupCode = gpCode<BR> dataCode = dataValue<BR> Dim blockRefObj As AcadBlockReference<BR> Dim insertionPnt(0 To 2) As Double<BR> </P>
<P> <BR> '在曲线上每隔一定距离取一个点,依次将点的坐标写入文件<BR> For i = 1 To Num1<BR> CommandSTR = "(Handent """ & SsetObj.Item(i - 1).Handle & """ ) "<BR> ThisDrawing.SendCommand "MEASURE" & vbCr & CommandSTR & vbCr & CStr(ds) & vbCr<BR> SsetPoint.Select acSelectionSetAll, , , groupCode, dataCode<BR> Num2 = SsetPoint.Count<BR> If Num2 <> 0 Then<BR> ReDim Pt(Num2 - 1, 2) As Double<BR> For j = 0 To Num2 - 1<BR> Set PointObj = SsetPoint.Item(j)<BR> Pt(j, 0) = PointObj.Coordinates(0)<BR> Pt(j, 1) = PointObj.Coordinates(1)<BR> Pt(j, 2) = PointObj.Coordinates(2)<BR> </P>
<P> <BR> <BR> Next j<BR> SsetPoint.Erase '删除选择集中所有图元<BR> 'Print #1, "第" & i & "条曲线"<BR> For j = 0 To Num2 - 1<BR> ' Print #1, Format(Pt(j, 0), "0.000"); ""; Format(Pt(j, 1), "0.000"); ""; Format(Pt(j, 2), "0.000")<BR> insertionPnt(0) = Pt(j, 0)<BR> insertionPnt(1) = Pt(j, 1)<BR> insertionPnt(2) = Pt(j, 2)<BR> Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock _<BR> (insertionPnt, bb, 1#, 1#, 1#, 0)<BR> Next j<BR> End If<BR> Next i<BR> Close 1<BR> SsetObj.Delete<BR> <BR> End Sub<BR> </P>
<P>实现多段线等距插入图块。</P>
页:
[1]