TheSwamp
Code Red => VB(A) => Topic started by: jura on September 01, 2004, 03:24:33 AM
-
I've got this small vba routine for setting osnap values:
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:
^C^C(command "VBASTMT" "SnapToggle(256)");
Is it possible to use this routine transparent???
-
The routine is called with:
^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.
-
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.
-
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.
-
same here Daron!!!
Jura calling Keith or Trev!!! come in plz..... :wink: (or any other mastermind)
-
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:
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
-
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,
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.
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)
-
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
(defun C:TOS()
(setvar "USERI2" 10)
)
VBA
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
-
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:
(defun C:TOS (10)
nil
)
Now lets change the BeginLisp to this:
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:
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