Dim ppr As PromptPointResult = ed.GetPoint("请选择插入点:")
成都创新互联长期为数千家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为澄海企业提供专业的网站制作、成都网站建设,澄海网站改版等技术服务。拥有10余年丰富建站经验和众多成功案例,为您定制开发。
Dim pt As Point3d = ppr.Value
utility.WriteToEditor(pt.ToString())
Dim pidBlock As New PIDBlock()
'自己定义的图块类,保存图块的路径和名称
pidBlock.Name = "sample"
pidBlock.Path = blockPath "b_sample.dwg"
Using blkDb As New Database(False, True)
'read drawing
blkDb.ReadDwgFile(pidBlock.Path, System.IO.FileShare.Read, True, Nothing)
blkDb.CloseInput(True)
Using docLock As DocumentLock = doc.LockDocument()
'多文档要先这样,否则报至命错误
Using t As Transaction = doc.TransactionManager.StartTransaction()
'insert it as a new block
Dim idBTR As ObjectId = doc.Database.Insert(pidBlock.Name, blkDb, False)
'create a ref to the block
Dim bt As BlockTable = DirectCast(t.GetObject(doc.Database.BlockTableId, OpenMode.ForRead), BlockTable)
Dim btr As BlockTableRecord = DirectCast(t.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord)
Using bref As New BlockReference(pt, idBTR)
btr.AppendEntity(bref)
t.AddNewlyCreatedDBObject(bref, True)
End Using
t.Commit()
End Using
End Using
End Using
应用程序启动了没
dim acadApp As AcadApplication
acadApp = CType(CreateObject("AutoCAD.Application.18"), AcadApplication)
acadApp.Visible = True
启动了CAD才能添加文件,其中18对应的是cad2010,版本不同不一样。
需要解析CAD文件的构成 然后根据规则绘制 说白点CAD文件是人家公司定义的一个文件格式 里面保存的不是图形 而是图形的绘制规则 程序AutoCad打开文件的时候是读取文件里面描写的绘制规则绘制图案的 你了解了CAD文件的构成后就可以自己写代码绘制图形了(具体CAD图形构成没研究过 你可以用记事本打开一个CAD的图形交换文件.Dxf 可以看到 这个文件是由图层说明和很多点坐标组成的)
你去查查书吧,书上挺详细的,在这说不好说,你先在项目里引用。然后 Dim acadapp As AcadApplication Dim acaddoc As AcadDocument On Error Resume Next AcadApp = GetObject(, "AutoCAD.Application") If Err.Number Then Err.Clear() AcadApp = CreateObject("AutoCAD.Application") If Err.Number Then MsgBox("不能运行AutoCAD,请检查是否安装了AutoCAD") Exit Sub End If End If AcadApp.Visible = True '界面可视
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Interop;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
AcadApplication app;
public Form1()
{
InitializeComponent();
}
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr SetParent(IntPtr child, IntPtr newParent);
[DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]
public static extern IntPtr GetParent(IntPtr hWnd);
private void Form1_Load(object sender, EventArgs e)
{
app = (AcadApplication)Marshal.GetActiveObject("AutoCad.Application");
SetParent(new IntPtr(app.HWND), this.Handle);
}
}
}
Private Function isopen() As AutoCAD.AcadApplication
Try
dim CADapp_temp AutoCAD.AcadApplication = GetObject(, "AutoCAD.Application")
return CADapp_temp
Catch ex As Exception
Return Nothing
End Try
End Function
'调用上面的函数,如果为nothing表示没有打开,否则打开并返回对象