Author Topic: Load-Run-Unload a VBA Project with VLISP  (Read 7812 times)

0 Members and 1 Guest are viewing this topic.

ML

  • Guest
Load-Run-Unload a VBA Project with VLISP
« on: April 21, 2008, 05:32:54 PM »

Hi
A Fellow Swampster turned me onto this bit of code

Code: [Select]
(defun c:Command ()
(LOADER "Projectname.dvb")
(VL-VBARUN "Projectname.dvb!Module")
(command "vbaunload" "Projectname.dvb")
 )

(defun loader (progname /)
(vl-vbaload (findfile progname))
)

It will load your project, run the macro then unload the project.

I really like the idea for a number of reasons and it works great.

However, if I have a macro that requires the user to pick something, then there is a problem

I used the code with a macro that is asking the user to pick a blockref and here is the result:

Code: [Select]
Command: test

_.-VBARUN

Macro name: Tools.dvb!Blocklayers.BlockonlayersLoop Pick a blockrefvbaunload

It is issuing the vbaunload command before the user gets to select the blockref...

Does anyone know how I may be able to pause the unload until the user escapes or after they are done picking?

Thank you,
Mark

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Load-Run-Unload a VBA Project with VLISP
« Reply #1 on: April 21, 2008, 06:24:24 PM »
can you post your dvb or the code in it so we can see whats happening?
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)

Bob Wahr

  • Guest
Re: Load-Run-Unload a VBA Project with VLISP
« Reply #2 on: April 21, 2008, 07:06:13 PM »
What the vlisp says is this:
  • Load a DVB
  • as soon as you possibly can, run this Macro in that DVB
  • as soon as you possibly can, unload the DVB
What AutoCAD is thinking while it does it:
Load the DVB
gotta run the macro but I'm busy
gotta run the macro but I'm busy
gotta run the macro but I'm busy
gotta run the macro but I'm busy
Run the macro
gotta unload the DVB but I'm busy
gotta unload the DVB but I'm busy
gotta unload the DVB but I'm busy
gotta unload the DVB but I'm busy
gotta unload the DVB but I'm busy
gotta unload the DVB but I'm busy
gotta unload the DVB but I'm busy
Unload the DVB


What's happening to you is that as soon as you allow user input, autocad is no longer busy and is waiting for input.  your vlisp gives it the input at the earliest possible moment which is exactly what you told it to do.

ML

  • Guest
Re: Load-Run-Unload a VBA Project with VLISP
« Reply #3 on: April 21, 2008, 08:26:35 PM »

Bob

I think ACAD needs to practice a little more patience.
Geeeez and to think how patient we are with ACAD  :-(

So, there is no way to pause it while the user picks?

I noticed that no matter what method I heave used to unload the project; if there needs to be user input in VBA, there seems to be no way to unload it programatically.

CM,
It is the project that we did where you pick the blocks and it returns the layers from the block def table.
Remember you helped write the loop part.
Still, the point is, no matter what the project, if user input is required, it looks like a manual unload is the only way.
I hope I am wrong.

Mark

Bob Wahr

  • Guest
Re: Load-Run-Unload a VBA Project with VLISP
« Reply #4 on: April 22, 2008, 11:19:23 AM »
Don't have a lot of time right now, definitely not enough to figure out the lispy bits but what about a lisp equivalent of this that could be run from the last line of the macro

Code: [Select]
sub unloadify(strMacro as string)
Dim PauseTime, Start
    PauseTime = 1
    Start = Timer
    Do While Timer < Start + PauseTime
    Loop  'The pause so you give time for the macro to finish before trying to unload
thisdrawing.sendcommand "vbaunload" "Projectname.dvb"

It's clunky but it should work.  Question though, why do you want to unload it after use anyway?  Is leaving a DVB loaded after use any worse than leaving a LSP loaded?

ML

  • Guest
Re: Load-Run-Unload a VBA Project with VLISP
« Reply #5 on: April 22, 2008, 11:35:33 AM »

Hey Bob
I am looking at your macro but I will answer you question first.
I prefer to unload a project if I am not using it but the bigger question is
If a VBA Project is being shared amongst different users and you need to edit it, how would you edit it if it is loaded on someones machine? I always get a read only message.

So, I was thinking that if you let the macro do it's thing, then unload, you can edit it anytime during the day without figuring out who has it loaded, then having to contact them and explain how to unload it.

With LISP, as far as I have seen, you can keep the routine loaded and still edit it.
Once the routine is updated, as long as it is re loaded, the user will get the update.

Please correct me if I am wrong.

I will go look at your macro now

Thank you
Mark

Bob Wahr

  • Guest
Re: Load-Run-Unload a VBA Project with VLISP
« Reply #6 on: April 22, 2008, 11:54:34 AM »
Makes sense.  I don't edit the copy that's in use, I edit a development copy and then replace it at the end of the day.  I've had a couple of times that the files needed to be updated immediately.  I told everyone to close acad so I could perform maintenance, then told them to open it again, but the world don't move to the beat of just one drum.  What might be right for you, may not be right for some.

ML

  • Guest
Re: Load-Run-Unload a VBA Project with VLISP
« Reply #7 on: April 22, 2008, 12:05:26 PM »

Hey, that's what I'm talking about Willis :)

ML

  • Guest
Re: Load-Run-Unload a VBA Project with VLISP
« Reply #8 on: April 22, 2008, 12:33:54 PM »

Bob

Your deployment method would make total sense with the acad.dvb file as that is inherently loaded all of the time on the users machines; otherwise, I'd rather save the trouble of deploying each night
I wonder, can one Acad.dvb be shared?

I know that here we share .pc3 files and despite the fact that there is one that says custom.pc3, there is always that user that just wants to always skate up hill.

So, we simply over ride the .pc3 files every night.

That will put some slush under his blades :)

Mark


Bob Wahr

  • Guest
Re: Load-Run-Unload a VBA Project with VLISP
« Reply #9 on: April 22, 2008, 12:52:24 PM »
I know that here we share .pc3 files and despite the fact that there is one that says custom.pc3, there is always that user that just wants to always skate up hill.
I check them into the boards.  A standard that isn't standard, isn't a standard at all.  YMMV.  If I had an employee that was causing me to overwrite standard files daily, I would have one fewer employee.

ML

  • Guest
Re: Load-Run-Unload a VBA Project with VLISP
« Reply #10 on: April 22, 2008, 01:39:02 PM »

I would obviously speak to them about it first; it they then blatantly dis regarded standards, I guess I would go to the next step.
Fortunately and unfortunately, I do not have that sort of authority here.

Some companies are too lax ed about standards and are perhaps a bit too timid to insist that people conform.
I guess those companies need a little more fuzz on their kiwis.

ML

  • Guest
Re: Load-Run-Unload a VBA Project with VLISP
« Reply #11 on: April 22, 2008, 01:43:46 PM »

Bob,

I am looking at your code
Code: [Select]
sub unloadify(strMacro as string)
Dim PauseTime, Start
    PauseTime = 1
    Start = Timer
    Do While Timer < Start + PauseTime
    Loop  'The pause so you give time for the macro to finish before trying to unload
thisdrawing.sendcommand "vbaunload" "Projectname.dvb"

Please correct me if I am wrong...
Now, this is intended to be a separate sub routine, is that correct?
Also, should this line say sub unloadify(Projectname as string)  ?

Thanks
Mark

ML

  • Guest
Re: Load-Run-Unload a VBA Project with VLISP
« Reply #12 on: April 22, 2008, 02:23:29 PM »

Bob
I said it before and I will say it again;
You the man!

I think you missed a few enters in the sendcommand but I got it
Code: [Select]
Dim PauseTime, Start
 ProjName = "Projectname.dvb"
 PauseTime = 1
 Start = Timer
 Do While Timer < Start + PauseTime
 Loop  'The pause so you give time for the macro to finish before trying to unload
 ThisDrawing.SendCommand "vbaunload" & vbCr & ProjName & vbCr

Here is the result:
Code: [Select]
Sub BlockonlayersLoop() 'This Sub will keep prompting for the next block until user escapes.
      Dim B As AcadBlock
      Dim ent As AcadEntity
      Dim P
      Dim LayerCol As New Collection
      Dim slayer As String
      Dim Picked As Boolean
      Dim i As Integer
      Dim PauseTime, Start 'Bob's Code
           
      PauseTime = 1 'Bob's Code
      Start = Timer 'Bob's Code
     
      Do While Timer < Start + PauseTime 'This pause gives time for the macro to finish before trying to unload 'Bob's Code
      Do
       On Error Resume Next
       ThisDrawing.Utility.GetEntity ent, P, "Pick a blockref"
       If Not TypeOf ent Is AcadBlockReference Then
        Picked = False
        GoTo ExitOut
       Else
        Picked = True
       End If
       If ent Is Nothing Then
        Picked = False
        GoTo ExitOut
       Else
        Picked = True
       End If
       
       Set B = ThisDrawing.Blocks(ent.Name)
       Debug.Print "The block " & B.Name & " uses the following layers:"
       
       For Each ent In B
        slayer = ent.Layer
        For i = 1 To LayerCol.Count
         If LayerCol(i) = slayer Then GoTo Skip
        Next
        LayerCol.Add slayer
Skip:
        Next
        For i = 1 To LayerCol.Count
         Debug.Print LayerCol(i)
        Next
ExitOut:
        Dim Num As Integer
         For Num = 1 To LayerCol.Count
          LayerCol.Remove 1
         Next
        Loop Until Picked = False
       Loop
       ThisDrawing.SendCommand "vbaunload" & vbCr & "Tools.dvb" & vbCr 'Bob's Code
     End Sub       

It seems to be working like a charm

Thank you sir!

Bob Wahr

  • Guest
Re: Load-Run-Unload a VBA Project with VLISP
« Reply #13 on: April 22, 2008, 02:31:45 PM »
I was actually suggesting that you do a lisp equivalent of the sub to unload it, just to stick closer to what you were trying, i just didn't have the time to figure out how to pass info to a lisp or how to pause for a specified time period.  Glad you're satisfied.

ML

  • Guest
Re: Load-Run-Unload a VBA Project with VLISP
« Reply #14 on: April 22, 2008, 02:41:26 PM »

I see

Unfortunately I am not very good with LISP
That LISP routine was passed onto me by CM.

It is a nice routine, I just don't know how to edit it the way you were suggesting.

"If" you get time, I would certainly love to see it

This method works nicely too, doesn't it?

Mark