CAD/CAM discussion forum > CAD > Insert external DWG as block via vb.net

Insert external DWG as block via vb.net

    
  Subscribe Topic

Rank: 2

abdall5439

Assistant Engineer

posts: 6

Registered: 2016-11-9

Message 1 of 4

 Insert external DWG as block via vb.net
19-12-2016 07:22 . pm   |   View his/her posts only
Hi all,I need to Insert an external dwg as block in the current active space(model or layout) via vb.net
how can I do that?????

Rank: 2

abdall5439

Assistant Engineer

posts: 6

Registered: 2016-11-9

Message 2 of 4

26-12-2016 06:39 . pm   |   View his/her posts only
any help??????????

Rank: 5Rank: 5

Jeffrey_ZWCAD

posts: 496

Registered: 2015-6-9

Message 3 of 4

06-01-2017 02:42 . pm   |   View his/her posts only
Reply 2# abdall5439


Hi, here is an example to insert a block via vb.net, but if need it to work in ZWCAD 2017, it may need to modify some statements slightly. http://www.cadtutor.net/forum/showthread.php?61579-Inserting-A-Block-in-VB.NET

Rank: 5Rank: 5

Jeffrey_ZWCAD

posts: 496

Registered: 2015-6-9

Message 4 of 4

10-01-2017 09:58 . am   |   View his/her posts only
Reply 2# abdall5439


Hi, I check the link here (http://www.cadtutor.net/forum/showthread.php?61579-Inserting-A-Block-in-VB.NET) and try to migrate the vb.net code to work in ZWCAD 2017, here is the code I edit.

Imports ZwSoft.ZwCAD.ApplicationServicesImports ZwSoft.ZwCAD.Runtime
Imports ZwSoft.ZwCAD.DatabaseServices
Imports ZwSoft.ZwCAD.Geometry
Imports System.Windows.Forms
Imports ZwSoft.ZwCAD.EditorInput
Imports System.IO


Namespace TEST
Public Class Class1
_
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 = ZwSoft.ZwCAD.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
End Class

End Namespace




If you want to create the dll by yourself, you may need to construct the developing environment by following the elementary guide as the attached pdf file.

Or if you just want a dll file, I also attached the dll file here. You can input NETLOAD command here and then choose to load this dll file, after that, input InsertBlock as a command to select a dwg to insert as a block.

Thanks. InsertBlock.zip (7.5 KB) ZWCAD .NET elementary guidance.pdf (575.18 KB)
See also
X