Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
Imports acadApp = Autodesk.AutoCAD.ApplicationServices.Application
Public Class GSClass
' Define command 'Asdkcmd1'
_
Public Sub Asdkcmd1()
Dim db As Database
Dim BlkId As ObjectId
Dim comp As String = "c:\cadproductie\c20\applicaties\cadensys\symb\prorail\50a.dwg"
Dim doc As Document = acadApp.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
Dim tr As Transaction = doc.TransactionManager.StartTransaction()
Try
Dim dwgName As String = HostApplicationServices.Current.FindFile(comp, acadApp.DocumentManager.MdiActiveDocument.Database, FindFileHint.Default)
' Read file in new database
db = New Database(False, False)
db.ReadDwgFile(dwgName, System.IO.FileShare.Read, True, "")
' insert block in drawing database
BlkId = doc.Database.Insert(dwgName, db, False)
Dim bt As BlockTable = tr.GetObject(doc.Database.BlockTableId, OpenMode.ForRead, True)
Dim btr As BlockTableRecord = tr.GetObject(BlkId, OpenMode.ForWrite)
Dim bref As BlockReference = New BlockReference(New Autodesk.AutoCAD.Geometry.Point3d(10, 10, 0), BlkId)
btr.AppendEntity(bref)
tr.AddNewlyCreatedDBObject(bref, True)
bref.ExplodeToOwnerSpace()
bref.Erase()
tr.Commit()
Finally
tr.Dispose()
End Try
End Sub
End Class
Hello All,
I am new to .NET for AutoCAD but have been doing AutoLISP for 20+ years and just started C#.NET. I am using VS2010 (Building 3.5) and AutoCAD 2012. I am trying to insert a title block in a new drawing. I am getting a "eNoInputFiler" error on line 'db.ReadDwgFile(dwgName, System.IO.FileShare.Read, true, null);'
Can you me help?
// Set the DWG to insert
string comp = "C:\\DATA\\TB11X17A.dwg";
Document doc = acadApp.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Transaction tr = doc.TransactionManager.StartTransaction();
try
{
string dwgName = HostApplicationServices.Current.FindFile(comp, acadApp.DocumentManager.MdiActiveDocument.Database, FindFileHint.Default);
Database db = new Database(false, false);
db.ReadDwgFile(dwgName, System.IO.FileShare.Read, true, null);
ObjectId BlkId;
BlkId = doc.Database.Insert(dwgName, db, false);
BlockTable bt = (BlockTable)tr.GetObject(doc.Database.BlockTableId, OpenMode.ForRead, true);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
BlockReference bref = new BlockReference(new Autodesk.AutoCAD.Geometry.Point3d(10, 10, 0), BlkId);
btr.AppendEntity(bref);
tr.AddNewlyCreatedDBObject(bref, true);
bref.ExplodeToOwnerSpace();
bref.Erase();
tr.Commit();
}
finally
{
tr.Dispose();
}
Hi Jim,
Look at this post:
http://forums.autodesk.com/t5/NET/Discussion-Group-ClassLibrary-please-read/td-p/3005908
It has an class for inserting blocks.
Hope it helps,
Kind regards,
Irvin
Can't find what you're looking for? Ask the community or share your knowledge.