AutoCAD CAD 二次开发 CAD VBA开发。

 我来答
快乐小朱家
2011-08-05 · TA获得超过1013个赞
知道小有建树答主
回答量:649
采纳率:40%
帮助的人:381万
展开全部
Dim BlockNameSt As String

Sub DimDimaligned()
On Error GoTo Err
Dim Po(0 To 2) As Double
Dim Pr(0 To 2) As Double
Dim Var As Variant
Dim DimDimalign As AcadDimRotated
Dim BlokName As String
Dim Ang As Double
Dim LDob As Double
Dim XDob As Double
Dim PtH As String

Var = ThisDrawing.Utility.GetPoint(, vbCr & "指定第一条尺寸界线原点:")
Po(0) = Var(0): Po(1) = Var(1): Po(2) = Var(2)

Var = ThisDrawing.Utility.GetPoint(Po, vbCr & "指定第二条尺寸界线原点:")
Pr(0) = Var(0): Pr(1) = Var(1): Pr(2) = Var(2)

XDob = Pr(0) - Po(0)
LDob = Sqr(((Pr(0) - Po(0)) * (Pr(0) - Po(0))) + ((Pr(1) - Po(1)) * (Pr(1) - Po(1))))
Ang = XDob / LDob

If Pr(1) > Po(1) Then
Ang = Atn(-Ang / Sqr(-Ang * Ang + 1)) + 2 * Atn(1)
End If
If Pr(1) < Po(1) Then
Ang = -Atn(-Ang / Sqr(-Ang * Ang + 1)) + 2 * Atn(1) - 180 * 3.1415926 / 180
End If
If Pr(1) = Po(1) And Pr(0) < Po(0) Then
Ang = 180 * 3.1415926 / 180
End If
If Pr(1) = Po(1) And Pr(0) > Po(0) Then
Ang = 0
End If
Set DimDimalign = ThisDrawing.ModelSpace.AddDimRotated(Po, Pr, Pr, Ang)
Err:

End Sub

Sub Linkblok()
On Error GoTo Err
Dim Po(0 To 2) As Double
Dim Pr(0 To 2) As Double
Dim Var As Variant
Dim BlokIn As AcadBlockReference
Dim BlokName As String
Dim Ang As Double
Dim LDob As Double
Dim XDob As Double
Dim PtH As String

Dim UcsObj As AcadUCS
Dim Origin(0 To 2) As Double
Dim XAxisPo(0 To 2) As Double
Dim YAxisPo(0 To 2) As Double

Origin(0) = 0#: Origin(1) = 0#: Origin(2) = 0#
XAxisPo(0) = 3: XAxisPo(1) = 0: XAxisPo(2) = 0
YAxisPo(0) = 0: YAxisPo(1) = 3: YAxisPo(2) = 0
Set UcsObj = ThisDrawing.UserCoordinateSystems.Add(Origin, XAxisPo, YAxisPo, "WUCS")
ThisDrawing.ActiveUCS = UcsObj

BlokName = ThisDrawing.Utility.GetString(False, vbCr & "输入的块名<" + BlockNameSt + ">: ")

If BlokName = "" Then BlokName = BlockNameSt

PtH = "D:\CAD块\" + BlokName + ".dwg"

If Dir(PtH) <> "" Then
BlockNameSt = BlokName

Do

Var = ThisDrawing.Utility.GetPoint(, vbCr & "选取图块放置点:")
Po(0) = Var(0): Po(1) = Var(1): Po(2) = Var(2)
Set BlokIn = ThisDrawing.ModelSpace.InsertBlock(Po, PtH, 1, 1, 1, 0)

Var = ThisDrawing.Utility.GetPoint(Po, vbCr & "指定图块方向:")
Pr(0) = Var(0): Pr(1) = Var(1): Pr(2) = Var(2)
XDob = Pr(0) - Po(0)
LDob = Sqr(((Pr(0) - Po(0)) * (Pr(0) - Po(0))) + ((Pr(1) - Po(1)) * (Pr(1) - Po(1))))
Ang = XDob / LDob

If Pr(1) > Po(1) Then
Ang = Atn(-Ang / Sqr(-Ang * Ang + 1)) + 2 * Atn(1)
End If
If Pr(1) < Po(1) Then
Ang = -Atn(-Ang / Sqr(-Ang * Ang + 1)) + 2 * Atn(1) - 180 * 3.1415926 / 180
End If
If Pr(1) = Po(1) And Pr(0) < Po(0) Then
Ang = 180 * 3.1415926 / 180
End If
If Pr(1) = Po(1) And Pr(0) > Po(0) Then
Ang = 0
End If

BlokIn.Rotate Po, Ang

Loop

Else
ThisDrawing.Utility.Prompt vbCr & PtH + "的文件路径不存在!"
End If

Err:

End Sub

Sub LinkblokR0()
On Error GoTo Err
Dim Po(0 To 2) As Double
Dim Pr(0 To 2) As Double
Dim Var As Variant
Dim BlokIn As AcadBlockReference
Dim BlokName As String
Dim Ang As Double
Dim LDob As Double
Dim XDob As Double
Dim PtH As String

Dim UcsObj As AcadUCS
Dim Origin(0 To 2) As Double
Dim XAxisPo(0 To 2) As Double
Dim YAxisPo(0 To 2) As Double

Origin(0) = 0#: Origin(1) = 0#: Origin(2) = 0#
XAxisPo(0) = 3: XAxisPo(1) = 0: XAxisPo(2) = 0
YAxisPo(0) = 0: YAxisPo(1) = 3: YAxisPo(2) = 0
Set UcsObj = ThisDrawing.UserCoordinateSystems.Add(Origin, XAxisPo, YAxisPo, "WUCS")
ThisDrawing.ActiveUCS = UcsObj

BlokName = ThisDrawing.Utility.GetString(False, vbCr & "输入的块名<" + BlockNameSt + ">: ")

If BlokName = "" Then BlokName = BlockNameSt

PtH = "D:\CAD块\" + BlokName + ".dwg"

If Dir(PtH) <> "" Then
BlockNameSt = BlokName

Do

Var = ThisDrawing.Utility.GetPoint(, vbCr & "选取图块放置点:")
Po(0) = Var(0): Po(1) = Var(1): Po(2) = Var(2)
Set BlokIn = ThisDrawing.ModelSpace.InsertBlock(Po, PtH, 1, 1, 1, 0)

'Var = ThisDrawing.Utility.GetPoint(Po, vbCr & "指定图块方向:")
'Pr(0) = Var(0): Pr(1) = Var(1): Pr(2) = Var(2)
Pr(0) = 0#: Pr(1) = 0#: Pr(2) = 0#
XDob = Pr(0) - Po(0)
LDob = Sqr(((Pr(0) - Po(0)) * (Pr(0) - Po(0))) + ((Pr(1) - Po(1)) * (Pr(1) - Po(1))))
Ang = XDob / LDob

If Pr(1) > Po(1) Then
Ang = Atn(-Ang / Sqr(-Ang * Ang + 1)) + 2 * Atn(1)
End If
If Pr(1) < Po(1) Then
Ang = -Atn(-Ang / Sqr(-Ang * Ang + 1)) + 2 * Atn(1) - 180 * 3.1415926 / 180
End If
If Pr(1) = Po(1) And Pr(0) < Po(0) Then
Ang = 180 * 3.1415926 / 180
End If
If Pr(1) = Po(1) And Pr(0) > Po(0) Then
Ang = 0
End If

BlokIn.Rotate Po, Ang

Loop

Else
ThisDrawing.Utility.Prompt vbCr & PtH + "的文件路径不存在!"
End If

Err:

End Sub

Sub PlineLenX()
On Error GoTo Err

Dim Plx As String
Dim Obj As AcadEntity
Dim LenTxt As AcadText
Dim Po(0 To 2) As Double
Dim Var As Variant

ThisDrawing.Utility.GetEntity Obj, Var, vbCr & "选取PolyLine对象:"

If Obj.ObjectName = "AcDbPolyline" Then
Plx = CStr(Int(Obj.Length * 100) / 100)

Var = ThisDrawing.Utility.GetPoint(, vbCr & "选取文字放置点:")
Po(0) = Var(0): Po(1) = Var(1): Po(2) = Var(2)
Set LenTxt = ThisDrawing.ModelSpace.AddText("heater len", Po, 4)
LenTxt.StyleName = "HEATERTXT": LenTxt.Layer = "3"
Po(0) = Po(0): Po(1) = Po(1) - 6: Po(2) = Po(2)
Set LenTxt = ThisDrawing.ModelSpace.AddText(Plx, Po, 4)
LenTxt.StyleName = "HEATERTXT": LenTxt.Layer = "3"
Else
ThisDrawing.Utility.Prompt vbCr & "选取对象无效!"

End If
Err:

End Sub
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
xyqf3340
2018-05-10 · TA获得超过155个赞
知道答主
回答量:324
采纳率:100%
帮助的人:73.9万
展开全部
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
无聊挨踢人
2011-08-02 · TA获得超过283个赞
知道小有建树答主
回答量:329
采纳率:0%
帮助的人:292万
展开全部
这算是什么问题?要资料还是有问题?
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 2条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式