Page 1 of 2 12 LastLast
Results 1 to 10 of 14

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

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

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

    Hi all,
    I'm trying to buld a macro to iterate through many files and change a typo (we are working for a canadian client and some of my colleagues are not so good with english, they wrote "LENGHT" in a table).
    I'm using AxDBlib with Autocad2010, and here's the code (something that I have adapded from an excel macro found on this forum):
    Code:
    Sub FixTypo()
        Dim FileSystem As Object
        Dim folderpath As String
        Dim SubFolder
        Dim SubSubFolder
        Dim currentPour As String
        Dim modelfile As String
        Dim AcadDbx As AxDbDocument
        Dim AcadObj As AcadObject
        Dim AcadTxt As AcadText
        
        folderpath = "D:\temp\"
        Set FileSystem = CreateObject("Scripting.FileSystemObject")
        Set AcadDbx = Application.GetInterfaceObject("ObjectDBX.AxDbDocument.18")
        For Each SubFolder In FileSystem.GetFolder(folderpath).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
                        AcadDbx.Open (modelfile)
                        If Err.Number = 0 And AcadDbx.Name <> "" Then
                            For Each AcadObj In AcadDbx.ModelSpace
                                If TypeOf AcadObj Is AcadText Then
                                    Set AcadTxt = AcadObj
                                    If InStr(AcadTxt.TextString, "LENGHT") <> 0 Then
                                        AcadTxt.TextString = Replace(AcadTxt.TextString, "LENGHT", "LENGTH")
                                        AcadDbx.Save
                                        Exit For
                                    End If
                                End If
                            Next AcadObj
                            Set AcadObj = Nothing
                            Set AcadTxt = Nothing
                        End If
                    End If
                Next SubSubFolder
            End If
        Next SubFolder
        Set AcadDbx = Nothing
    End Sub
    (the subfolder and subsubfolder thing is because of our storage system)

    When I run it it stops at "AcadDbx.Save" throwing thew error
    Code:
    Method "Viewports" of object "IAxDbDocument" failed when saving via AxDBlib
    I can't understand why.
    Does anyone have a clue?

  2. #2
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,420
    Login to Give a bone
    0

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

    I haven't tested with recent releases, but there used to be a problem with the Save method (I don't remember what the issue was). The solution was to use the SaveAs method and overwrite the same file. You might give that a try.
    C:> ED WORKING....


    LinkedIn

  3. #3
    Active Member
    Join Date
    2012-11
    Location
    Italy
    Posts
    65
    Login to Give a bone
    0

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

    Does it throw that error at the very first iteration of the foreach loop?

    Bytheway I recentley could compare the performance of a VBA macro looping through many files both using Dbx and "normal" Autocad application open&close file. Against all my expectations they performed the same, provided I set application "Visible" property to "False".
    So shouldn't you succeed in fixing that dbx problem, you might switch to opening Autocad application.

  4. #4
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    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
    Does it throw that error at the very first iteration of the foreach loop?

    Bytheway I recentley could compare the performance of a VBA macro looping through many files both using Dbx and "normal" Autocad application open&close file. Against all my expectations they performed the same, provided I set application "Visible" property to "False".
    So shouldn't you succeed in fixing that dbx problem, you might switch to opening Autocad application.
    I haven't seen your code, but if you're getting similar performance between ActiveX & .NET, then that's likely due to using DBX, or opening the drawing in the Editor, in lieu of ReadDwgFile(), or Core Console. Feel free to post a thread in the .NET forum to discuss, if you like.

    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

  5. #5
    Active Member
    Join Date
    2012-11
    Location
    Italy
    Posts
    65
    Login to Give a bone
    0

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

    No BB
    those codes of mine where both VBA ones
    one accessing the drawing as AxDbDocument, so:
    Code:
    ThisDrawing = Acad.GetInterfaceObject("ObjectDBX.AxDbDocument.18")
    ThisDrawing.Open FilePath & "\" & FileName"
    and the other accessing it via Autocad editor:
    Code:
    Set Acad = GetObject(, "AutoCAD.Application")
    Set ThisDrawing = Acad.Documents.Open(FilePath & FileName)
    as for NET, I'm still stuck. but with high hopes!

  6. #6
    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

    Thanks to all!
    SaveAs did the trick, now the macro runs without problems.

    I'm running a similar macro, but starting from excel, over 750 files to extract all the texts, some mtexts and some mleader, and it takes about 20 seconds per dwg.
    I used adbxlib because in this and other forums many people stated that it's faster than the normal open&close, and I struggled few days to make it work. Now you tell me the performance are similar

    maybe it's time to switch to .NET, since the drawings are piling up quickly (they will be about 2000dwgs at the end of this project) and I plan to start building some inventor addins to help the modeling process.. if only my work pc could handle it!

  7. #7
    Active Member
    Join Date
    2012-11
    Location
    Italy
    Posts
    65
    Login to Give a bone
    0

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

    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

  8. #8
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    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
    No BB
    those codes of mine where both VBA ones
    No worries; my misunderstanding.



    Quote Originally Posted by a.ghensi689507 View Post
    SaveAs did the trick, now the macro runs without problems.

    I'm running a similar macro, but starting from excel, over 750 files to extract all the texts, some mtexts and some mleader, and it takes about 20 seconds per dwg.
    I used adbxlib because in this and other forums many people stated that it's faster than the normal open&close, and I struggled few days to make it work. Now you tell me the performance are similar

    maybe it's time to switch to .NET, since the drawings are piling up quickly (they will be about 2000dwgs at the end of this project) and I plan to start building some inventor addins to help the modeling process.. if only my work pc could handle it!
    Glad you got it sorted!

    I'd love to be able to test a .NET equivalent on a copy of the same data set, given the performance gains shown here. :geek:

    VBA isn't going anywhere, but it's also not evolving at the same rate as .NET, nor is it currently just a slower equivalent. .NET just has more capability, and can better meet the ever-changing needs of most... But that doesn't necessarily mean it's the best tool for the job either, given one's own proficiencies, availability of required applications, internal policies, and ultimately your ability to develop, distribute, and maintain the resultant apps.

    Despite strongly encouraging any who have a firm grasp on ActiveX to begin the long process of learning .NET, that doesn't mean you need to give up VBA, Visual LISP, etc. - you're adding to your skill sets, not necessarily replacing one.

    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

  9. #9
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    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
    so, before you get definitely caught by Lord Fener (I and BB know what I mean!) ....
    Here's a general translation for those that do not speak Italian, from a recent thread.

    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

  10. #10
    Active Member
    Join Date
    2012-11
    Location
    Italy
    Posts
    65
    Login to Give a bone
    0

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

    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?

Page 1 of 2 12 LastLast

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
  •