Author Topic: Autocad.activate or Autocad.setfocus  (Read 6051 times)

0 Members and 1 Guest are viewing this topic.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Autocad.activate or Autocad.setfocus
« on: October 04, 2007, 11:33:41 AM »
I dont know if this can be done, Im sure it can.  What im trying to do is during DEBUGGING/TESTING only, I would like to step into a sub, and I would like to make autocad have the focus.  I set breakpoints, so the code will stop.  My problem is sometimes when I am stepping through the code, VBA expects me to pick something, and when I try to switch over to that window, I end up picking somewhere else.
I know if I am trying to get excel I can do it using

Code: [Select]
            Set objExcel = CreateObject("Excel.Application")
            objExcel.UserControl = True
            objExcel.Visible = True

but Im trying to do it from in the IDE
« Last Edit: October 04, 2007, 01:25:07 PM by CmdrDuh »
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

ML

  • Guest
Re: Autocad.activate or Autocad.setfocus
« Reply #1 on: October 16, 2007, 12:42:03 PM »

Not sure what you are trying to do precisely CM??


David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Autocad.activate or Autocad.setfocus
« Reply #2 on: October 19, 2007, 09:52:41 AM »
when Im debugging, using F8 to step thru the code, when it gets to a pick point or select object, I would like to send focus to acad w/o me having to click on it(which sometimes results in mispicks, which fires error checking in the code Im debugging)
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

ML

  • Guest
Re: Autocad.activate or Autocad.setfocus
« Reply #3 on: October 19, 2007, 10:20:08 AM »

OK, I understand now :)
That is interesting; I just took a few minutes to look into it
There must be a method to get back into The drawing environment with code.
Assuming that is what you are looking for?

The blue button we use to access ACAD from VBA triggers the host document filename.

So, how do we translate that to code? That is the question.......

I noticed there is an Acadview object but I am not sure that I am on the right track

If I get some time later, I will definetely try to get you an answer.

Mark

ML

  • Guest
Re: Autocad.activate or Autocad.setfocus
« Reply #4 on: October 23, 2007, 04:27:54 PM »

CM,

I think this may be what you are looking for

Put this is your code before having the user make the selection
Code: [Select]
Application.VBE.MainWindow.Visible = False

Mark

Bob Wahr

  • Guest
Re: Autocad.activate or Autocad.setfocus
« Reply #5 on: October 23, 2007, 07:37:54 PM »
I don't see any way for this to work.  If you are stepping through the code, you are executing one line of code at a time.  If you change focus on the line preceding the selection, you can't hit F8 to get to the selection.  If it is the next line, you can't step to it until after you select.  It would be awesome to have but it seems to me like a conundrum giving an enigma to a mystery.  Maybe an external app that would switch focus to autocad when it was waiting for a selection but I don't know.

ML

  • Guest
Re: Autocad.activate or Autocad.setfocus
« Reply #6 on: October 24, 2007, 09:34:01 AM »

Yeah

I don't know; I am sure I am understanding the exact need but that one line of code will certainly give focus  to ACAD without clicking anything.

May be you could write a sub or function that will say

If this happens, then
 
Code: [Select]
Application.VBE.MainWindow.Visible = False  'Give focus to ACAD
 
End If

Not sure :(

Mark

ML

  • Guest
Re: Autocad.activate or Autocad.setfocus
« Reply #7 on: October 24, 2007, 09:34:29 AM »

Sorry, I meant, I am not totally understanding

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Autocad.activate or Autocad.setfocus
« Reply #8 on: October 24, 2007, 12:47:21 PM »
I think Bob said it best, in that how is VBA supposed to know if Im hitting F8.  I think it cant be done.  Oh well
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

ML

  • Guest
Re: Autocad.activate or Autocad.setfocus
« Reply #9 on: October 24, 2007, 02:04:02 PM »

Hold on there man

Let's try one silly little thing

ML

  • Guest
Re: Autocad.activate or Autocad.setfocus
« Reply #10 on: October 24, 2007, 02:18:25 PM »

I don't think this will work:
The syntax makes sense but I don't know how you would trigger it

Mark

Code: [Select]
If SendKeys = "{F8}"
 Then Application.VBE.MainWindow.Visible = False
End If

ML

  • Guest
Re: Autocad.activate or Autocad.setfocus
« Reply #11 on: October 24, 2007, 02:20:08 PM »

I just answered your question above CM
That is how ACAD will know you hit F8

How to make it trigger on the particular event you need it to, I am not sure

Mark

Bob Wahr

  • Guest
Re: Autocad.activate or Autocad.setfocus
« Reply #12 on: October 24, 2007, 02:45:40 PM »
ML, I'm not sure you've got what he wants correctly.  He's talking about using F8 to step through his code one line at a time in the VBAIDE.  When input is needed in acad, such as a selection, he wants focus to switch to the acad window.  If you use Application.VBE.MainWindow.Visible = False while stepping through code, it just flashes the IDE off for the split second that it takes to get to the next line of code.  I tried the old awesomey acad sample events code dvb to see if a selection fired any events and it doesn't appear to.  I used the code below.  The object modified event fires when the width is changed but that's the only event that fired for me.


Code: [Select]

'      AutoCAD 2000
'
'      Events Example Code ActiveX Automation.
'
'      Copyright (C) 1999 by Autodesk, Inc.
'
'      Permission to use, copy, modify, and distribute this software
'      for any purpose and without fee is hereby granted, provided
'      that the above copyright notice appears in all copies and
'      that both that copyright notice and the limited warranty and
'      restricted rights notice below appear in all supporting
'      documentation.
'
'      AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
'      AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
'      MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK, INC.
'      DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
'      UNINTERRUPTED OR ERROR FREE.
'
'      Use, duplication, or disclosure by the U.S. Government is subject to
'      restrictions set forth in FAR 52.227-19 (Commercial Computer
'      Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
'      (Rights in Technical Data and Computer Software), as applicable.
'
Option Explicit

Public WithEvents PLine As AcadLWPolyline       ' Use with Modified Event Example

Public WithEvents ACADApp As AcadApplication    ' Use with Application Event Examples


'------------------------------------------------------------------
' Document Events
'------------------------------------------------------------------
Private Sub AcadDocument_Activate()
    ' This example intercepts a drawing Activate event.
    '
    ' This event is triggered when a drawing window becomes active.
    '
    ' To trigger this example event: Either open a new drawing or switch from
    ' one drawing window to another

    MsgBox "You have just activated a drawing!"
End Sub

Private Sub AcadDocument_BeginClose()
    ' This example intercepts a drawing BeginClose event.
    '
    ' This event is triggered when a drawing receives a request to close.
    '
    ' To trigger this example event: Close an open drawing

    MsgBox "A drawing has just been closed!"
End Sub

Private Sub AcadDocument_BeginCommand(ByVal CommandName As String)
    ' This example intercepts a drawing BeginCommand event.
    '
    ' This event is triggered when a drawing receives
    ' any command compatible with this event.
    '
    ' To trigger this example event: Issue any command to an open drawing from
    ' either the command line, VBA, the ACAD menus, the ACAD toolbars, or LISP.

    ' Use the "CommandName" variable to determine which command was started
    MsgBox "A drawing has just been issued a " & CommandName & " command."
End Sub




<whacked a big chunk out here because my post was too long>





'----------------------------------------------------------------------------
' Modified (PLINE) Event Sample
'----------------------------------------------------------------------------

Sub Example_Modified()
     ' This example creates a light weight polyline in model space and
     ' references the new PolyLine using the public variable (PLine) which
     ' is setup to intercept Modified events.
     '
     ' This example then modifies the new object, triggering the code
     ' in the Modified event.
   
    Dim points(0 To 9) As Double
   
    ' Define the 2D polyline points
    points(0) = 1: points(1) = 1
    points(2) = 1: points(3) = 2
    points(4) = 2: points(5) = 2
    points(6) = 3: points(7) = 2
    points(8) = 4: points(9) = 4
       
    ' Create a light weight Polyline object in model space
    '
    ' * Note: We are returning the new PolyLine object into a Module
    ' level variable.  This allows us to intercept events associated
    ' with that particular object.
    Set PLine = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)
   
    ThisDrawing.Application.ZoomAll
   
    ' Modify object to trigger event.
    '
    ' * Note: The event code for the PolyLine modification will be triggered
    ' before we move forward and refresh the view, so the line will not
    ' appear red when the event message box is displayed
    PLine.color = acRed

    ThisDrawing.Regen acAllViewports
   
End Sub

Private Sub PLine_Modified(ByVal pObject As AutoCAD.IAcadObject)
    ' This example intercepts an object's Modified event.
    '
    ' This event is triggered when an object supporting this event is modified
    '
    ' To trigger this code: Modifiy an object connected to this event
    ' * Note: By connected, we mean the object setup to intercept events using
    ' the VBA WithEvents statement

    ' Use the "pObject" variable to determine which object was modified
    MsgBox "You just modified an object with an ID of: " & pObject.ObjectID
   
End Sub



Sub test()
Dim objPL As AcadLWPolyline
Dim varPnt As Variant
ThisDrawing.Utility.GetEntity objPL, varPnt
objPL.ConstantWidth = 1

End Sub

ML

  • Guest
Re: Autocad.activate or Autocad.setfocus
« Reply #13 on: October 24, 2007, 02:58:22 PM »

Hi Bob

I actually did understand what he wanted but I have no clue how to get there; I was just grasping for straws
CM, said, how will ACAD know when I hit F8? Well I just said how.

Code: [Select]
If SendKeys = "{F8}"
 'whatever code you want
End If

I also said that I don't know how to do want he needs.

Oh well, we can't have every thing, right :)

Mark