metaldan Posted February 17, 2012 Share Posted February 17, 2012 Hi I search the way to make a WBLOCK command in vb.net. I have to ask th user to select some BOM line, with that, ask him to select different object to make wblock with them. did someone can help me. Quote Link to comment Share on other sites More sharing options...
fixo Posted February 17, 2012 Share Posted February 17, 2012 Take a look at online docs: http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer's%20Guide/index.html?url=WS1a9193826455f5ff2566ffd511ff6f8c7ca-4875.htm,topicNumber=d0e51 ~'J'~ Quote Link to comment Share on other sites More sharing options...
metaldan Posted February 18, 2012 Author Share Posted February 18, 2012 thank's Fixo I found a WBLOCKCLONNING method, now, i'am lokking to save it in dxf format. Quote Link to comment Share on other sites More sharing options...
fixo Posted February 18, 2012 Share Posted February 18, 2012 Save a drawing usual way as ".dwg", then you can save them after as ".dxf" using Interop Namespace Or you may want to try this slow method using Reflection: Imports System.Runtime.InteropServices Imports System.Reflection Imports System.Globalization Imports System.Collections Imports Autodesk.AutoCAD.Runtime <Assembly: CommandClass(GetType(OldHorse.ReflectionCommands))> Namespace OldHorse Public Class ReflectionCommands <System.Security.SuppressUnmanagedCodeSecurity()> _ Public Shared Sub DwgToDxf(acadver As String, fname As String, dxfname As String) Dim thisThread As System.Globalization.CultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture thisThread = New System.Globalization.CultureInfo("en-US") Dim appProgID As String = "Autocad.Application" + "." + acadver ' get reference on interface IDispatch Dim AcadType As Type = Type.GetTypeFromProgID(appProgID) ' run AutoCAD Dim AcadApp As Object = Activator.CreateInstance(AcadType) Dim visargs() As Object = New Object(0) {} visargs(0) = True ' make application visible AcadApp.GetType().InvokeMember("Visible", BindingFlags.SetProperty, Nothing, AcadApp, visargs, Nothing) Dim AcadDocs As Object = AcadApp.GetType().InvokeMember( _ "Documents", BindingFlags.GetProperty, Nothing, AcadApp, Nothing) ' define arguments to open file Dim args() As Object = New Object(1) {} args(0) = fname args(1) = False 'read-only=false, in other words we open file in write mode ' try open file Dim AcDoc As Object = AcadDocs.GetType.InvokeMember( _ "Open", BindingFlags.InvokeMethod, Nothing, AcadDocs, args, Nothing) Dim Util As Object = New Object Try ' get active document AcDoc = AcadApp.GetType.InvokeMember( _ "ActiveDocument", BindingFlags.GetProperty, Nothing, AcadApp, Nothing, Nothing) 'Save document in desired DXF format: ''-------------------------------------------------'' '' DXF formats: '' 13 = ac2000_dxf, 25 = ac2004_dxf, 37 = ac2007_dxf ''-------------------------------------------------'' AcDoc.GetType().InvokeMember( _ "SaveAs", BindingFlags.InvokeMethod, Nothing, AcDoc, New Object() {dxfname, 37}) ' Close source document 'Dim closeargs() As Object = New Object(1) {} 'closeargs(0) = True ' with same name ' closeargs(1) = fname ' close source document ' Try close active document ' AcDoc.GetType().InvokeMember( _ ' "Close", BindingFlags.InvokeMethod, Nothing, AcDoc, closeargs, _ 'Nothing, System.Globalization.CultureInfo.CurrentCulture, Nothing ' simplified syntax to close document AcDoc.GetType().InvokeMember( _ "Close", BindingFlags.InvokeMethod, Nothing, AcDoc, Nothing) ' Try quit application AcadApp.GetType().InvokeMember( _ "Quit", BindingFlags.InvokeMethod, Nothing, AcadApp, Nothing) MsgBox("Done, check a dxf file") Catch ex As System.Exception MsgBox("Error: " & ex.Message & vbLf & "Trace: " & ex.StackTrace) Finally ' garbage clean ' release AcDoc. releaseObject(AcDoc) ' release AcadDocs. releaseObject(AcadDocs) ' release AcadApp. releaseObject(AcadApp) ' call garbage cleaner immediatelly GC.WaitForPendingFinalizers() GC.GetTotalMemory(True) GC.WaitForPendingFinalizers() GC.GetTotalMemory(True) ' restore current culture System.Threading.Thread.CurrentThread.CurrentUICulture = thisThread End Try End Sub Public Shared Sub releaseObject(ByVal obj As Object) Try System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj) obj = Nothing Catch ex As System.Exception obj = Nothing Finally GC.Collect() End Try End Sub End Class End Namespace then in caller class try something like this: (tested on 2009 only many times) <CommandMethod("SaveAsDxf", "sdxf", CommandFlags.Session Or CommandFlags.Modal)> _ Public Sub TestSaveAsDXF() Dim acver As System.Version = Autodesk.AutoCAD.ApplicationServices.Application.Version Dim numver As String = acver.Major.ToString '' source drawing after executing the WbloneObjects method Dim fileName As String = "C:\Test\foo.dwg" '' save document as DXF file Dim dxfname As String = "C:\Test\foo.dxf" ReflectionCommands.DwgToDxf(numver, fileName, dxfname) End Sub ~'J'~ Quote Link to comment Share on other sites More sharing options...
Jeff H Posted February 18, 2012 Share Posted February 18, 2012 Have you tried Database.DxfOut Method Quote Link to comment Share on other sites More sharing options...
metaldan Posted March 1, 2012 Author Share Posted March 1, 2012 Thank's Jeff H your DATABASE.DXFOUT method work perfectley. I put it in a loop to pass all the item in my BOM. For each item, the user select the objet, the vb.net open a new acad document ( temporaly ) , database.dxfout it, and after a close the document. The Dxf is saved perfectly but it don't close it. I have 1 temporaly document for each item.??? wierd. Maybe a put the END USING database at the wrong place. i will check it tomorow. Quote Link to comment Share on other sites More sharing options...
metaldan Posted March 4, 2012 Author Share Posted March 4, 2012 Hi I found the way instead of the DOCUMENT.DISPOSE method, I use DOCUMENT.ClLOSEANDDISCARD() THANK'S FOR YOUR HELP Quote Link to comment Share on other sites More sharing options...
metaldan Posted March 7, 2012 Author Share Posted March 7, 2012 hi A error apear when a run my progrm on a 64bit machine ( win 7 64bit + acad 201264bit) but not on winxp 32 bit + acad 2008 After that line acDbNewDoc.DxfOut("R:\IN BEND\" & Left(DANCART.DESSIN, & "-" & BOML.ITEM & ".dxf", 16, DwgVersion.Current) i receive this error INTERNAL ERROE : !dbobji.cpp@7319: eNotOpenForWrite after, i have a 0 ko dxf file. Did you have any ideas??? The R:\IN BEND is on a Network, i try to make a manualy saveas DXF at the same location, with the same name and it work. Quote Link to comment Share on other sites More sharing options...
metaldan Posted March 13, 2012 Author Share Posted March 13, 2012 I found the solution on my problemm. I instal the service pack 1 from and all work well now. 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.