Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: Method "Viewports" of object "IAxDbDocument" failed when saving via AxDBlib

  1. #11
    Member
    Join Date
    2015-01
    Posts
    27
    Login to Give a bone
    0

    Default Re: Method "Viewports" of object "IAxDbDocument" failed when saving via AxDBlib

    Quote Originally Posted by RICVBA View Post
    20 seconds per dwg is a lot of time, indeed.
    so, before you get definitely caught by Lord Fener (I and BB know what I mean!) I'd suggest one VBA alternative: using selectionsets
    but to this end you must abandon adbxlib and stick to the "normal open&close"

    if you post your VBA code I'll gladly try and help you to make it much faster
    I'm new to VBA (even though I learned VB a looong time ago) an especially to Autocad VBA, so I didn't know much about selection sets. Examples I found always started from user selections, but now I found this function that could help improving my code, and also the code someone else wrote before I was hired.
    I'll try that and I will report as soon as I have results!

    In the meantime, I downloaded SharpDevelop (a portable version since I'm no admin of my pc) and I'll try to dip into .NET when I got time to develop new functionalities; for now I won't fix what's not broken, but when I'll got some more experience I could migrate existing macros.

    (I still can't figure out why they changed Darth Vader's name here in Italy!)

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

    Default Re: Method "Viewports" of object "IAxDbDocument" failed when saving via AxDBlib

    Quote Originally Posted by RICVBA View Post
    I followed the links BB gave in its post #8 and landed at "Through the Interface" Keans's "Accessing DWG files not open in the AutoCAD editor using .NET" post
    form where I boldly copied and pasted his "ExtractObjects" C# project and had it run, oddly, at my first attempt.

    Still through those posts I thought to understand that using side database would avoid using transaction, too. and that this latter would be almost necessary to achieve the "geek" performance results. But in Kean's code I see Transaction using right after database loading.

    is it possible to avoid it?
    Transactions are how you access a given DBObject for read, or write.

    Now, Transactions are also effectively 'wrappers' for handling some of the internal 'stuff' that needs to be managed, and a Transaction handles all of that 'stuff' for you with a performance hit as compared to handling all of the 'stuff' yourself (which, if not done properly, easily leads to fatal errors, etc.).

    So managing it yourself via Open/Close, or using a Transaction, the same steps are being done - only level of control, and overall performance are dependent on which you choose.

    Particularly for those new to .NET API, I'd strongly suggest you first grasp using Transactions, when to Lock the Document, Application vs Document Context, etc. before worrying about manually managing DBObject's Open/Close, garbage collection, memory leaks, etc.

    ... My $0.02
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

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

    Default Re: Method "Viewports" of object "IAxDbDocument" failed when saving via AxDBlib

    Quote Originally Posted by a.ghensi689507 View Post
    I'm new to VBA (even though I learned VB a looong time ago) an especially to Autocad VBA, so I didn't know much about selection sets. Examples I found always started from user selections, but now I found this function that could help improving my code, and also the code someone else wrote before I was hired.
    I'll try that and I will report as soon as I have results!

    In the meantime, I downloaded SharpDevelop (a portable version since I'm no admin of my pc) and I'll try to dip into .NET when I got time to develop new functionalities; for now I won't fix what's not broken, but when I'll got some more experience I could migrate existing macros.
    FWIW -

    Especially as you're already adept at .NET outside of AutoCAD API, I'd strongly suggest you consider .NET API over that of VBA (ActiveX)... Unless client/employer requires it, I cannot think why you'd otherwise want to relegate yourself, in terms of both feature exposure, and performance... Much, much harder to go from AutoLISP, Visual LISP, or VBA ==> .NET (especially with no Windows .NET experience).

    Given your earlier proficiencies with .NET, learning AutoCAD API should be as easy as learning the code library, keywords, Object Model's Fields, Properties, Methods, and Events, etc.


    Quote Originally Posted by a.ghensi689507 View Post
    (I still can't figure out why they changed Darth Vader's name here in Italy!)
    This may help: Why is Darth Vader called Lord Fener in Italy?

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

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  4. #14
    Member
    Join Date
    2015-01
    Posts
    27
    Login to Give a bone
    0

    Default Re: Method "Viewports" of object "IAxDbDocument" failed when saving via AxDBlib

    Hi guys,
    switching to selections sets dropped the time from ~20sec/dwg to ~3sec/dwg!

    Here's the old code:
    Code:
    Sub RecuperaTesti()
        Dim FileSystem As Object
        Dim SubFolder
        Dim SubSubFolder
        Dim currentPour As String
        Dim modelfile As String
        Dim acad As AcadApplication
        Dim AcadDbx As Object
        Dim AcadObj As AcadObject
        Dim AcadML As AcadMLeader
        Dim AcadTxt As AcadText
        Dim AcadMTxt As AcadMText
        Dim textListWS As Worksheet
        Dim i As Long
        Dim k As Long
        Dim acadRunning As Boolean
        Dim temp
        Dim alreadyProcessedRange As Range
        Dim lastProcessedCell As Range
        Dim foundCell As Range
        
        Application.DisplayStatusBar = True
        Application.StatusBar = "Opening Autocad..."
        Set acad = Nothing
        On Error Resume Next
        Set acad = GetObject(, "AutoCAD.Application.18")
        If Err <> 0 Then
            Set acad = CreateObject("AutoCAD.Application.18")
            acad.Visible = False
            acadRunning = False
        Else
            acadRunning = True
        End If
        On Error GoTo 0 'Error_Control
        
        Set textListWS = ActiveWorkbook.Sheets("TextsList")
        Set FileSystem = CreateObject("Scripting.FileSystemObject")
        
        k = 2 'indice per segnare i pour non aperti
        ' necessita AxBDLib e Autocad con VBA abilitato
        Set AcadDbx = acad.GetInterfaceObject("ObjectDBX.AxDbDocument.18")
        
        Set lastProcessedCell = textListWS.Range("A" & textListWS.Rows.Count).End(xlUp)
        Set alreadyProcessedRange = textListWS.Range("A2:" & lastProcessedCell.Address)
        i = lastProcessedCell.Row + 1
    
        For Each SubFolder In FileSystem.GetFolder(Application.ActiveWorkbook.Path).SubFolders
            If SubFolder.Name <> "Xref" And SubFolder.Name <> "Xstamps" And SubFolder.Name <> "Publish" And SubFolder.Name <> "@ Superseded" And SubFolder.Name <> "0000_CM" And SubFolder.Name <> "1111_AR" Then
                For Each SubSubFolder In SubFolder.SubFolders
                    currentPour = SubSubFolder.Name
                    modelfile = SubSubFolder.Path & "\" & "MDL_A-" & currentPour & "-CV-D50-001.dwg"
                    If Dir(modelfile) <> "" Then
                        Set foundCell = alreadyProcessedRange.Find(What:=currentPour, after:=lastProcessedCell)
                        If foundCell Is Nothing Then
                            ' Open a drawing in ObjectDbx
                            On Error Resume Next
                            AcadDbx.Open (modelfile)
                            If Err.Number = 0 And AcadDbx.Name <> "" Then
                                On Error GoTo 0
                                Application.StatusBar = "Processing " & currentPour & "..."
                                For Each AcadObj In AcadDbx.ModelSpace
                                    testo = ""
                                    If TypeOf AcadObj Is AcadText Then
                                        Set AcadTxt = AcadObj
                                            ......
                                    ElseIf TypeOf AcadObj Is AcadMText Then
                                        Set AcadMTxt = AcadObj
                                           ......
                                        End If
                                    ElseIf TypeOf AcadObj Is AcadMLeader Then
                                        Set AcadML = AcadObj
                                           .....
                                    End If
                                Next AcadObj
                                ' Clean up Variables
                                Set AcadObj = Nothing
                                Set AcadTxt = Nothing
                                Set AcadMTxt = Nothing
                                Set AcadML = Nothing
                            End If
                        End If
                    End If
                    On Error GoTo 0
                Next SubSubFolder
            End If
        Next SubFolder
        Application.StatusBar = "Closing Autocad..."
        Set AcadDbx = Nothing
        If acadRunning = False Then acad.Quit
        Set acad = Nothing
        Application.StatusBar = "Done."
        Application.StatusBar = False
    End Sub
    and this is the modified part of the code (obviously I switched from axdblib to acaddocument):
    Code:
    If SelectObjectsOnLayer(acadDoc, acadSelection, "TEXT", "*") > 0 Then
        For Each AcadTxt In acadSelection
            ....
        Next AcadTxt
    End If
    If SelectObjectsOnLayer(acadDoc, acadSelection, "MTEXT", "*") > 0 Then
        For Each AcadMTxt In acadSelection
            ....
        Next AcadMTxt
    End If
    If SelectObjectsOnLayer(acadDoc, acadSelection, "MULTILEADER", "*") > 0 Then
         For Each AcadML In acadSelection
            .....
        Next AcadML
    End If
    Using the SelectObjectsOnLayer function I found on the autodesk forum that I posted earlier.


    I'm no .NET expert (my VB experience dates back to VB6 age), in fact I always tried to avoid everything microsoft after I discovered open source software :P
    Obviously now I have to stick with company standards and tools, so I'll try to learn .NET to help speedup the workflow!

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 0
    Last Post: 2012-06-06, 11:54 AM
  2. AXDBLib AcSaveAsType "object or method error"
    By bob.stains in forum VBA/COM Interop
    Replies: 2
    Last Post: 2009-04-14, 06:18 PM
  3. ENTIDADES EN ALIGNMENT COMO "FIXED", "FLOTING" y "FREE"
    By cadia in forum AutoCAD Civil 3D - General
    Replies: 1
    Last Post: 2009-02-01, 04:21 AM
  4. Replies: 7
    Last Post: 2007-09-26, 08:53 PM
  5. Replies: 2
    Last Post: 2006-06-20, 05:12 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
  •