明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 15287|回复: 36

[分享]闲来无事,写了这个编号的程序

  [复制链接]
发表于 2004-5-11 18:12:00 | 显示全部楼层 |阅读模式
搞来玩的,望各位大侠指点一二。 'by gzy
'gzy@mjtd.com Dim Nums As Integer Sub Numbers()
Nums = 1
Dim keyWord As String
ThisDrawing.Utility.InitializeUserInput 0, "y n"
keyWord = ThisDrawing.Utility.GetKeyword(vbCrLf & "编号是否带圈[否(N)/是(Y)][N]: ")

If keyWord = "" Then
keyWord = "N"
Call Ncircle
Else
Call Cir
End If

If keyWord = "N" Then Call Ncircle
End Sub Sub Ncircle()
RETRY:
Dim PPck1 As Variant, PPck2 As Variant
Dim textobject(0) As AcadObject: Dim line1 As AcadLine: Dim line2 As AcadLine
Dim ppt(0 To 2) As Double: Dim Numbers1 As String: Dim Inserpt(0 To 2) As Double

On Error Resume Next
PPck1 = ThisDrawing.Utility.GetPoint(, "请指定零件:")
If Err <> 0 Then
Err.Clear
ThisDrawing.Utility.Prompt " 没有指定零件,退出"
Exit Sub
End If
PPck2 = ThisDrawing.Utility.GetPoint(, "请指定编号位置:")
If Err <> 0 Then
Err.Clear
ThisDrawing.Utility.Prompt " 没有指定编号位置,退出"
Exit Sub
End If
Set line1 = ThisDrawing.ModelSpace.AddLine(PPck1, PPck2)
TextHeight = ThisDrawing.GetVariable("dimtxt") '沿用系统文字高度

If pd(PPck1, PPck2) = True Then
ppt(0) = PPck2(0) - 2 * TextHeight: ppt(1) = PPck2(1): ppt(2) = PPck2(2)
Else
ppt(0) = PPck2(0) + 2 * TextHeight: ppt(1) = PPck2(1): ppt(2) = PPck2(2)
End If

Set line2 = ThisDrawing.ModelSpace.AddLine(PPck2, ppt)
line2.Lineweight = acLnWt030
ThisDrawing.SendCommand "_LWDISPLAY" & vbCr & "on" & vbCr '显示线宽

Numbers1 = ThisDrawing.Utility.GetString(0, vbCrLf & "请输入编号数字(上一编号为" & Nums - 1 & ")" & "[" & Nums & "]:")
If Numbers1 = "" Then Numbers1 = Nums
If pd(PPck1, PPck2) = True Then
Inserpt(0) = ppt(0) + 0.5 * TextHeight: Inserpt(1) = ppt(1) + 0.2 * TextHeight: Inserpt(2) = ppt(2)
Else
Inserpt(0) = ppt(0) - 1.5 * TextHeight: Inserpt(1) = ppt(1) + 0.2 * TextHeight: Inserpt(2) = ppt(2)
End If
Set textobject(0) = ThisDrawing.ModelSpace.AddText(Numbers1, Inserpt, TextHeight)
Nums = Numbers1 '使提示与上一编号关联
Nums = Nums + 1
GoTo RETRY
End Sub Sub Cir()
RETRY:
Dim PPck1 As Variant, PPck2 As Variant
Dim textobject(0) As AcadObject: Dim line1 As AcadLine: Dim Cirobj As AcadCircle
Dim ppt(0 To 2) As Double: Dim Numbers1 As String: Dim Inserpt(0 To 2) As Double

On Error Resume Next
PPck1 = ThisDrawing.Utility.GetPoint(, "请指定零件:")
If Err <> 0 Then
Err.Clear
ThisDrawing.Utility.Prompt " 没有指定零件,退出"
Exit Sub
End If
PPck2 = ThisDrawing.Utility.GetPoint(, "请指定编号位置:")
If Err <> 0 Then
Err.Clear
ThisDrawing.Utility.Prompt " 没有指定编号位置,退出"
Exit Sub
End If
Set line1 = ThisDrawing.ModelSpace.AddLine(PPck1, PPck2)
TextHeight = ThisDrawing.GetVariable("dimtxt") '沿用系统文字高度
ppt(0) = PPck2(0) + 0.7 * TextHeight: ppt(1) = PPck2(1) - 0.5 * TextHeight: ppt(2) = PPck2(2)
Set Cirobj = ThisDrawing.ModelSpace.AddCircle(PPck2, TextHeight)
PPck2 = Cirobj.IntersectWith(line1, acExtendNone) '求交点
line1.EndPoint = PPck2 '剪切引线

Numbers1 = ThisDrawing.Utility.GetString(0, vbCrLf & "请输入编号数字(上一编号为" & Nums - 1 & ")" & "[" & Nums & "]:")
If Numbers1 = "" Then Numbers1 = Nums
If Len(Numbers1) = 2 Then
Inserpt(0) = ppt(0) - 1.4 * TextHeight: Inserpt(1) = ppt(1) + 0.01 * TextHeight: Inserpt(2) = ppt(2)
End If
If Len(Numbers1) = 1 Then
Inserpt(0) = ppt(0) - TextHeight: Inserpt(1) = ppt(1) + 0.01 * TextHeight: Inserpt(2) = ppt(2)
End If

Set textobject(0) = ThisDrawing.ModelSpace.AddText(Numbers1, Inserpt, TextHeight)

Nums = Numbers1 '使提示与上一编号关联
Nums = Nums + 1
GoTo RETRY
End Sub
Function pd(p1 As Variant, p2 As Variant) As Boolean '判断斜率,以便确定文字位置
If p1(0) > p2(0) And p1(0) > p2(0) Then
pd = True
Else
pd = False
End If
End Function

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x

评分

参与人数 1金钱 +20 收起 理由
mccad + 20 【好评】好程序

查看全部评分

发表于 2024-4-12 15:19:23 | 显示全部楼层
希望楼主经常没事,多多写写这种好程序
回复 支持 1 反对 0

使用道具 举报

发表于 2024-4-12 16:09:48 | 显示全部楼层
这是用的VBA不是LISP,只能大体看懂
发表于 2004-5-11 19:07:00 | 显示全部楼层
  1. PPck2 = ThisDrawing.Utility.GetPoint(, "请指定编号位置:")
复制代码
这里改成
  1. PPck2 = ThisDrawing.Utility.GetPoint(PPck1, "请指定编号位置:")
复制代码
要好些吧
发表于 2004-5-11 19:23:00 | 显示全部楼层
精神可嘉!我虽然用不着,相信对用得上的人是很实用的。
发表于 2004-5-11 21:34:00 | 显示全部楼层
楼上说的有道理,支持
发表于 2004-5-11 21:41:00 | 显示全部楼层
最好能把画好的内容编成组合,这样方便选择。
 楼主| 发表于 2004-5-11 21:48:00 | 显示全部楼层
各位的意见已收到!改进后再贴上来!
 楼主| 发表于 2004-5-12 12:52:00 | 显示全部楼层
加了一点对文字定位的内容,群组了编号内容。
  1. 'by gzy
  2. 'gzy@mjtd.com
  3. 'scutaDim Nums As Integer
  4. Sub Numbers()
  5. Nums = 1
  6. Dim keyWord As String
  7.        ThisDrawing.Utility.InitializeUserInput 0, "y n"
  8.        keyWord = ThisDrawing.Utility.GetKeyword(vbCrLf & "编号是否带圈[否(N)/是(Y)][N]: ")
  9.       
  10.        If keyWord = "" Then
  11.            keyWord = "N"
  12.            Call Ncircle
  13.        Else
  14.            Call Cir
  15.        End If
  16.       
  17.        If keyWord = "N" Then Call Ncircle
  18. End SubSub Ncircle()
  19. RETRY:
  20.        Dim PPck1 As Variant, PPck2 As Variant
  21.        Dim textobject(0) As AcadObject: Dim line1 As AcadLine: Dim line2 As AcadLine
  22.        Dim ppt(0 To 2) As Double:   Dim Numbers1 As String: Dim Inserpt(0 To 2) As Double
  23.       
  24.          On Error Resume Next
  25.        '   ThisDrawing.GetVariable ("osnap")
  26.          PPck1 = ThisDrawing.Utility.GetPoint(, "请指定零件:")
  27.                  If Err <> 0 Then
  28.                                Err.Clear
  29.                                ThisDrawing.Utility.Prompt " 没有指定零件,退出"
  30.                                Exit Sub
  31.                    End If
  32.          PPck2 = ThisDrawing.Utility.GetPoint(, "请指定编号位置:")
  33.                If Err <> 0 Then
  34.                                Err.Clear
  35.                                ThisDrawing.Utility.Prompt " 没有指定编号位置,退出"
  36.                                Exit Sub
  37.                    End If
  38.    Set line1 = ThisDrawing.ModelSpace.AddLine(PPck1, PPck2)
  39.    TextHeight = ThisDrawing.GetVariable("dimtxt") '沿用系统文字高度
  40.    
  41.    If pd(PPck1, PPck2) = True Then
  42.              ppt(0) = PPck2(0) - 2 * TextHeight:     ppt(1) = PPck2(1):       ppt(2) = PPck2(2)
  43.    Else
  44.              ppt(0) = PPck2(0) + 2 * TextHeight:     ppt(1) = PPck2(1):       ppt(2) = PPck2(2)
  45.    End If
  46.    
  47.    Set line2 = ThisDrawing.ModelSpace.AddLine(PPck2, ppt)
  48.    line2.Lineweight = acLnWt030
  49.    ThisDrawing.SendCommand "_LWDISPLAY" & vbCr & "on" & vbCr     '显示线宽
  50.            
  51.    Numbers1 = ThisDrawing.Utility.GetString(0, vbCrLf & "请输入编号数字(上一编号为" & Nums - 1 & ")" & "[" & Nums & "]:")
  52.    If Numbers1 = "" Then Numbers1 = Nums
  53.    If pd(PPck1, PPck2) = True Then
  54.        If Len(Numbers1) = 1 Then
  55.            Inserpt(0) = ppt(0) + 0.6 * TextHeight: Inserpt(1) = ppt(1) + 0.2 * TextHeight: Inserpt(2) = ppt(2)
  56.        Else
  57.            Inserpt(0) = ppt(0) + 0.1 * TextHeight: Inserpt(1) = ppt(1) + 0.2 * TextHeight: Inserpt(2) = ppt(2)
  58.        End If
  59.    Else
  60.          If Len(Numbers1) = 1 Then
  61.            Inserpt(0) = ppt(0) - 1.2 * TextHeight: Inserpt(1) = ppt(1) + 0.2 * TextHeight: Inserpt(2) = ppt(2)
  62.          Else
  63.              Inserpt(0) = ppt(0) - 1.8 * TextHeight: Inserpt(1) = ppt(1) + 0.2 * TextHeight: Inserpt(2) = ppt(2)
  64.          End If
  65.    End If
  66.          Set textobject(0) = ThisDrawing.ModelSpace.AddText(Numbers1, Inserpt, TextHeight)
  67.        Nums = Numbers1 '使提示与上一编号关联
  68.        Nums = Nums + 1
  69. Dim Group1 As AcadGroup
  70. Dim objgroup(0 To 2) As AcadEntity
  71. Set objgroup(0) = line1
  72. Set objgroup(1) = line2
  73. Set objgroup(2) = textobject(0)
  74.   Set Group1 = ThisDrawing.Groups.Add("*")
  75.   Group1.AppendItems objgroupGoTo RETRY
  76. End SubSub Cir()
  77. RETRY:
  78.        Dim PPck1 As Variant, PPck2 As Variant
  79.        Dim textobject(0) As AcadObject: Dim line1 As AcadLine: Dim Cirobj As AcadCircle
  80.        Dim ppt(0 To 2) As Double:   Dim Numbers1 As String: Dim Inserpt(0 To 2) As Double
  81.       
  82.          On Error Resume Next
  83.          PPck1 = ThisDrawing.Utility.GetPoint(, "请指定零件:")
  84.                  If Err <> 0 Then
  85.                                Err.Clear
  86.                                ThisDrawing.Utility.Prompt " 没有指定零件,退出"
  87.                                Exit Sub
  88.                    End If
  89.          PPck2 = ThisDrawing.Utility.GetPoint(, "请指定编号位置:")
  90.                If Err <> 0 Then
  91.                                Err.Clear
  92.                                ThisDrawing.Utility.Prompt " 没有指定编号位置,退出"
  93.                                Exit Sub
  94.                    End If
  95.    Set line1 = ThisDrawing.ModelSpace.AddLine(PPck1, PPck2)
  96.    TextHeight = ThisDrawing.GetVariable("dimtxt") '沿用系统文字高度
  97.    ppt(0) = PPck2(0) + 0.7 * TextHeight: ppt(1) = PPck2(1) - 0.5 * TextHeight: ppt(2) = PPck2(2)
  98.    Set Cirobj = ThisDrawing.ModelSpace.AddCircle(PPck2, 1.2 * TextHeight)
  99.        PPck2 = Cirobj.IntersectWith(line1, acExtendNone) '求交点
  100.        line1.EndPoint = PPck2     '剪切引线
  101.            
  102.        Numbers1 = ThisDrawing.Utility.GetString(0, vbCrLf & "限于输入二位数字" & vbCrLf & "请输入编号数字(上一编号为" & Nums - 1 & ")" & "[" & Nums & "]:")
  103.        If Numbers1 = "" Then Numbers1 = Nums
  104.        If Len(Numbers1) = 2 Then
  105.            Inserpt(0) = ppt(0) - 1.5 * TextHeight: Inserpt(1) = ppt(1) + 0.01 * TextHeight: Inserpt(2) = ppt(2)
  106.        End If
  107.        If Len(Numbers1) = 1 Then
  108.          Inserpt(0) = ppt(0) - TextHeight: Inserpt(1) = ppt(1) + 0.01 * TextHeight: Inserpt(2) = ppt(2)
  109.        End If
  110.       
  111.        Set textobject(0) = ThisDrawing.ModelSpace.AddText(Numbers1, Inserpt, TextHeight)
  112.       
  113.        Nums = Numbers1 '使提示与上一编号关联
  114.        Nums = Nums + 1
  115. Dim Group2 As AcadGroup
  116. Dim objgroup(0 To 2) As AcadEntity
  117. Set objgroup(0) = line1
  118. Set objgroup(1) = Cirobj
  119. Set objgroup(2) = textobject(0)
  120.   Set Group1 = ThisDrawing.Groups.Add("*")
  121.   Group1.AppendItems objgroupGoTo RETRY
  122. End Sub
  123. Function pd(p1 As Variant, p2 As Variant) As Boolean '判断斜率,以便确定文字位置
  124.        If p1(0) > p2(0) Then
  125.            pd = True
  126.        Else
  127.            pd = False
  128.        End If
  129. End Function
发表于 2004-5-18 23:53:00 | 显示全部楼层
不错,挺实用的!
发表于 2004-5-21 15:11:00 | 显示全部楼层
我用的编号:



下带横线的,可加前后缀--如给水立管JL-1B         JL-2B ...;横线不加粗





多数不要引线但可加前后缀--如井号JL-1a         JL-2a ...
发表于 2004-6-3 15:59:00 | 显示全部楼层
我觉得你的发明很好,我画图时用的上,但是我是一个菜鸟,能否将你的发明发一个给我,并告诉我,最笨的安装方法!谢谢了!我的E :woshiyu1217@126.com
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-25 04:53 , Processed in 0.172067 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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