Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

AutoLisp VS VBA

16 REPLIES 16
SOLVED
Reply
Message 1 of 17
Amremad
1773 Views, 16 Replies

AutoLisp VS VBA

hi

i have a problem in my vba and autolisp code and i hope to find a sloution of my problem here

 

my problem is :

 

IN VBA i have a function like  -->

      Public Function ShowMessage (str as string)

          msgbox str

     End Function

 

no i will use the lisp code to call my function by it

defun c:EB ()    ( vl-vbarun  "C:/AMR LISP/AMRVB.dvb!MYMedoule.ShowMessage("hello")")

 

the red word is my problem how can i send this string to vba function by autolisp to show it in message

 

thanks for help

16 REPLIES 16
Message 2 of 17
ProfWolfMan
in reply to: Amremad

Hi,

 

As i know vl-vbarun function used to call vba macro only. 

 

We can not call any function in the module directly from vl-vbarun.

 

We can call only macro.In which we can call other functions in that vba project.

 

-G

 

 

 

Thanks & Regards,
G
Message 3 of 17
Amremad
in reply to: ProfWolfMan

 i  have a lot of value for this function

say 100 value for one function

by ur solution i must create 100 function for each value so i will create 100 command for each function i think this is very hard to use

 

just i want  to send alot of value for one function i hope u understand me

sorry for my english

Message 4 of 17
ProfWolfMan
in reply to: Amremad

Hi,

 

Only problem is vl-vbarun can call only macro which can not have arguments.

 

Here you do not need to create 100 functions.

 

You just create a macro set a looping function.

From that you call your function passing different value each time.

 

Now you can call that macro using vl-vbarun.

 

-G

 

 

Thanks & Regards,
G
Message 5 of 17
Amremad
in reply to: ProfWolfMan

I think you meant like this :

 

LISP Code :

 

(defun c:ax () (command "-vbarun" "C:/AMR LISP/AMRVB.dvb!ADVANCED_LIST.ShowMessage" "hello"))

 

 

VBA Code :

 

Public Function ShowMessage()
Dim str As String
Const HasSpaces = False
str = UCase(ThisDrawing.Utility.GetString(HasSpaces))

MsgBox str
End Function

 

 

Message 6 of 17
ProfWolfMan
in reply to: Amremad

S. You done that.

 

The fact is "Visual LISP and VBA has incompatable data types and you cannot to call VBA function with lisp argument". 

 

Other way is you should get input within your vba function. Just call that function thru vl-vbarun.

 

-G

 

Thanks & Regards,
G
Message 7 of 17
Amremad
in reply to: ProfWolfMan

thank you for help

 

i will Accept As Solution

Message 8 of 17
Amremad
in reply to: Amremad

Mr  ProfWolfMan if you can help in this topic i will be happy thank you

 

How Can I load my VBA using LISP From Current Path

Message 9 of 17
_gile
in reply to: Amremad

Hi,

 

You can use this routine to avoid using VBA.

 

 

;;; Val buttons
;;; 0   OK
;;; 1   OK Cancel
;;; 2   Abort Retry Ignore
;;; 3   Yes No Cancel
;;; 4   Yes No
;;; 5   Retry Cancel
;;; +   icons
;;; 16  Alert
;;; 32  Question
;;; 48  Exclamation
;;; 64  Information
;;;
;;; Val return
;;; 1   OK
;;; 2   Cancel
;;; 3   abort
;;; 4   Retry
;;; 5   Ignore
;;; 6   Yes
;;; 7   No

(defun MsgBox (title buttons message time / reply WshShell)
  (vl-load-com)
  (setq WshShell (vlax-create-object "WScript.Shell"))
  (setq	reply	(vlax-invoke
		  WshShell
		  'Popup
		  message
		  time
		  title
		  (itoa buttons)
		)
  )
  (vlax-release-object WshShell)
  reply
)

 

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 10 of 17
Amremad
in reply to: _gile

i don't understand plz explan what's the realation between this and my VBA Function

 

sorry brother

iam watting

Message 11 of 17
Anonymous
in reply to: Amremad

There is no relation between your VBA function and the alternative proposed by _gile. AS he says, this is the VLISP equivalent of the same MsgBox you wan to call in your VBA code, but using this alternative you don't need to deal with the VBA and LISP data compatibility issues. _giles solution is pure VLISP which uses ActiveX capabilities of VLISP and calls the Message box from the  Windows Script Host. This code should be loaded and called as any other LISP programming.

 

And BTW, you should stop investing time in automating AutoCAD with VBA because Autodesk will discard VBA as an API for its products, so there will be no more VBA for AutoCAD in the near future.

Message 12 of 17
Amremad
in reply to: Anonymous

Dear  SomeBuddy

    thank you very much for you help . but the Function ShowMessage was for an example

my problem was in parapmeter not ShowMessage Function , say also i have any other function like this DrawElbow (Type as string),DrawIPE(Size as string),i don't neet how can i showmessage box but i need to send a prameter for my VBA Function Using AutoLisp Command , i hope you understand me ,

 

 

Message 13 of 17
Anonymous
in reply to: Amremad

I understand you, but I hope you understand too that there's no future in VBA (at least for AutoCAD), is dying, if not already dead.

 

But if you still want to invest time in this, then what you need is the Vlax.cls module by Frank Oquendo and you can read more about this at the following address, where you have examples and a link to download the class module.

 

http://autolisp-exchange.com/Forums/Forum6/F6T7P1.htm

 

Or you can read this:

 

http://groups.google.com/group/autodesk.autocad.customization.vba/browse_thread/thread/7161b0a7c58be...

 

Good luck

Message 14 of 17
dgorsman
in reply to: Amremad

You would have to provide the arguments indirectly, such as through one of the USERnnn system variables, a registry entry, or an external file.  The VBA code would then be able to read the data from that location. 

Agressively mixing LISP and VBA this way makes for more trouble than its worth - go with one or the other.  As mentioned its a good idea to keep VBA at arms length, as it will reduce the amount of work you will need to do later on.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


Message 15 of 17
hawstom
in reply to: Amremad

VBA is dying. But if you didn't get your answer, I can help you.

 

Tom

Message 16 of 17
Amremad
in reply to: hawstom

hello Mr.  hawstom

Thx for your rplay

did you read my message 5  in this topic ?

 

is there another soulition for my problem ?

 

 

iam waitting your reply

 

thank you for help


Message 17 of 17
hawstom
in reply to: Amremad

As others here have said, it's true you can't do this:

 

 

(command "-vbarun" "C:/AMR LISP/AMRVB.dvb!ADVANCED_LIST.ShowMessage" "hello")

What you can do is this:

 

(defun c:ax () (setvar "users1" "hello")(command "-vbarun" "C:/AMR LISP/AMRVB.dvb!ADVANCED_LIST.ShowMessage"))

Then inside your vba, you can read users1 like this:

strHello = AutoCAD.Application.ActiveDocument.GetVariable("users1") 

Is that what you wanted?

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost