.NET

Reply
Member
egug
Posts: 4
Registered: ‎08-23-2006
Message 1 of 2 (895 Views)

block explode vb.net

895 Views, 1 Replies
08-27-2006 04:13 AM
this program insert a block in a dwg, works wonderfull. my problem is, after block insert i will explode this block. what can i do ? thanks for ideas

Option Explicit On

Imports System
Imports System.Type
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports acadApp = Autodesk.AutoCAD.ApplicationServices.Application
Imports Autodesk.AutoCAD.Geometry
Imports DBTransMan = Autodesk.AutoCAD.DatabaseServices.TransactionManager

Public Class AdskClass1
_
Public Function Asdkcmd1()
Dim insertionPoint(2) As Double
Dim Comp As String
Comp = "d:\temp\test.dwg"
insertionPoint(0) = 10 : insertionPoint(1) = 20 : insertionPoint(2) = 0
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)
Dim db As Database = New Database(False, False)
db.ReadDwgFile(dwgName, IO.FileShare.Read, True, "")
Dim BlkId As ObjectId
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(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite, True)
Dim bref As BlockReference = New BlockReference(New Autodesk.AutoCAD.Geometry.Point3d(insertionPoint), BlkId)
btr.AppendEntity(bref)
tr.AddNewlyCreatedDBObject(bref, True)
tr.Commit()
Catch ex As Exception
ed.WriteMessage(ex.ToString)
End Try
End Function
End Class
Member
egug
Posts: 4
Registered: ‎08-23-2006
Message 2 of 2 (895 Views)

Re: block explode vb.net

08-27-2006 09:49 AM in reply to: egug
the program is now working :-)

Option Explicit On

Imports System
Imports System.Type
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports acadApp = Autodesk.AutoCAD.ApplicationServices.Application
Imports Autodesk.AutoCAD.Geometry
Imports DBTransMan = Autodesk.AutoCAD.DatabaseServices.TransactionManager

Public Class AdskClass1
_
Public Function Asdkcmd1()
Dim insertionPoint(2) As Double
Dim Comp As String
Comp = "d:\temp\test.dwg"
insertionPoint(0) = 10 : insertionPoint(1) = 20 : insertionPoint(2) = 0
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)
Dim db As Database = New Database(False, False)
db.ReadDwgFile(dwgName, IO.FileShare.Read, True, "")
Dim BlkId As ObjectId
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(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite, True)
Dim bref As BlockReference = New BlockReference(New Autodesk.AutoCAD.Geometry.Point3d(insertionPoint), BlkId)
btr.AppendEntity(bref)
tr.AddNewlyCreatedDBObject(bref, True)
bref.ExplodeToOwnerSpace()
bref.Erase()
tr.Commit()
Catch ex As Exception
ed.WriteMessage(ex.ToString)
End Try
End Function
End Class
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.