Author Topic: Open Drawings Commands  (Read 4025 times)

0 Members and 1 Guest are viewing this topic.

terrycadd

  • Guest
Open Drawings Commands
« on: May 14, 2014, 06:21:02 PM »
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
___________________________________________
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
_______________________________________
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
« Last Edit: May 16, 2014, 03:47:41 PM by terrycadd »

IBIEINIID

  • Guest
Re: Open Drawings Commands
« Reply #1 on: August 15, 2014, 01:13:22 PM »
I'm not familiar with what the arguments used to be for SendCommand, but the current (2015) help file shows the argument format as this: "object.SendCommand Command"

I think it's possible that it's just your format for the command that you're sending. I've used this exact line to regenerate modelspace via the command line through vba, so try to use this format and see if it helps: "acaddoc.SendCommand ("RE ")". (acaddoc is basically ThisDrawing.... I'm running the program through Excel VBA) The space inside the quotes works as if you pressed the enter button or spacebar while typing in the command line. If I knew more about LISP, I could completely reformat your entry strings, but I'm afraid I don't.

Good luck.