实例介绍
【实例截图】

【核心代码】
VERSION 5.00 Begin VB.Form Form1 Caption = "楼梯断面图" ClientHeight = 3240 ClientLeft = 5685 ClientTop = 4185 ClientWidth = 3720 LinkTopic = "Form1" ScaleHeight = 3240 ScaleWidth = 3720 Begin VB.CommandButton cmdExit Caption = "退出(&X)" Height = 375 Left = 2400 TabIndex = 23 Top = 2760 Width = 1215 End Begin VB.CommandButton cmdDraw Caption = "绘图(&D)" Height = 375 Left = 2400 TabIndex = 22 Top = 2280 Width = 1215 End Begin VB.CommandButton cmdCal Caption = "计算(&C)" Height = 375 Left = 2400 TabIndex = 21 Top = 1800 Width = 1215 End Begin VB.Frame Frame3 Caption = "楼梯梁参数" Height = 1455 Left = 120 TabIndex = 14 Top = 1680 Width = 2055 Begin VB.TextBox txtGirderW Height = 285 Left = 1060 TabIndex = 17 Top = 330 Width = 855 End Begin VB.TextBox txtGirderH Height = 285 Left = 1060 TabIndex = 16 Top = 690 Width = 855 End Begin VB.TextBox txtBoardT Height = 285 Left = 1060 TabIndex = 15 Top = 1050 Width = 855 End Begin VB.Label Label9 Caption = "楼梯梁宽" Height = 255 Left = 240 TabIndex = 20 Top = 360 Width = 855 End Begin VB.Label Label8 Caption = "楼梯梁高" Height = 255 Left = 240 TabIndex = 19 Top = 720 Width = 855 End Begin VB.Label Label7 Caption = "楼板厚" Height = 255 Left = 240 TabIndex = 18 Top = 1080 Width = 855 End End Begin VB.Frame Frame2 Caption = "踏步参数" Height = 1455 Left = 1680 TabIndex = 7 Top = 120 Width = 1900 Begin VB.TextBox txtStepH Height = 285 Left = 900 TabIndex = 10 Top = 330 Width = 855 End Begin VB.TextBox txtStepW Height = 285 Left = 900 TabIndex = 9 Top = 690 Width = 855 End Begin VB.TextBox txtStepNum Height = 285 Left = 900 TabIndex = 8 Top = 1050 Width = 855 End Begin VB.Label Label6 Caption = "踏步高" Height = 255 Left = 240 TabIndex = 13 Top = 360 Width = 855 End Begin VB.Label Label5 Caption = "踏步宽" Height = 255 Left = 240 TabIndex = 12 Top = 720 Width = 855 End Begin VB.Label Label4 Caption = "级数" Height = 255 Left = 240 TabIndex = 11 Top = 1080 Width = 855 End End Begin VB.Frame Frame1 Caption = "基点" Height = 1455 Left = 120 TabIndex = 0 Top = 120 Width = 1455 Begin VB.TextBox txtPtZ Height = 285 Left = 480 TabIndex = 6 Top = 1050 Width = 855 End Begin VB.TextBox txtPtY Height = 285 Left = 480 TabIndex = 4 Top = 690 Width = 855 End Begin VB.TextBox txtPtX Height = 285 Left = 480 TabIndex = 2 Top = 330 Width = 855 End Begin VB.Label Label3 Caption = "Z:" Height = 255 Left = 240 TabIndex = 5 Top = 1080 Width = 255 End Begin VB.Label Label2 Caption = "Y:" Height = 255 Left = 240 TabIndex = 3 Top = 720 Width = 255 End Begin VB.Label Label1 Caption = "X:" Height = 255 Left = 240 TabIndex = 1 Top = 360 Width = 255 End End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Dim bCal As Boolean '是否已经进行计算 '存储楼梯上层各点的坐标 Dim ptArr1() As Double '楼梯下侧各点的坐标 Dim ptArr2(19) As Double Private Sub cmdCal_Click() '判断是否缺少参数 Dim objControl As Control For Each objControl In Form1.Controls If TypeOf objControl Is TextBox Then If objControl.Text = "" Then MsgBox "缺少参数,无法计算!", vbCritical Exit Sub End If End If Next '获得计算所需参数值 Dim x0 As Double, y0 As Double '定位基点 Dim s As Double, t As Double, n As Double '踏步的高、宽和级数 Dim b As Double, h As Double, h0 As Double '楼梯梁的宽、高和楼板厚 x0 = txtPtX.Text: y0 = txtPtY.Text s = txtStepH.Text: t = txtStepW.Text: n = txtStepNum.Text b = txtGirderW.Text: h = txtGirderH.Text: h0 = txtBoardT.Text '约束条件 If h0 >= h Or b > 80 Or s >= t Then MsgBox "输入条件不合要求,请检查参数的合理性!", vbCritical Exit Sub End If ReDim ptArr1(2 * (2 * n 2) - 1) '计算上半部各点的坐标 ptArr1(0) = x0 - 100: ptArr1(1) = y0 ptArr1(2) = x0: ptArr1(3) = y0 ptArr1(4) = x0: ptArr1(5) = y0 s Dim i As Integer For i = 6 To 2 * (2 * n 2) - 3 If i Mod 4 = 2 Then ptArr1(i) = ptArr1(i - 4) t ElseIf i Mod 4 = 3 Then ptArr1(i) = ptArr1(i - 4) s ElseIf i Mod 4 = 0 Then ptArr1(i) = ptArr1(i - 2) ElseIf i Mod 4 = 1 Then ptArr1(i) = ptArr1(i - 2) s End If Next i ptArr1(2 * (2 * n 2) - 2) = ptArr1(2 * (2 * n 2) - 4) 100 ptArr1(2 * (2 * n 2) - 1) = ptArr1(2 * (2 * n 2) - 3) '计算下半部各点的坐标 ptArr2(0) = x0 - 100: ptArr2(1) = y0 - h0 ptArr2(2) = x0 - b: ptArr2(3) = y0 - h0 ptArr2(4) = x0 - b: ptArr2(5) = y0 - h ptArr2(6) = x0: ptArr2(7) = y0 - h ptArr2(8) = x0: ptArr2(9) = y0 - h0 ptArr2(10) = x0 (n - 1) * t: ptArr2(11) = y0 (n - 1) * s - h0 ptArr2(12) = ptArr1(2 * (2 * n 2) - 4): ptArr2(13) = ptArr1(2 * (2 * n 2) - 3) - h ptArr2(14) = ptArr2(12) b: ptArr2(15) = ptArr2(13) ptArr2(16) = ptArr2(14): ptArr2(17) = ptArr2(15) (h - h0) ptArr2(18) = ptArr1(2 * (2 * n 2) - 2): ptArr2(19) = ptArr1(2 * (2 * n 2) - 1) - h0 '已经计算 bCal = True End Sub Private Sub cmdDraw_Click() '判断是否计算 If bCal = False Then MsgBox "请先进行计算,再进行绘图!", vbCritical Exit Sub End If On Error Resume Next ' 连接至 AutoCAD 应用程序 Dim acadApp As AcadApplication Set acadApp = GetObject(, "AutoCAD.Application.16") If Err Then Err.Clear Set acadApp = CreateObject("AutoCAD.Application.16") If Err Then MsgBox Err.Description Exit Sub End If End If ' 连接至 AutoCAD 图形 Dim acadDoc As AcadDocument Set acadDoc = acadApp.ActiveDocument acadDoc.ModelSpace.AddLightWeightPolyline ptArr1 acadDoc.ModelSpace.AddLightWeightPolyline ptArr2 ZoomAll acadApp.Visible = True '绘图完成,要求下一次计算 bCal = False End Sub Private Sub cmdExit_Click() End End Sub Private Sub Form_Load() '默认参数值 txtPtX.Text = 0 txtPtY.Text = 0 txtPtZ.Text = 0 txtStepH.Text = 20 txtStepW.Text = 40 txtStepNum.Text = 10 txtGirderW.Text = 25 txtGirderH.Text = 45 txtBoardT.Text = 15 bCal = False End Sub
标签: AutoCAD
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论