Results 1 to 5 of 5

Thread: Open Drawings Commands

  1. #1
    Login to Give a bone
    0

    Question Open Drawings Commands

    I have a little program that the user can issue several commands in all open drawings.
    It has worked for years in AutoCAD versions 2006 through 2012.
    I am testing our programs in AutoCAD 2015 before updating the Drafting Department.

    After loading OpenDwgsCmds.lsp here is an example for using it.
    Command: ODC
    ZOOM E
    END

    The commands can even be an AutoLISP program you need to run in all open drawings such as MyCode or (c:MyCode) or (MyCode).
    OpenDwgsCmd does not work in AutoCAD 2015 using the SendCommand in the VBA code.
    A programmer with Autodesk helped me with the code by replacing "SendCommand" with "SendKeys" in the VBA code.
    By replacing SendCommand with SendKeys the program will work,
    but I have to toggle to each open drawing before it executes the commands.
    I use Ctrl+Tab to toggle to each drawing, but that's not the way it's supposed to work.
    In previous AutoCAD versions it executed the code automatically in all open drawings.

    I have attached the code I am working with to see if someone can help me.
    To test OpenDwgsCmdsOriginal.dvb rename it to OpenDwgsCmds.dvb
    Thank you,
    TerryCadd
    a.k.a. Terry Miller
    __________________________________________________
    OpenDwgsCmds.dvb Original Version with SendCommand
    __________________________________________________
    Code:
    Option Explicit
    Sub Main()
      Dim objDwg As AcadDocument
      Dim objAcad As AcadApplication
      Dim intDwgCnt As Integer
      Dim strThisDwg As String
      Dim intThisDwg As Integer
      Set objAcad = AcadApplication.Application
      intDwgCnt = 0
      strThisDwg = ThisDrawing.FullName
      For Each objDwg In objAcad.Documents
        If objAcad.Documents.Item(intDwgCnt).FullName <> strThisDwg Then
          objAcad.Documents.Item(intDwgCnt).Activate
          objDwg.SendCommand "(load ""OpenDwgsCmds.lsp"")" & vbCr & "OpenDwgsCmds" & vbCr
        Else
          intThisDwg = intDwgCnt
        End If
        intDwgCnt = intDwgCnt + 1
      Next objDwg
      objAcad.Documents.Item(intThisDwg).Activate
      ThisDrawing.SendCommand "(load ""OpenDwgsCmds.lsp"")" & vbCr & "OpenDwgsCmds" & vbCr
    End Sub
    ______________________________________________
    OpenDwgsCmds.dvb Revised Version with SendKeys
    ______________________________________________
    Code:
    Public Sub Main()
      Dim initialDwg As AcadDocument
      Set initialDwg = Application.ActiveDocument
      initialDwg.SendCommand "(load ""OpenDwgsCmds.lsp"") OpenDwgsCmds "
      Dim objDwg As AcadDocument
      For Each objDwg In Application.Documents
        If Not objDwg Is initialDwg Then
          objDwg.Activate
          DoEvents
          SendKeys "{(}load ""OpenDwgsCmds.lsp""{)} OpenDwgsCmds ", True
          DoEvents
        End If
      Next
      initialDwg.Activate
    End Sub
    Attached Files Attached Files
    Last edited by Terry Cadd; 2014-05-15 at 10:07 PM.

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

    Default Re: Open Drawings Commands

    Not sure if this is your particular issue, but in addition to the 'big split' in 2013 API, 2015 API also introduces changes that were not present in 2014 (i.e., MdiActiveDocument is now Nullable, there are changes to how one can call Commands, etc.)... Mind you I skipped VBA altogether going Visual LISP --> .NET, but I'd speculate this affects VBA as well at some level.



    From Kean:

    AutoCAD 2015 for developers

    AutoCAD 2015: calling commands

    Supporting AutoCAD 2015’s dark theme

    AutoCAD 2015’s updated JavaScript API

    ... etc.
    "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. #3
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,420
    Login to Give a bone
    0

    Default Re: Open Drawings Commands

    It looks to me like you're just trying to save all dwgs after switching to ps. You should just do it all in vba and avoid sendcommand/sendkeys. Here is a sub I wrote to save all. Just add your code to switch to ps before oDwg.Save.
    Code:
    Sub SaveAll()
        Dim oDwg As AcadDocument
        
        For Each oDwg In AcadApplication.Documents
            If oDwg.GetVariable("DBMOD") > 0 And Not oDwg.Name Like "Drawing*" Then
                oDwg.Save
                CommandLine oDwg.Name & " ...Saved"
            Else
                CommandLine oDwg.Name & " ...Not Saved"
            End If
        Next oDwg
    End Sub
    
    
    Sub CommandLine(msg As String)
        ThisDrawing.Utility.Prompt (msg & vbCrLf & "Command: ")
    End Sub
    C:> ED WORKING....


    LinkedIn

  4. #4
    Login to Give a bone
    0

    Default Re: Open Drawings Commands

    Hi Ed,
    You have helped me out in the past. I was just playing around with your SaveAll program. Very cool stuff.
    I like your example For Each loop because it is short and sweet.
    I also did a search on running an AutoLisp program from VBA and read a lot of posts.
    How would I add code to run a AutoLisp routine in you For Each loop?
    Thanks for you help.
    Terry

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

    Default Re: Open Drawings Commands

    VBA is not a good choice for trying to run lisp like that because the lisp will run asynchronously. That's why I suggested you use vba to do the few commands you listed. If you use acad 2015 then you have another choice in .NET for mixing lisp into your code.

    VBA works ok where you call a lisp and then the vba finishes, after which the lisp will run. But not where you want to execute some lisp, have it return and then continue with vba execution.
    C:> ED WORKING....


    LinkedIn

Similar Threads

  1. Replies: 3
    Last Post: 2012-06-17, 09:42 PM
  2. Replies: 2
    Last Post: 2011-04-28, 02:04 AM
  3. Allow scrolling of commands from multiple drawings in same session
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 0
    Last Post: 2006-11-06, 09:24 PM
  4. Replies: 5
    Last Post: 2006-06-14, 09:06 PM
  5. Dialog box does not display when using commands like - Open / SaveAs
    By Glenn Pope in forum AutoCAD FAQ (Read only)
    Replies: 0
    Last Post: 2005-03-16, 05:06 PM

Posting Permissions

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