Sub sk_jl() '根据两点及比较在图纸空间新建视口 Dim returnObj As AcadObject Dim vv As AcadPViewport Dim basePnt1 As Variant Dim basePnt2 As Variant Dim leftlow(0 To 2) As Double Dim righttow(0 To 2) As Double Dim bl As Double Dim kd As Double Dim gd As Double Dim jd As Double UserForm3.Show gd = 250 bl = UserForm3.TextBox1.Value '比例 Dim returnPnt As Variant 'On Error Resume Next ThisDrawing.ActiveSpace = acModelSpace basePnt1 = ThisDrawing.Utility.GetPoint(, "Enter a point: ") basePnt2 = ThisDrawing.Utility.GetPoint(, "Enter a Next point: ") jd = fwj(basePnt2(0) - basePnt1(0), basePnt2(1) - basePnt1(1)) '计算角度 kd = ((basePnt2(0) - basePnt1(0)) ^ 2 + (basePnt2(1) - basePnt1(1)) ^ 2) ^ 0.5 * bl leftlow(0) = basePnt1(0) + gd / 2 * bl * Cos(jd - 3.1415926 / 2) leftlow(1) = basePnt1(1) + gd / 2 * bl * Sin(jd - 3.1415926 / 2) righttow(0) = basePnt2(0) + gd / 2 * bl * Cos(jd + 3.1415926 / 2) righttow(1) = basePnt2(1) + gd / 2 * bl * Sin(jd + 3.1415926 / 2) ' ThisDrawing.ModelSpace.AddLine leftlow, righttow Dim pviewportObj As AcadPViewport Dim center(0 To 2) As Double center(0) = 200: center(1) = 200: center(2) = 0 ThisDrawing.ActiveSpace = acPaperSpace Set pviewportObj = ThisDrawing.PaperSpace.AddPViewport(center, kd, gd) pviewportObj.Display True pviewportObj.twistAngle = 2 * 3.1415926 - jd '旋转角度 ThisDrawing.MSpace = True ThisDrawing.Application.ZoomWindow leftlow, righttow ThisDrawing.MSpace = False ThisDrawing.Regen acAllViewports End Sub 学了半天时间才搞的程序。 |