Results 1 to 5 of 5

Thread: ObjectARX AUTOCAD 2013 - VisualStudioExpress 2010

  1. #1
    Member
    Join Date
    2015-05
    Posts
    3
    Login to Give a bone
    0

    Default ObjectARX AUTOCAD 2013 - VisualStudioExpress 2010

    Ciao a tutti,
    sto provando a scrivere un' applicazione per leggere blocchi da disegni autocad ed importarli nel disegno corrente.

    Non riesco a capire il motivo dell' errore nella funzione di Insert:

    Code:
            <Autodesk.AutoCAD.Runtime.CommandMethod("INSERISCI")> _
            Public Shared Sub Inserisci()
                Dim tDoc As ApplicationServices.Document = ApplicationServices.Application.DocumentManager.MdiActiveDocument
                Dim tDocDB As DatabaseServices.Database = tDoc.Database
                Dim tDocLock As ApplicationServices.DocumentLock = Nothing
                Dim tTrAct As DatabaseServices.Transaction = Nothing
    
    
                Dim tDwgFileName As String = "C:\Users\UTENTE\Documents\VB.NET\HelloWorld\test1.dwg"
                Dim tBlockName As String = "test1"
                Dim tBlTabRecID As ObjectId = Nothing
    
    
                Dim tDB As DatabaseServices.Database = Nothing
                Try
                    If IO.File.Exists(tDwgFileName) Then
                        tDocLock = tDoc.LockDocument
                        tTrAct = tDoc.TransactionManager.StartTransaction
    
    
                        tDB = New Database(False, True)
                        tDB.ReadDwgFile(tDwgFileName, IO.FileShare.None, True, "")
    
    
                        tDocDB.Insert(Matrix3d.Displacement(New Vector3d(0, 0, 0)), tDB, True) '<-------- OK!
    
    
                        'Errore!
                        tBlTabRecID = tDocDB.Insert(tBlockName, tDB, False) <------ Errore eSelfReference!
    
    
                        tTrAct.Commit()
                    Else
                        MsgBox("File: " & tDwgFileName & " could not be found!")
                    End If
    
    
                Catch ex As Autodesk.AutoCAD.Runtime.Exception
                    MsgBox("ReadFromDWG:" & ex.Message & vbNewLine & ex.StackTrace)
                Finally
                    If tTrAct IsNot Nothing Then tTrAct.Dispose() : tTrAct = Nothing
                    If tDocLock IsNot Nothing Then tDocLock.Dispose() : tDocLock = Nothing
                End Try
            End Sub
    Cosa sbaglio??

    Grazie!
    Attached Files Attached Files
    Last edited by BlackBox; 2015-05-19 at 03:14 PM. Reason: Please use [CODE] Tags | Si prega di utilizzare i Tag [CODE]

  2. #2
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,526
    Login to Give a bone
    0

    Default Re: ObjectARX AUTOCAD 2013 - VisualStudioExpress 2010

    English (Google Translate):

    Quote Originally Posted by lucalenzi82701057 View Post
    Hello everyone,
    I'm trying to write an 'application to read blocks from AutoCAD drawings and import them into the current drawing.

    I can not understand the reason of 'error in the function Insert:

    Code:
            <Autodesk.AutoCAD.Runtime.CommandMethod("INSERISCI")> _
            Public Shared Sub Inserisci()
                Dim tDoc As ApplicationServices.Document = ApplicationServices.Application.DocumentManager.MdiActiveDocument
                Dim tDocDB As DatabaseServices.Database = tDoc.Database
                Dim tDocLock As ApplicationServices.DocumentLock = Nothing
                Dim tTrAct As DatabaseServices.Transaction = Nothing
    
    
                Dim tDwgFileName As String = "C:\Users\UTENTE\Documents\VB.NET\HelloWorld\test1.dwg"
                Dim tBlockName As String = "test1"
                Dim tBlTabRecID As ObjectId = Nothing
    
    
                Dim tDB As DatabaseServices.Database = Nothing
                Try
                    If IO.File.Exists(tDwgFileName) Then
                        tDocLock = tDoc.LockDocument
                        tTrAct = tDoc.TransactionManager.StartTransaction
    
    
                        tDB = New Database(False, True)
                        tDB.ReadDwgFile(tDwgFileName, IO.FileShare.None, True, "")
    
    
                        tDocDB.Insert(Matrix3d.Displacement(New Vector3d(0, 0, 0)), tDB, True) '<-------- OK!
    
    
                        'Errore!
                        tBlTabRecID = tDocDB.Insert(tBlockName, tDB, False) <------ Errore eSelfReference!
    
    
                        tTrAct.Commit()
                    Else
                        MsgBox("File: " & tDwgFileName & " could not be found!")
                    End If
    
    
                Catch ex As Autodesk.AutoCAD.Runtime.Exception
                    MsgBox("ReadFromDWG:" & ex.Message & vbNewLine & ex.StackTrace)
                Finally
                    If tTrAct IsNot Nothing Then tTrAct.Dispose() : tTrAct = Nothing
                    If tDocLock IsNot Nothing Then tDocLock.Dispose() : tDocLock = Nothing
                End Try
            End Sub
    What is wrong ??

    Thanks!
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3620, Core i7-7700K 4.2GHz, 64GB RAM, Samsung 970 Pro M.2, 8GB NVIDIA Quadro P4000

  3. #3
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,526
    Login to Give a bone
    0

    Default Re: ObjectARX AUTOCAD 2013 - VisualStudioExpress 2010

    Consider the meaning of the Exception being raised, and note the name of both your source drawing (being opened as side Database), and the block you're attempting to Insert():

    [Google Translate] Si consideri il significato della eccezione sollevata, e prendere nota del nome del sia il vostro disegno di origine (come l'apertura del database lato), e il blocco che si sta tentando di inserire ():

    Quote Originally Posted by lucalenzi82701057 View Post
    Code:
            <Autodesk.AutoCAD.Runtime.CommandMethod("INSERISCI")> _
            Public Shared Sub Inserisci()
                Dim tDoc As ApplicationServices.Document = ApplicationServices.Application.DocumentManager.MdiActiveDocument
                Dim tDocDB As DatabaseServices.Database = tDoc.Database
                Dim tDocLock As ApplicationServices.DocumentLock = Nothing
                Dim tTrAct As DatabaseServices.Transaction = Nothing
    
    
                Dim tDwgFileName As String = "C:\Users\UTENTE\Documents\VB.NET\HelloWorld\test1.dwg"
                Dim tBlockName As String = "test1"
                Dim tBlTabRecID As ObjectId = Nothing
    
    
                Dim tDB As DatabaseServices.Database = Nothing
                Try
                    If IO.File.Exists(tDwgFileName) Then
                        tDocLock = tDoc.LockDocument
                        tTrAct = tDoc.TransactionManager.StartTransaction
    
    
                        tDB = New Database(False, True)
                        tDB.ReadDwgFile(tDwgFileName, IO.FileShare.None, True, "")
    
    
                        tDocDB.Insert(Matrix3d.Displacement(New Vector3d(0, 0, 0)), tDB, True) '<-------- OK!
    
    
                        'Errore!
                        tBlTabRecID = tDocDB.Insert(tBlockName, tDB, False) <------ Errore eSelfReference!
    
    
                        tTrAct.Commit()
                    Else
                        MsgBox("File: " & tDwgFileName & " could not be found!")
                    End If
    
    
                Catch ex As Autodesk.AutoCAD.Runtime.Exception
                    MsgBox("ReadFromDWG:" & ex.Message & vbNewLine & ex.StackTrace)
                Finally
                    If tTrAct IsNot Nothing Then tTrAct.Dispose() : tTrAct = Nothing
                    If tDocLock IsNot Nothing Then tDocLock.Dispose() : tDocLock = Nothing
                End Try
            End Sub


    That said, give this DevBlog article a read, and note the usage of WblockCloneObjects() instead of Insert() Method:

    [Google Translate] Detto questo, dare a questo articolo Devblog una lettura, e notare l'uso di WblockCloneObjects () al posto di Insert () Metodo:

    http://adndevblog.typepad.com/autoca...sing-net-.html




    Separatamente, dove in Italia si chiama a casa? Abbiamo famiglia lì; mia Nonna vive appena fuori Venezia!

    Ciao
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3620, Core i7-7700K 4.2GHz, 64GB RAM, Samsung 970 Pro M.2, 8GB NVIDIA Quadro P4000

  4. #4
    Member
    Join Date
    2015-05
    Posts
    3
    Login to Give a bone
    0

    Default Re: ObjectARX AUTOCAD 2013 - VisualStudioExpress 2010

    Hi, first of all thanks for your fast reply.

    I have discover so the mistake...I have change the blockname from:
    Code:
    Dim tBlockName As String = "test1"
    ...to
    Code:
    Dim tBlockName As String = "test2"
    and it works.

    But I have seen that in block list I have both "test1" and "test2" with "DB.Insert" command.
    How to keep only one block, that read from dwg file?

    So, to insert an external drawing directly into the current drawing to I have to use matrix object, right?
    Code:
    tDocDB.Insert(Matrix3d.Displacement(New Vector3d(0, 0, 0)), tDB, True)
    ...and to add a block read from an external drawing into blocklist do I have to use WblockCloneObjects, right?

    Thanks
    Last edited by BlackBox; 2015-05-20 at 06:16 PM. Reason: Please use [CODE] Tags

  5. #5
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,526
    Login to Give a bone
    0

    Default Re: ObjectARX AUTOCAD 2013 - VisualStudioExpress 2010

    Quote Originally Posted by lucalenzi82701057 View Post
    Hi, first of all thanks for your fast reply.
    You're welcome.



    Quote Originally Posted by lucalenzi82701057 View Post
    I have discover so the mistake...I have change the blockname from:
    Code:
    Dim tBlockName As String = "test1"
    ...to
    Code:
    Dim tBlockName As String = "test2"
    and it works.

    But I have seen that in block list I have both "test1" and "test2" with "DB.Insert" command.
    How to keep only one block, that read from dwg file?

    So, to insert an external drawing directly into the current drawing to I have to use matrix object, right?
    Code:
    tDocDB.Insert(Matrix3d.Displacement(New Vector3d(0, 0, 0)), tDB, True)
    ...and to add a block read from an external drawing into blocklist do I have to use WblockCloneObjects, right?
    As I understand it (and I could be mistaken), Database.Insert() is only used to insert the entirety of another drawing into MdiActiveDocument (like the INSERT Command), or an existing BlockTableRecord within the current Database into same Database as BlockReference, etc.... Whereas Database.WblockCloneObjects() Method is used to 'copy' objects (and their BlockTableRecord[s], etc.) from one drawing to another (without INSERTing the entire source drawing).

    Here's another reference:

    http://through-the-interface.typepad..._blocks_f.html



    HTH (Hope This Helps)
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3620, Core i7-7700K 4.2GHz, 64GB RAM, Samsung 970 Pro M.2, 8GB NVIDIA Quadro P4000

Similar Threads

  1. 2013: Setting AutoCAD to always saveas 2010 file format using 2013
    By 3D Jack in forum AutoCAD for Mac General
    Replies: 5
    Last Post: 2013-11-02, 02:11 PM
  2. DE115-2: Ask the Experts: ObjectARX and AutoCAD .NET Panel Discussion
    By Autodesk University in forum Customization and Programming
    Replies: 0
    Last Post: 2013-05-05, 01:43 PM
  3. Sharing files between Autocad 2013 LT and Autocad 2013
    By ksnyyfan2341090 in forum AutoCAD General
    Replies: 1
    Last Post: 2013-04-25, 01:25 AM
  4. AutoCAD, ObjectARX e AUGI
    By fpmalard in forum Português - Customização / Programação
    Replies: 2
    Last Post: 2007-05-18, 02:36 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •