Author Topic: using vba routine transparent  (Read 2861 times)

0 Members and 1 Guest are viewing this topic.

jura

  • Guest
using vba routine transparent
« on: September 01, 2004, 03:24:33 AM »
I've got this small vba routine for setting osnap values:

Code: [Select]

Sub SnapToggle(VarSnapType As Integer)
Dim VarOsmode As Integer
Dim VarAftrek As Integer
Dim VarOsmodeOrg As Integer

VarOsmode = ThisDrawing.GetVariable("osmode")
VarOsmodeOrg = ThisDrawing.GetVariable("osmode")
VarAftrek = 16384

While VarAftrek > VarSnapTyp
VarAftrek = VarAftrek / 2
If VarOsmode > VarAftrek Then VarOsmode = VarOsmode - VarAftrek
Wend

If VarOsmode = VarSnapType Then VarOsmodeOrg = VarOsmodeOrg - VarSnapType
If VarOsmode < VarSnapType Then VarOsmodeOrg = VarOsmodeOrg + VarSnapType

ThisDrawing.SetVariable ("osmode"), VarOsmodeOrg
End Sub



The routine is called with:
Code: [Select]

^C^C(command "VBASTMT" "SnapToggle(256)");



Is it possible to use this routine transparent???

daron

  • Guest
Re: using vba routine transparent
« Reply #1 on: September 01, 2004, 08:43:31 AM »
Quote from: jura

The routine is called with:
Code: [Select]

^C^C(command "VBASTMT" "SnapToggle(256)");



Is it possible to use this routine transparent???


Not with how you're calling it. You can't do anything transparent when you have command in the code. Try vbaload and vbarun.

jura

  • Guest
using vba routine transparent
« Reply #2 on: September 01, 2004, 08:55:56 AM »
Could you specify that a little futher Daron?

The routine is loaded on start up so that's no problem. But it won't work with vbarun, cause i need to transfer a variable from the command line to vba. (i use the same routine with different variables) If there is an other sollution please let me know.

daron

  • Guest
using vba routine transparent
« Reply #3 on: September 01, 2004, 08:58:13 AM »
I'm going to have to defer to Keith or Trev on that one. I too am still trying to wrap my head around vba. Every time I get started, I have to stop and by the time I get started again, I can't remember how to start.

jura

  • Guest
using vba routine transparent
« Reply #4 on: September 01, 2004, 09:01:00 AM »
same here Daron!!!


Jura calling Keith or Trev!!! come in plz.....  :wink: (or any other mastermind)

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16727
  • Superior Stupidity at its best
using vba routine transparent
« Reply #5 on: September 01, 2004, 12:08:15 PM »
Ok, let me first say that it is not possible to send a variable to VBA from the LISP environment OR from the command line directly .... or at least it has not been shown to be able to do directly.

All is not lost though.....we can solve this problem with a couple of simple changes ....
1) make the function NOT take an argument
2) Dim the variable VarSnapType
3) add code to grab the value of "useri1" and put it in VarSnapType
4) correct the spelling of "VarSnapTyp" in line 10
5) vbastmt will not execute functions, use -vbarun instead

Now as far as calling VBA routines transparently.... you cannot ....

BUT

you CAN create a reactor that will do the job for you.

Lets do it like this ...
1) Rewrite the function as I have indicated above.
2) Add this code to the ThisDrawing window:

Code: [Select]
Private Sub AcadDocument_BeginLisp(ByVal FirstLine As String)
 If StrConv(FirstLine, vbUpperCase) = "C:TOS" Then
  ThisDrawing.SnapToggle
 End If
End Sub


You will have to work on the rest to get it right... but there is ALWAYS a way... only it does not always seem efficient

Now create a lisp program to set the value of USERI1
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

jura

  • Guest
using vba routine transparent
« Reply #6 on: September 02, 2004, 03:46:15 AM »
Keith,

I almost got it working.
Rewriting this in lisp would probebly be easier, but working with vba is a good practice for me.

I don't get the last part. What does the reactor do exactly. As i read through it it seems like you want to execute snaptoggle when "TOS" is typed at the command line. Unfortunately nothing happens when i type "TOS". Does it need to be called from a lisp routine?

If the global routine is writen in ThisDrawing part, does that mean that it's stored in the drawing itself?


[/code]

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16727
  • Superior Stupidity at its best
using vba routine transparent
« Reply #7 on: September 02, 2004, 08:33:02 AM »
Quote from: jura
Keith,

I almost got it working.
Rewriting this in lisp would probebly be easier, but working with vba is a good practice for me.

I don't get the last part. What does the reactor do exactly. As i read through it it seems like you want to execute snaptoggle when "TOS" is typed at the command line. Unfortunately nothing happens when i type "TOS". Does it need to be called from a lisp routine?

I suppose I should have clarified that is what you should define and use as a lisp, or change it to the function name you are using.

The reason is that the Begin_Lisp reactor returns the first line of the executing lisp, it allows you to identify the function by its name by simply extracting the first few characters and applying it to a comparison. The VBA will then run transparently whenever you run that particular LISP program.
It is quite a neat way to handle the situation seeing that you cannot use 'vbarun or 'vbastmt.

Quote from: jura

If the global routine is writen in ThisDrawing part, does that mean that it's stored in the drawing itself?


No, it is written in the acad.dvb (or whatever you name it)
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

jura

  • Guest
using vba routine transparent
« Reply #8 on: September 02, 2004, 10:28:01 AM »
No progress at all. I'm feeling dumber by the minute here.

Still i must be doing something wrong, would you be so kind to check this.

LISP
Code: [Select]

(defun C:TOS()
(setvar "USERI2" 10)
)


VBA
Code: [Select]

Private Sub AcadDocument_BeginLisp(ByVal FirstLine As String)
 If StrConv(FirstLine, vbUpperCase) = "C:TOS" Then
  ThisDrawing.SnapToggle
 End If
End Sub

Sub SnapToggle()
Dim VarOsmode As Integer
Dim VarAftrek As Integer
Dim VarOsmodeOrg As Integer
Dim VarSnapType As Integer

VarSnapType = ThisDrawing.GetVariable("Useri2")

VarOsmode = ThisDrawing.GetVariable("osmode")
VarOsmodeOrg = ThisDrawing.GetVariable("osmode")
VarAftrek = 16384

While VarAftrek > VarSnapType
VarAftrek = VarAftrek / 2
If VarOsmode > VarAftrek Then VarOsmode = VarOsmode - VarAftrek
Wend

If VarOsmode = VarSnapType Then VarOsmodeOrg = VarOsmodeOrg - VarSnapType
If VarOsmode < VarSnapType Then VarOsmodeOrg = VarOsmodeOrg + VarSnapType

ThisDrawing.SetVariable ("osmode"), VarOsmodeOrg
End Sub

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16727
  • Superior Stupidity at its best
using vba routine transparent
« Reply #9 on: September 02, 2004, 12:02:46 PM »
After looking at the code I realize that a couple of things are happening.
The VBA SnapToggle will fire before the lisp completes, so lets do this.....

Change the TOS program to this:
Code: [Select]

(defun C:TOS (10)
nil
)

Now lets change the BeginLisp to this:
Code: [Select]

Private Sub AcadDocument_BeginLisp(ByVal FirstLine As String)
 If StrConv(FirstLine, vbUpperCase) = "C:TOS" Then
  ThisDrawing.SnapToggle (Mid$,FirstLine,6,3)
 End If
End Sub


and change the SnapToggle to this:
Code: [Select]

Sub SnapToggle( VarSnapType As Variant)
Dim VarOsmode As Integer
Dim VarAftrek As Integer
Dim VarOsmodeOrg As Integer

VarOsmode = ThisDrawing.GetVariable("osmode")
VarOsmodeOrg = ThisDrawing.GetVariable("osmode")
VarAftrek = 16384

While VarAftrek > VarSnapType
VarAftrek = VarAftrek / 2
If VarOsmode > VarAftrek Then VarOsmode = VarOsmode - VarAftrek
Wend

If VarOsmode = VarSnapType Then VarOsmodeOrg = VarOsmodeOrg - VarSnapType
If VarOsmode < VarSnapType Then VarOsmodeOrg = VarOsmodeOrg + VarSnapType

ThisDrawing.SetVariable ("osmode"), VarOsmodeOrg
End Sub
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal