📄 form1.frm
字号:
VERSION 5.00
Begin VB.Form Form1
BorderStyle = 1 'Fixed Single
Caption = "定义为图元"
ClientHeight = 2145
ClientLeft = 45
ClientTop = 330
ClientWidth = 4680
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 2145
ScaleWidth = 4680
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton Command3
Caption = "关闭"
Height = 375
Left = 2640
TabIndex = 4
Top = 1440
Width = 1575
End
Begin VB.TextBox Text3
DataField = "坐标y"
DataSource = "Data1"
Height = 375
Left = 2760
TabIndex = 6
Text = "Text3"
Top = 960
Visible = 0 'False
Width = 1335
End
Begin VB.TextBox Text2
DataField = "坐标x"
DataSource = "Data1"
Height = 375
Left = 1080
TabIndex = 5
Text = "Text2"
Top = 960
Visible = 0 'False
Width = 1095
End
Begin VB.CommandButton Command2
Caption = "保存图元"
Height = 375
Left = 480
TabIndex = 3
Top = 1440
Visible = 0 'False
Width = 1575
End
Begin VB.CommandButton Command1
Caption = "新增图元"
Height = 375
Left = 600
TabIndex = 2
Top = 1440
Width = 1575
End
Begin VB.Data Data1
Caption = "Data1"
Connect = "Access"
DatabaseName = "C:\开放性图库\图元库.mdb"
DefaultCursorType= 0 'DefaultCursor
DefaultType = 2 'UseODBC
Exclusive = 0 'False
Height = 375
Left = 480
Options = 0
ReadOnly = 0 'False
RecordsetType = 1 'Dynaset
RecordSource = "图元"
Top = 1680
Visible = 0 'False
Width = 3855
End
Begin VB.TextBox Text1
DataField = "文件名"
DataSource = "Data1"
Enabled = 0 'False
Height = 390
Left = 2400
TabIndex = 1
Text = "Text1"
Top = 240
Width = 1695
End
Begin VB.Label Label1
Caption = "请输入图元名:"
Height = 255
Left = 720
TabIndex = 0
Top = 360
Width = 1455
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public acadapp As Object
Public acaddoc As Object
Public mospace As Object
Public acadutil As Object
Private Sub Form_Load()
On Error Resume Next
Set acadapp = GetObject(, "autocad.application") '如果AutoCAD已经启动,则直接得到
If Err Then
Err.Clear
Set acadapp = CreateObject("autocad.application") '若AutoCAD未启动,则启动AutoCAD
End If
Set acaddoc = acadapp.ActiveDocument '设置acaddoc为当前图形文件
Set mospace = acaddoc.ModelSpace '设置mospace为当前图形文件的模型空间
Set acadutil = acaddoc.Utility '设置acadUtil对象
acadapp.Visible = False
End Sub
Private Sub Command1_Click()
Data1.Recordset.AddNew
Text1.Enabled = True
Text1.SetFocus
Command1.Visible = False
Command2.Visible = True
End Sub
Private Sub Command2_Click()
If Text1.Text = "" Then '如果没有输入文件名,提示输入并重新开始
MsgBox "必须输入图块名!"
Exit Sub
End If
'隐藏窗体,定义记录集
Me.Hide
acadapp.Visible = True
Dim recordset1 As Recordset
Dim recordset2 As Recordset
'插找图元库中有无相同的记录
Dim filterstr As String
filterstr = "文件名='" + Text1.Text + "'"
Set recordset2 = Data1.Recordset
recordset2.Filter = filterstr
Set recordset1 = recordset2.OpenRecordset(recordset2.Type)
If recordset1.RecordCount = 0 Then '如果没有相同记录
'选择图形并输出bmp文件
Dim exportFile As String
exportFile = "c:\开放性图库\图形文件\" + Text1.Text
Dim sset As Object
Set sset = acaddoc.SelectionSets.Add("TEST")
sset.SelectOnScreen
acaddoc.Export exportFile, "bmp", sset
'选择相对插入点将其坐标添加到数据库
Dim insert As Variant
Dim prompt As String
Dim x, y As Double
prompt = NL & "请选择块的插入点: " '提示用户输入起始点
insert = acadutil.Getpoint(, prompt)
Text2.Text = insert(0)
Text3.Text = insert(1)
'输出dwg文件并卸载窗体
acaddoc.Wblock "c:\开放性图库\图形文件\" + Text1.Text, sset
Unload Me
Else
MsgBox "图元已经存在,请另外选择名称!" '如果文件名存在则提示
End If
End Sub
Private Sub Command3_Click()
acadapp.Visible = True
Unload Me
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -