TheSwamp

CAD Forums => CAD General => Topic started by: hudster on February 12, 2004, 02:25:26 PM

Title: VBA or LSP?
Post by: hudster on February 12, 2004, 02:25:26 PM
I am now at the point where I need to learn how to program custom programs for my companys CAD systems.

So which should I learn VBA or LSP?

Cheers For any advice.
Title: VBA or LSP?
Post by: Mark on February 12, 2004, 02:29:08 PM
I would say autolisp first. because you can get some real work done fairly quickly.
Title: VBA or LSP?
Post by: daron on February 12, 2004, 02:38:27 PM
Learn both. Give Keith, Hendie and Trev something to do.
Title: VBA or LSP?
Post by: hyposmurf on February 12, 2004, 03:58:41 PM
Which would you suggest first though?I've started looking at LISP,looked at VBA briefly.VBA is more pop up buttons though,maybe thats why I found LISP harder as I dont see results as quickly,might go back to VBA.I realise they have different uses,such as LISP is restricted to AutoCAD where as VBA can be used in lts of other programs to,but can someone expand on what I've said,cheers.
Title: VBA or LSP?
Post by: daron on February 12, 2004, 04:09:20 PM
Main reason to learn lisp is two-fold, all you need is a text editor to write it and most people got their start in programming, by learning it. Many of us are proficient in lisp, so it's definately a good place to start because you can get a lot of help with it. We have great vba minds here too. I'd say, decide what your needs are based on HS's post and go that route.
Title: VBA or LSP?
Post by: Spageddie on February 12, 2004, 05:10:02 PM
8) Should really consider what it is you need to achieve....do you need to simply enhance autocad productivity (ie general cad output) or do you need to combine it with other products for output (ie exporting to Excel/Access ect)
You decision should reflect this and not which is easier to learn. 8)
Title: VBA or LSP?
Post by: TR on February 12, 2004, 05:53:22 PM
I say VBA. Lisp is only valuable in AutoCAD, VBA is valuable throughout AutoCAD, MS Office, and a few other programs.

I'm glad I chose VBA over lisp otherwise I wouldn't have been able to do a lot of Excel programming as well as some programming with our document management system.

And daron you can code VBA in a text editor if you really want to.  :D
Title: VBA or LSP?
Post by: daron on February 12, 2004, 06:09:49 PM
I know you can, but you can't open the compiled code in a text editor, which needs to be compiled to run. Lisp does not. That's what I meant. I just couldn't spit it out correctly.
Title: VBA or LSP?
Post by: Keith™ on February 12, 2004, 06:10:44 PM
Basically, LISP has been around for many many years... I believe there is a thread here somewhere detailing it's rise. Essentially the reason that LISP is the language of choice for many cad people is that all of the menus and buttons can be lisp driven without calling the vba environment. In fact, many lisp programs can be written in just a few lines of code, while the same thing in VLisp or VBA requires up to 4 times the amount of coding.

For example..
Draw a line from 0,0,0 to 0,12,0 in lisp
Code: [Select]

(defun C:LINE12()
 (command "_.line" "0,0,0" "0,12,0" "")
)


Draw the same line in VBA
Code: [Select]

Sub line12()
 Dim stpnt(2) As Double
 Dim endpnt(2) As Double
 stpnt(0) = 0#: stpnt(1) = 0#: stpnt(2) = 0#
 endpnt(0) = 0#: endpnt(1) = 12#: endpnt(2) = 0#
 ThisDrawing.ModelSpace.AddLine stpnt, endpnt
End Sub


Now there are 7 lines of code compared to 3...
notwithstanding, you ALSO must either select the VBA command from the macro window or type:
Command: -vbarun
Macro name: ThisDrawing.line12

While in the lisp version you type:
Command: line12

In a button the syntax is exactly the same as above.

Lisp is easier to learn in my opinion, AND it is much more user friendly with there being tons of resources available for lisp programmers. Also it is simple to look at and understand others code while VBA tends to be a whole lot more structured.

I say learn LISP, then when you are comfortable with lisp, particularly with customization, then delve into VBA and VB, finally ARX, C++, .NET and C#

Incedently I hear that .NET is the next "language of choice" for AutoCAD customization.
Title: VBA or LSP?
Post by: hendie on February 13, 2004, 03:46:45 AM
I don't think it really matters which one you start learning first. Within a short time, you are going to be looking at both. Once you start the learning process, adding another language isn't such a big deal.

I started learning Lisp but quickly started learning VBA 'cos I just couldn't bring myself to get into that morass called DCL !
So, basically, if what I propose to do stays completely within Autocad, my first choice is Lisp. If I have to communicate with any other programme I go VBA ~ it's much, much easier ! ~ and if I decide I want any kind of dialogues then I go VBA
I never said I wasn't lazy


at the end of the day the choice is yours.... bet that's helped a lot now hasn't it ?  :P
Title: VBA or LSP?
Post by: hudster on February 13, 2004, 06:58:58 AM
I'm swaying more towards VBA, mainly because I want most things to be driven via dialogue boxes.

i.e. a drawing setup utility that the user selects from a set list of choices and the program does the rest.

Is it difficult to do dialogue boxes via lisp?
Title: VBA or LSP?
Post by: hendie on February 13, 2004, 07:19:43 AM
Quote from: Hudster

Is it difficult to do dialogue boxes via lisp?


BWahahahahhah


splurg phnergle breep !
Title: VBA or LSP?
Post by: SMadsen on February 13, 2004, 08:23:06 AM
Quote from: Hudster
i.e. a drawing setup utility that the user selects from a set list of choices and the program does the rest.

As for drawing setup - when it involves layouts, plotsetup, settings etc., VBA may have a slight advantage over AutoLISP. If it also involves layer setup, title blocks etc., then it may be a draw. AutoLISP is powerfull when it comes to handling entities, especially large quantities.


Quote from: Hudster
Is it difficult to do dialogue boxes via lisp?

Call me a weirdo, but I actually like doing dialog boxes in AutoLISP! Not so much DCL - that's relatively quickly over and done with - but I enjoy coding the dialogs.
You will experience it as frustating and probably jump to VBA - as have many done just because of DCL - but once over that, it can actually grow on you.

I know .. I'm a weirdo!

Anyway, learn AutoLISP and VBA. AutoLISP for the purpose of getting adesk to support this excellent tool in the future, and VBA for the reasons given by the others here. I'm ready to bet that VBA is being replaced very soon, though. ADS was abandoned after what, a few releases, after they got into bed with MS? So, if MS is saying that .NET is the future then ... well, just keep a few books on C# handy.
Title: VBA or LSP?
Post by: daron on February 13, 2004, 09:16:37 AM
Don't forget vb.net. I'm sure they'll make a subset Application form of it to go with autocad.
Title: VBA or LSP?
Post by: SMadsen on February 13, 2004, 09:28:36 AM
If .NET comes in flavors of both VB and C# - like ADS was available to Pascal and C - I'd definately forget about VB.NET  :)
But yes, IDE-wise it'll probably be VB.NET.
Title: VBA or LSP?
Post by: daron on February 13, 2004, 09:41:03 AM
Yup. It does.
Title: VBA or LSP?
Post by: TR on February 17, 2004, 07:01:46 PM
Quote from: Keith
In fact, many lisp programs can be written in just a few lines of code, while the same thing in VLisp or VBA requires up to 4 times the amount of coding.

For example..
Draw a line from 0,0,0 to 0,12,0 in lisp
Code: [Select]

(defun C:LINE12()
 (command "_.line" "0,0,0" "0,12,0" "")
)


Draw the same line in VBA
Code: [Select]

Sub line12()
 Dim stpnt(2) As Double
 Dim endpnt(2) As Double
 stpnt(0) = 0#: stpnt(1) = 0#: stpnt(2) = 0#
 endpnt(0) = 0#: endpnt(1) = 12#: endpnt(2) = 0#
 ThisDrawing.ModelSpace.AddLine stpnt, endpnt
End Sub


Now there are 7 lines of code compared to 3...
notwithstanding, you ALSO must either select the VBA command from the macro window or type:
Command: -vbarun
Macro name: ThisDrawing.line12

While in the lisp version you type:
Command: line12


Sorry, but that's not correct. Your lisp code could be duplicated in VBA with exactly three lines. If you're doing something simple in VBA (like drawing a single line with constant values) there isn't a need to use variables.
Code: [Select]

Public Sub line12()
  Thisdrawing.Utility.SendCommand("line 0,0,0 0,12,0 ")
End Sub


And you could use simple lisp to add the VBA program as a command. That's pretty much all i use lisp for.
Code: [Select]

(defun C:LINE12()
 (command "-vbarun" "c:/pathtodvb/filename.dvb!modulename.line12")
)
Title: VBA or LSP?
Post by: Keith™ on February 18, 2004, 10:48:44 PM
Quote from: Tim Riley
Sorry, but that's not correct. Your lisp code could be duplicated in VBA with exactly three lines. If you're doing something simple in VBA (like drawing a single line with constant values) there isn't a need to use variables.
Code: [Select]

Public Sub line12()
  Thisdrawing.Utility.SendCommand("line 0,0,0 0,12,0 ")
End Sub



I suppose you are correct, but alas, I was refering to the ActiveX methods as opposed to a command sent to the AutoCAD command line. Also SendCommand is not available in R14 VBA,  plus you always get that ugly command line echoing....bleeaaccchhhh

Quote from: Tim Riley
And you could use simple lisp to add the VBA program as a command. That's pretty much all i use lisp for.
Code: [Select]

(defun C:LINE12()
 (command "-vbarun" "c:/pathtodvb/filename.dvb!modulename.line12")
)


You absolutely can and I regularly do where required, but here again, I was refering to the strictly ActiveX VBA comparison to Lisp.

This was intended to be a simple program example not a full fledged code compaction example. If you look at most code there are many ways that you can shorten the length of the code, but most do not because of a lack of understanding of the programming language.
Title: VBA or LSP?
Post by: SMadsen on February 19, 2004, 06:02:36 AM
I always used to say, what good is a language that needs another language to run it? I know that is not exactly true, either, but it does turn out that many people are using lisp to run their macro's (man, alone the words 'macro' and 'module' send shivers down my spine (that's a personal grudge/mental block, though)).

I'll agree with Tim that it was a poor example - both languages use the command pipeline without much difference. They are both talking to the same server.

But the only thing that would keep me from translating a survey file of points to a bunch of lines with a simple expression like (defun line (p1 p2) (entmake (list '(0 . "LINE")(cons 10 p1)(cons 11 p2)))) - as opposed to the "split-points-into-arrays-and-go-through-several-objects-type-of-vba-thing" - would be if AutoLISP were non-existent.
Heck, I could import a 5 Mb survey file at the command line with a few parantheses if I wanted. The guy who proposed to bring XLISP into AutoCAD was a brilliant guy in my eyes :)