bigr1822 Posted August 4, 2011 Share Posted August 4, 2011 Team, Does anyone have any sample code out there I can use to insert a block using vb.net? The help documents are based on vb. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 5, 2011 Share Posted August 5, 2011 (edited) Something like this perhaps? Pseudo code: [color=black] <CommandMethod("InsertBlock")> _ Public Sub InsertBlock() Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument acDoc.SendStringToExecute("._-insert [color=red]<YouFillInTheRest>[/color]", False, False, False) End Sub[/color] Edited August 5, 2011 by BlackBox Wow was my original post completely wrong!? That's what I get for posting VB.NET (from memory) from my iPhone! Quote Link to comment Share on other sites More sharing options...
SEANT Posted August 5, 2011 Share Posted August 5, 2011 (edited) Here is an example of inserting a block reference by first selecting the file with a dialog box. It is moderately basic; for instance, it could be extended further, via “jigging”, to allow visual feedback during the insert process. That would increase the complexity of the quite a bit. Watch word wrap! Public Sub InsertFromFileCommand() Dim ofd As OpenFileDialog = New OpenFileDialog() ofd.DefaultExt = ".dwg" ofd.Filter = "Drawing Files (*.dwg)|*.dwg" If ofd.ShowDialog() <> DialogResult.OK Then Return End If Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument Dim db As Database = doc.Database Dim ed As Editor = doc.Editor Dim ppo As New PromptPointOptions(vbLf & "Insertion point: ") Dim ppr As PromptPointResult = ed.GetPoint(ppo) If ppr.Status <> PromptStatus.OK Then Return End If Using xDb As New Database(False, True) xDb.ReadDwgFile(ofd.FileName, FileShare.Read, True, Nothing) Using tr As Transaction = doc.TransactionManager.StartTransaction() Dim name As String = SymbolUtilityServices.GetBlockNameFromInsertPathName(ofd.FileName) Dim id As ObjectId = db.Insert(name, xDb, True) If id.IsNull Then ed.WriteMessage(vbLf & "Failed to insert block") Return End If Dim currSpace As BlockTableRecord = CType(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord) Dim p3d As Point3d = ppr.Value Dim coordS As CoordinateSystem3d = New CoordinateSystem3d(p3d, db.Ucsxdir, db.Ucsydir) 'Determine UCS Dim insert As New BlockReference(p3d, id) insert.Normal = coordS.Zaxis 'Align to UCS currSpace.AppendEntity(insert) insert.SetDatabaseDefaults() tr.AddNewlyCreatedDBObject(insert, True) tr.Commit() End Using End Using End Sub Edited August 5, 2011 by SEANT Typo Quote Link to comment Share on other sites More sharing options...
koranot Posted May 30, 2022 Share Posted May 30, 2022 Hi Seant, I get some part of your code for my own program and it work as expect. The code was very usefull and was the best example to improve my code in the future. Thank you. Koranot Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.