利用VBA实现AutoCAD的样条曲线SPline的打断转化

 SolidWorks、coreldraw、PS、Illustrator等矢量绘图或3D图象图形设计处理软件,在进行CAD格式输出后,转出的CAD文件都是样条曲线SPLINE线,要想转化变成LINE或PLINE线,该怎么办呢?
AutoCAD中并没有提供现成的命令去处理。
我们可以通过AutoCAD提供的二次开发工具VBA来自行解决这个问题。
用AutoCAD打开对应的cad文件,选择“工具”菜单中的“宏”—-”Visual Basic 编辑器"命令,打开VBA编辑器,将下列的代码粘贴到其中,点击运行命令,转化即可在瞬间完成。
相应程序代码命令的含义可以查阅VBA联机文档。

Private Sub covertSP2L() Dim spline As AcadSpline Dim startPoint(0 To 2) As Double Dim endPoint(0 To 2) As Double Dim vline1 As AcadLine Dim n As Integer Dim blk As AcadBlock n = ThisDrawing.Blocks.Item(0).Count Set blk = ThisDrawing.Blocks.Item(0) For i = n - 1 To 0 Step -1 If blk.Item(i).ObjectName = "AcDbSpline" Then Set spline = blk.Item(i) For j = 0 To 3 * spline.NumberOfControlPoints - 6 Step 3 startPoint(0) = spline.ControlPoints(j) startPoint(1) = spline.ControlPoints(j + 1) endPoint(0) = spline.ControlPoints(j + 3) endPoint(1) = spline.ControlPoints(j + 4) Set vline = ThisDrawing.ModelSpace.AddLine(startPoint, endPoint) vline.color = i Next spline.Delete End If Next End Sub

其他的一些方法:
1.命令行键入命令:flatten,按提示选择你要转换的样条曲线即可。
注意:flatten命令是Express扩展工具包中的命令,使用前先确认你已经安装了这个扩展工具。
(use the FLATTEN command and it will convert that spline into a polyline with arc segments.)

2.将要转换的样条曲线复制在一新图中,用“另存为”命令将图纸保存为“AutoCAD R12/L12 DXF (*.dxf)”格式,再“打开”命令选择打开刚才保存的“DXF (*.dxf)”格式文件即可。 (Save the drawing as Autocad R12/LT2 DXF. Close the drawing. Reopen the DXF file. This changes the spline to a polyline. Explode the polyline if needed, and you have lots of little line segments that your CAM program can read.)

你可能感兴趣的:(利用VBA实现AutoCAD的样条曲线SPline的打断转化)