ImageVerifierCode 换一换
格式:DOCX , 页数:14 ,大小:708.72KB ,
资源ID:2994973      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/2994973.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(VBA二次开发.docx)为本站会员(b****4)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

VBA二次开发.docx

1、VBA二次开发The Report of Parametric DesignName: Student No.: Expecting Score: 901. The Object of Design:My design is a program , which is writed by VBA,to drawing a screw bolt .In my design,users can creat a screw bolt just by typing the parameters of the bolt.So ,I design a form,which display the param

2、eters the user should typing in.and then ,users can specify a point as the first point P0,then click “OK ”; a screw bolt is ceated.2. The original picture:The parameters of the screw bolt is like the picture as follow:3. Program: Firstly ,designing the form: Secondly,designing functions of the form

3、above-mentioned:Dim PX As Double 定义存储点的变量 Dim PY As Double Dim P2 As Variant Sub CommandButton1_Click() 将控制权交给AutoCAD UserForm1.Hide 获取点的位置 P2 = ThisDrawing.Utility.GetPoint(, 指定点:) PX = P2(0) PY = P2(1) TextBox13 = P2(0) TextBox14 = P2(1) 返回对话框 UserForm1.ShowEnd SubPrivate Sub quxiao_Click()ZoomExt

4、entsEndEnd SubSub yes_Click() 定义所需要的变量 Dim dk As Double Dim n As Double Dim k As Double Dim t As Double Dim L As Double Dim L1 As Double Dim d As Double Dim plineObj(0 To 9, 0 To 2) As AcadLine 定义一个二维数组,存储所画的直线 Dim i As Integer 定义循环控制变量 Dim j As Integer Dim P0(0 To 2) As Double Dim P1(0 To 2) As Dou

5、ble 初始化 dk = TextBox1 n = TextBox2 k = TextBox12 t = TextBox9 L = TextBox8 L1 = TextBox11 d = TextBox10 P0(0) = PX P0(1) = PY P1(0) = PXP1(1) = PY 开始计算绘图 画中心线 On Error Resume Next ThisDrawing.Linetypes.Load CENTER, acad.lin ThisDrawing.ActiveLinetype = ThisDrawing.Linetypes.Item(CENTER) Set plineObj

6、(0, 0) = AddLineReXY(P0, 1.3 * L, 0) Set plineObj(0, 1) = AddLineReXY(P0, -0.2 * L, 0) (1) On Error Resume Next ThisDrawing.Linetypes.Load CONTINUOUS, acad.lin ThisDrawing.ActiveLinetype = ThisDrawing.Linetypes.Item(CONTINUOUS) Set plineObj(1, 0) = AddLineReXY(P0, 0, n / 2) Set plineObj(1, 1) = AddL

7、ineReXY(P1, 0, -n / 2) P0(1) = P0(1) + n / 2 P1(1) = P1(1) - n / 2 (2) Set plineObj(2, 0) = AddLineReXY(P0, -k, 0) P0(0) = P0(0) - k Set plineObj(2, 1) = AddLineReXY(P1, -k, 0) P1(0) = P1(0) - k (3) Set plineObj(3, 0) = AddLineReXY(P0, 0, (dk / 2 - n / 2) P0(1) = P0(1) + (dk / 2 - n / 2) Set plineOb

8、j(3, 1) = AddLineReXY(P1, 0, -(dk / 2 - n / 2) P1(1) = P1(1) - (dk / 2 - n / 2) (4) Set plineObj(4, 0) = AddLineReXY(P0, t, 0) P0(0) = P0(0) + t Set plineObj(4, 1) = AddLineReXY(P1, t, 0) P1(0) = P1(0) + t (5) Set plineObj(5, 0) = AddLineReXY(P0, 0, -dk / 2) P0(1) = P0(1) + (d / 2 - dk / 2) Set plin

9、eObj(5, 1) = AddLineReXY(P1, 0, dk / 2) P1(1) = P1(1) - (d / 2 - dk / 2) (6) Set plineObj(6, 0) = AddLineReXY(P0, L, 0) P0(0) = P0(0) + L Set plineObj(6, 1) = AddLineReXY(P1, L, 0) P1(0) = P1(0) + L (7) Set plineObj(7, 0) = AddLineReXY(P0, 0, -d / 2) P0(1) = P0(1) - d / 2 P0(0) = P0(0) - L1 Set plin

10、eObj(7, 1) = AddLineReXY(P1, 0, d / 2) P1(1) = P1(1) + d / 2 P1(0) = P1(0) - L1 (8) Set plineObj(8, 0) = AddLineReXY(P0, 0, d / 2) P0(1) = P0(1) + d / 2 - 1 Set plineObj(8, 1) = AddLineReXY(P0, L1, 0) Set plineObj(9, 0) = AddLineReXY(P1, 0, -d / 2) P1(1) = P1(1) - d / 2 + 1 Set plineObj(9, 1) = AddL

11、ineReXY(P1, L1, 0) plineObj(0, 0).Lineweight = acLnWt009 plineObj(0, 1).Lineweight = acLnWt009 plineObj(0, 0).ScaleEntity P2, suofang plineObj(0, 0).Update plineObj(0, 1).ScaleEntity P2, suofang plineObj(0, 1).Update plineObj(0, 1).color = zs 指定中心线的颜色 zs 代表中心线颜色 plineObj(0, 0).color = zs 指定中心线的颜色 Fo

12、r i = 1 To 10 Step 1 循环对螺钉直线进行操作,两层循环 For j = 0 To 1 Step 1 plineObj(i, j).Lineweight = acLnWt030 指定螺钉线宽 plineObj(i, j).color = ls 指定螺钉线的颜色 ls代表螺钉线颜色 plineObj(i, j).ScaleEntity P2, suofang 指定螺钉缩放比例 plineObj(i, j).Update Next j Next i ZoomExtentsEnd Sub Finally,designing a module ,this module contain

13、s required function.Option ExplicitPublic Sub Alternation() 创建显示窗口和隐藏窗口的函数 UserForm1.Hind UserForm1.ShowEnd Sub创建直线的基准函数Public Function AddLine(ByVal ptSt As Variant, ByVal ptEn As Variant) As AcadLine Set AddLine = ThisDrawing.ModelSpace.AddLine(ptSt, ptEn)End Function根据另一点的相对直角坐标创建直线Public Functio

14、n AddLineReXY(ByVal ptSt As Variant, ByVal x As Double, ByVal y As Double) As AcadLine 定义终点 Dim ptEn As Variant ptEn = GetPoint(ptSt, x, y) Set AddLineReXY = AddLine(ptSt, ptEn)End Function获得相对已经点偏移一定距离的点Public Function GetPoint(pt As Variant, x As Double, y As Double) As Variant Dim ptTarget(0 To 2

15、) As Double ptTarget(0) = pt(0) + x ptTarget(1) = pt(1) + y ptTarget(2) = 0 GetPoint = ptTargetEnd Function4. Running results: Load the project Run this project,typing the Parameters of the bolt as follow Pick a point as the first point Click 确定 Click 取消 退出程序 Different typings lead to different result

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1