| Dim acadUtil as Object Dim stPnt, enPnt As Variant Dim prompt1, prompt2 As String Set acadUtil=acaddoc.Utility '设置Utility对象 prompt1 = "起始点: " ‘代替From Point prompt2 = "终止点: " '代替End Point stPnt = acadUtil.GetPoint(, prompt1) enPnt = acadUtil.GetPoint(stPnt, prompt2) '获得用户输入(既可输入坐标值,也可直接在屏幕上选点) Dim startPoint(0 To 2) As Double Dim endPoint(0 To 2) As Double startPoint(0) = stPnt(0) startPoint(1) = stPnt(1) startPoint(2) = stPnt(2) endPoint(0) = enPnt(0) endPoint(1) = enPnt(1) endPoint(2) = enPnt(2) moSpace.AddLine startPoint, endPoint '利用用户输入生成直线 把系统变量设置SetVariable与Utility对象的GetString方法结合,即可向AutoCad的状态行写入内容: Dim yourname as String yourname = acadUtil.GetString(0, " 请输入您的姓名: ") acaddoc.SetVariable "MODEMACRO", yourname & ", 你好!" |
| Dim tlayer as Object For Each tlayer In acaddoc.Layers If tlayer.Name = "wall" Then tlayer.Freeze = acTrue Else If tlayer.Name="beam" Then tlayer.LayerOn = acTrue Set acaddoc.ActiveLayer = tlayer End If Next |
| Public Sub changeview(ByVal x, ByVal y, ByVal z) Dim newDirection(0 To 2) As Double Dim vport As Object acaddoc.ActiveSpace = acModelSpace ‘使ModelSpace成为活动 空间 Set vport = acaddoc.Viewports.Add("newview") ‘建立新视图 newDirection(0) = x newDirection(1) = y newDirection(2) = z ‘视图的视角方向 vport.Direction = newDirection acaddoc.ActiveViewport = vport ‘把新视图激活 acaddoc.ActiveViewport.ZoomAll ‘全图显示 End Sub |
| Dim tempset as Object Dim obj as Object Set tempset = acaddoc.SelectionSets.Add("newset") '建立新选择集 tempset.SelectOnScreen ‘用户在屏幕上选择 For Each obj In tempset ‘遍历选择集中的实体 If obj.EntityName="AcDbLine" And obj.Layer="wall" Then obj.HighLight(True) '亮显实体 End IF Next |
| Dim actualCode(3) As String Dim actualValue(3) As String Dim groupcode As Variant Dim groupValue As Variant Dim extminpt(2) As Double Dim extmaxpt(2) As Double Dim tsset As Object Dim tobj As Object actualCode(0) = -4 actualValue(0) = " actualCode(1) = 8 '保证 Layer是"wall" actualValue(1) = "wall" actualCode(2) = 100 actualValue(2) = "AcDbLine" '所选实体为直线 actualCode(3) = -4 actualValue(3) = "AND>" extminpt(0) = 0 extminpt(1) = 0 extminpt(2) = 0 extmaxpt(0) = 800 extmaxpt(1) = 400 extmaxpt(2) = 0 ‘设选择集涉及区域的左上点与右下点坐标 groupcode = actualCode groupValue = actualValue Set tsset = acaddoc.SelectionSets.Add("SS2") tsset.Select acSelectionSetAll, extminpt, extmaxpt, groupcode,_ groupValue ‘加了过滤器的选择集 For Each tobj In tsset tobj.HighLight(True) 'tobj一定满足既是直线,又在层"wall"上 Nexe |
| SendKeys "{esc}", True SendKeys "{esc}", True ‘避免以前命令的干扰 SendKeys "_break" & "{enter}", True SendKeys "{(}" & "handent" & """" & wallhandle & """" & "{)}" & "{enter}", True ‘选择要断开的实体(wallhandle为其句柄) SendKeys Format(cood1(0)) & "," & Format(cood1(1)) & "{enter}", True SendKeys Format(cood2(0)) & "," & Format(cood2(1)) & "{enter}", True ‘cood1与cood2是实体上断开点的坐标 |