求大神解释CAD的VBA程序代码,谢谢 在线等
SubY02()OnErrorGoToErr:DimVarianAsVariantDimPti(0To2)AsDoubleDimPtHAsStringDimTextHAs...
Sub Y02()
On Error GoTo Err:
Dim Varian As Variant
Dim Pti(0 To 2) As Double
Dim PtH As String
Dim TextH As Double
Dim Po(0 To 2) As Double
Dim Texta As AcadText
Dim Tsc As Double
Dim BlocobjA As AcadBlockReference
Tsc = 1 '比例
PtH = "C:\螺钉标准件\螺钉标准件\六角螺栓.dwg"
'此路径你自定义,必须有;没有会报错
If Dir(PtH) <> "" Then
Varian = ThisDrawing.Utility.GetPoint(, vbCr & "放置点:")
Po(0) = Varian(0): Po(1) = Varian(1): Po(2) = Varian(2)
Set BlocobjA = ThisDrawing.ModelSpace.InsertBlock(Po, PtH, Tsc, Tsc, Tsc, 0)
BlocobjA.Explode
BlocobjA.Delete
Else
MsgBox "<" + PtH + " >文件不存在!!!", vbCritical, "读取文件错误" '文件报错
End If
Err: '错误停止运行
End Sub 展开
On Error GoTo Err:
Dim Varian As Variant
Dim Pti(0 To 2) As Double
Dim PtH As String
Dim TextH As Double
Dim Po(0 To 2) As Double
Dim Texta As AcadText
Dim Tsc As Double
Dim BlocobjA As AcadBlockReference
Tsc = 1 '比例
PtH = "C:\螺钉标准件\螺钉标准件\六角螺栓.dwg"
'此路径你自定义,必须有;没有会报错
If Dir(PtH) <> "" Then
Varian = ThisDrawing.Utility.GetPoint(, vbCr & "放置点:")
Po(0) = Varian(0): Po(1) = Varian(1): Po(2) = Varian(2)
Set BlocobjA = ThisDrawing.ModelSpace.InsertBlock(Po, PtH, Tsc, Tsc, Tsc, 0)
BlocobjA.Explode
BlocobjA.Delete
Else
MsgBox "<" + PtH + " >文件不存在!!!", vbCritical, "读取文件错误" '文件报错
End If
Err: '错误停止运行
End Sub 展开
2个回答
展开全部
Sub Y02()
On Error GoTo Err: '有错跳至err子过程
Dim Varian As Variant '定义Varian 类型
Dim Pti(0 To 2) As Double '定义Pti为数组,内容限0-2行,或列
Dim PtH As String'定义为文本
Dim TextH As Double'为双精度
Dim Po(0 To 2) As Double'为双精度数组
Dim Texta As AcadText'定义为cad单行文本
Dim Tsc As Double
Dim BlocobjA As AcadBlockReference'定义为cad块
Tsc = 1 '比例
PtH = "C:\螺钉标准件\螺钉标准件\六角螺栓.dwg"
'此路径你自定义,必须有;没有会报错
If Dir(PtH) <> "" Then'用dir判断有没有pth文件,没有=""
Varian = ThisDrawing.Utility.GetPoint(, vbCr & "放置点:")'在cad上选择一个坐标,或位置
Po(0) = Varian(0): Po(1) = Varian(1): Po(2) = Varian(2)'取出坐标的xyz值
Set BlocobjA = ThisDrawing.ModelSpace.InsertBlock(Po, PtH, Tsc, Tsc, Tsc, 0)'在po位置插入块pth
BlocobjA.Explode'块分解?
BlocobjA.Delete'块删除
Else
MsgBox "<" + PtH + " >文件不存在!!!", vbCritical, "读取文件错误" '文件报错
End If
Err: '错误停止运行
End Sub
大至是这个意思了
On Error GoTo Err: '有错跳至err子过程
Dim Varian As Variant '定义Varian 类型
Dim Pti(0 To 2) As Double '定义Pti为数组,内容限0-2行,或列
Dim PtH As String'定义为文本
Dim TextH As Double'为双精度
Dim Po(0 To 2) As Double'为双精度数组
Dim Texta As AcadText'定义为cad单行文本
Dim Tsc As Double
Dim BlocobjA As AcadBlockReference'定义为cad块
Tsc = 1 '比例
PtH = "C:\螺钉标准件\螺钉标准件\六角螺栓.dwg"
'此路径你自定义,必须有;没有会报错
If Dir(PtH) <> "" Then'用dir判断有没有pth文件,没有=""
Varian = ThisDrawing.Utility.GetPoint(, vbCr & "放置点:")'在cad上选择一个坐标,或位置
Po(0) = Varian(0): Po(1) = Varian(1): Po(2) = Varian(2)'取出坐标的xyz值
Set BlocobjA = ThisDrawing.ModelSpace.InsertBlock(Po, PtH, Tsc, Tsc, Tsc, 0)'在po位置插入块pth
BlocobjA.Explode'块分解?
BlocobjA.Delete'块删除
Else
MsgBox "<" + PtH + " >文件不存在!!!", vbCritical, "读取文件错误" '文件报错
End If
Err: '错误停止运行
End Sub
大至是这个意思了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询