明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1526|回复: 0

自动绘螺丝

[复制链接]
发表于 2006-7-17 19:01:00 | 显示全部楼层 |阅读模式

可以绘M5--M10以内的螺丝,命令行内有提示,操作简易,

如果觉得可用,顶一下!

Public Sub mm()
Dim ptcen As Variant
Dim radius As Double
Dim keyword As String
On Error Resume Next
'添加线型
Dim ltypename As String
If linetypeexist(ltypename) = False Then
ltypename = "acad_iso02w100"
ThisDrawing.Linetypes.Load ltypename, "acad.lin"
End If


ptcen = ThisDrawing.Utility.GetPoint(, "请选择圆心:")
ThisDrawing.Utility.InitializeUserInput 0, "m5 m6 m8 m10"
keyword = ThisDrawing.Utility.GetKeyword(vbCrLf & "选取螺纹类型[M5(m5)/M6(m6)/M8(m8)/M10(m10)]:")
If keyword = "" Then keyword = "m8"
If keyword = "m5" Then
addcircle ptcen, 2.1
addcircle1 ptcen, 2.5

End If
If keyword = "m6" Then
addcircle ptcen, 2.5
addcircle1 ptcen, 3
End If
If keyword = "m8" Then
addcircle ptcen, 6.75 / 2
addcircle1 ptcen, 4
End If
If keyword = "m10" Then
addcircle ptcen, 4.25
addcircle1 ptcen, 5

End If
Dim objline As AcadLine
Dim ptst(0 To 2) As Double
Dim pten(0 To 2) As Double
Dim ptst1(0 To 2) As Double
Dim pten1(0 To 2) As Double
ptst(0) = ptcen(0): ptst(1) = ptcen(1) - 5: ptst(2) = 0
pten(0) = ptcen(0): pten(1) = ptcen(1) + 5: pten(2) = 0
ptst1(0) = ptcen(0) - 5: ptst1(1) = ptcen(1): ptst1(2) = 0
pten1(0) = ptcen(0) + 5: pten1(1) = ptcen(1): pten1(2) = 0


Set objline = ThisDrawing.ModelSpace.AddLine(ptst, pten)
objline.color = acBlue

Set objline = ThisDrawing.ModelSpace.AddLine(ptst1, pten1)
objline.color = acBlue


End Sub

Public Function addcircle(ByVal ptcen As Variant, ByVal radius As Double) As AcadCircle
Dim objcir As AcadCircle

Set objcir = ThisDrawing.ModelSpace.addcircle(ptcen, radius)
objcir.color = acBlue
Set objcir = addcircle

End Function
Public Function addcircle1(ByVal ptcen As Variant, ByVal radius As Double) As AcadCircle
Dim objcir As AcadCircle

Set objcir = ThisDrawing.ModelSpace.addcircle(ptcen, radius)
objcir.color = acBlue
objcir.Linetype = "acad_iso02w100"
objcir.LinetypeScale = 0.4
Set objcir = addcircle1

End Function


Public Function linetypeexist(ByVal ltypename As String) As Boolean
Dim element As Object
linetypeexist = False
For Each element In ThisDrawing.Linetypes
If element.Name = UCase(ltypename) Then
linetypeexist = True
Exit For
End If
Next

End Function

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-27 00:21 , Processed in 0.163686 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表