Author Topic: plz point me in the right direction VB, LISP??  (Read 12049 times)

0 Members and 1 Guest are viewing this topic.

leebrown5

  • Guest
plz point me in the right direction VB, LISP??
« on: September 07, 2005, 09:13:31 AM »
cuz I'm just a non-code-writtin-fool.  I would benefit from a routine, and I have many parts, heck- I even bought a LISP book.  Unfortunately I can't find the time to make any sense out if it yet.  So I would like a hint on which language best does what I want.  I need to filter for both color, and (line/poly/lwpoly) to end up with theoretically 256 subsets, on which I could run a len summation (real length in ft & in)  I can list colors used, create sel set by color pick, and tally, all by typical amounts of user-intervention (small routines I've found here & elsewhere).  I need to learn how to use that and,or stuff,  whiles and loops, someday.  But as I RTFM and lurk, I notice overlap of languages and little VL stuff dropped here & there.  Can anyone explain which language works best for what?  I'm only working inside acad, all acad entities.

tia- lee

deegeecees

  • Guest
Re: plz point me in the right direction VB, LISP??
« Reply #1 on: September 07, 2005, 09:50:28 AM »
Lee,

Here's the scoop:

Lisp = List Processing
Description (In my own words): Lisp is the oldest programming language native to AutoCad, and is still used for mainly legacy purposes. Pre-existing commands and boolean logic make up the bulk of it. You can do much, but limited.

VLisp = Visual List Processing
Description (In my own words): VLisp was created as a bridge between Lisp and VBA (sortof). You can do everything in VLisp that you would be able to do in Lisp, and then some. Application level events are supported.

VBA = Visual Basic for Applications
Description (In my own words): VBA is probably the most powerful of the 3 (VBA, VLisp, Lisp), because of the ability to take hold of the application level (start AutoCad remotely etc.). You can do the most damage with VBA.

I know there are others here that can elaborate a bit more, so I'll just leave it at that. Hope it helps.  :-D

Deeg

Bob Wahr

  • Guest
Re: plz point me in the right direction VB, LISP??
« Reply #2 on: September 07, 2005, 10:53:06 AM »
Good definitions.  I'll add to it that either lisp or vba can easily do what you want.  For this it really comes down to which language you would rather work in.

Basically, you pick a language and someone here will help get you through the code.
« Last Edit: September 07, 2005, 11:17:01 AM by Bob Wahr »

leebrown5

  • Guest
Re: plz point me in the right direction VB, LISP??
« Reply #3 on: September 07, 2005, 03:07:31 PM »
well- thank-uz very muchly!   that's what I thought.  I guess I'll look at VB, since it's more widely applicable.  Acad is like Cinderella here- the one that gets all the work done, but it's not officially our 'tool'...  designers here say CATIA stands for 'crashed again, try in autocad', but the modelers rule the roost.  My fear is someday they will push us all (designers & modelers) over to Craptia. I'd have to start looking for new employment and perhaps VB would make me more valuable :|
I find the "Swamp" to be aptly named, as my phrase du jour is about the alligators and the swamp......

thanks again.
lee

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: plz point me in the right direction VB, LISP??
« Reply #4 on: September 07, 2005, 03:41:21 PM »
Well to get you started see these.

To select by color: http://www.theswamp.org/forum/index.php?topic=1915.0

And for length: http://www.theswamp.org/forum/index.php?topic=5891.0
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Bob Wahr

  • Guest
Re: plz point me in the right direction VB, LISP??
« Reply #5 on: September 07, 2005, 05:21:53 PM »
This was really quickly plopped together and was pretty down and dirty but should get you well on your way.  I have pretty much given up entirely on commenting my code except in extreme circumstances so try to figure out what I am doing but feel free to ask for an explanation on anything you don't understand.
Code: [Select]
Sub ColwahrLength()
Dim intColor As Integer
Dim objLWPoly As AcadLWPolyline
Dim objPoly As AcadPolyline
Dim objLine As AcadLine
Dim objSelSet As AcadSelectionSet
Dim objSelSets As AcadSelectionSets
Dim intGroup(0 To 7) As Integer
Dim varData(0 To 7) As Variant
Dim strSetName As String
Dim objEnt As AcadEntity
Dim dblTotLength As Double

Set objSelSets = ThisDrawing.SelectionSets
strSetName = "length"
For intColor = 0 To 255
  intGroup(0) = -4: varData(0) = "<AND"
  intGroup(1) = 62: varData(1) = intColor
  intGroup(2) = -4: varData(2) = "<OR"
  intGroup(3) = 0: varData(3) = "LINE"
  intGroup(4) = 0: varData(4) = "POLYLINE"
  intGroup(5) = 0: varData(5) = "LWPOLYLINE"
  intGroup(6) = -4: varData(6) = "OR>"
  intGroup(7) = -4: varData(7) = "AND>"
 
  KillSet strSetName
  Set objSelSet = objSelSets.Add(strSetName)
  objSelSet.Select acSelectionSetAll, , , intGroup, varData

  dblTotLength = 0
  For Each objEnt In objSelSet
    If TypeOf objEnt Is AcadLine Then
      Set objLine = objEnt
      dblTotLength = dblTotLength + objLine.Length
    Else
      If TypeOf objEnt Is AcadPolyline Then
        Set objPoly = objEnt
        dblTotLength = dblTotLength + objPoly.Length
      Else
        If TypeOf objEnt Is AcadLWPolyline Then
          Set objLWPoly = objEnt
          dblTotLength = dblTotLength + objLWPoly.Length
        End If
      End If
    End If
  Next objEnt
  MsgBox "Color " & intColor & " lengths = " & dblTotLength, vbOKOnly, "Lengths for color " & intColor

Next intColor

End Sub


Function KillSet(strSet As String)
  Dim objSelSet As AcadSelectionSet
  Dim objSelSets As AcadSelectionSets
 
  Set objSelSets = ThisDrawing.SelectionSets
     
  For Each objSelSet In objSelSets
    If objSelSet.Name = strSet Then
      ThisDrawing.SelectionSets.Item(strSet).Delete
    Exit For
    End If
  Next

End Function

leebrown5

  • Guest
Re: plz point me in the right direction VB, LISP??
« Reply #6 on: September 09, 2005, 08:43:53 AM »
wow- that was quite unexpected- didn't figured you'd do all the work for me!  Unfortunately you've put me in a rather embarrassing spot :roll:
I don't know what to do with what you gave me!  It sure isn't lisp, which is the only thing I know how to load.  I saved it as a dvb file, 'cause that's what the help said was the file type for VBA.  That didn't work.  can you give me a little hint? :oops:

deegeecees

  • Guest
Re: plz point me in the right direction VB, LISP??
« Reply #7 on: September 09, 2005, 09:21:15 AM »
Want me to handle this one Bob?

Bob Wahr

  • Guest
Re: plz point me in the right direction VB, LISP??
« Reply #8 on: September 09, 2005, 11:22:05 AM »
By all means feel free but I'll get it since I'm here.

  • Type VBAMAN in AutoCAD.
  • On the right side of the dialog box, click the "New" button.
  • In the bottom left corner, click the "Visual Basic Editor" button.

  This brings up the VBA IDE (Integrated Development Environment) which is
  the happy place you edit VBA, much like the Vlisp editor.
  • Since I can't remember what the default state is for the IDE, press F7. 

  If the code pane is up this won't do anything, if not, it will bring it up.
  • Paste the above code into the window.
  • Save the file, this will save it as a DVB.
  • Close your IDE
  • Make a lisp front end to run the sub like:
    Code: [Select]
    (DEFUN C:COLWAHRLENGTH()[/li][/list]
      (vl-vbaload "P:/ehver/you/saved/it/colwahrlength.dvb")
      (vl-vbarun  "colwahrlength")
      (princ)
    )
Ask more questions as you have them.  Be VERY careful about thinking of this as finished code.  This was done quickly as a rough start with very little testing (or thought for that matter).  It still has some work left to do.

On another note, if you are interested in learning VBA, CmdrDuh is running an entry level VBA class here on the board.  You might contact him regarding it.  Just promise him a Jack'nDew, I'm sure he'll fall for that one.

Bob Wahr

  • Guest
Re: plz point me in the right direction VB, LISP??
« Reply #9 on: September 09, 2005, 11:33:30 AM »
If any moderator types trip over this thread, it might want to be moved to a less lispish place.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: plz point me in the right direction VB, LISP??
« Reply #10 on: September 09, 2005, 11:52:18 AM »
I think it's ok where it is since it's a mix of vb / lisp.

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

leebrown5

  • Guest
Re: plz point me in the right direction VB, LISP??
« Reply #11 on: September 09, 2005, 11:59:29 AM »
yipee!!! I looked in the macro pulldown but couldn't figure out where to go with it.  thanx-a-bunch.   also- no I don't expect you'd have a polished product ready to go for me.  I didn't think it was the sort of routine anyone would have pre-done, and I would hate to think you could have completed front to back tested and ready in that short of time.  Really- I'd HATE to think that.  I mean I know I'm jus-a little ol skeeter and youz a big ol bull-frog, but that would be just too darn efficient to think about.....

really, thanks again for the help.
lee

Bob Wahr

  • Guest
Re: plz point me in the right direction VB, LISP??
« Reply #12 on: September 09, 2005, 12:16:14 PM »
I mean I know I'm jus-a little ol skeeter and youz a big ol bull-frog
That's just because I talk too much.  Or type too much I guess.  One thing that might help you in general is when you are in your IDE (which you can open with Alt-F11 BTW), have your locals window open (you can find it in the view menu).  Then step through the code.  F8 will run the code one line at a time.  Pay attention to the things that change in the locals window and try to figure out what the lines of code are actually doing.  After you have gone through a "For" loop a few times and have it figured out, you can type Ctrl-Shift-F8 and it will run the rest of the loop automatically. I would also change the line

  MsgBox "Color " & intColor & " lengths = " & dblTotLength, vbOKOnly, "Lengths for color " & intColor

to

  Debug.Print "Color " & intColor & " lengths = " & dblTotLength
Then you can see the results in the "Immediate" window (It's in the view menu as well) withough having to click OK 256 times.  That msgbox was kind of mean of me in retrospect.
« Last Edit: September 09, 2005, 12:21:55 PM by Bob Wahr »

Bob Wahr

  • Guest
Re: plz point me in the right direction VB, LISP??
« Reply #13 on: September 09, 2005, 12:16:31 PM »
I think it's ok where it is since it's a mix of vb / lisp.

:)
Cool dat

leebrown5

  • Guest
Re: plz point me in the right direction VB, LISP??
« Reply #14 on: September 09, 2005, 01:59:50 PM »
made file as follows

(defun c:colwahrlength()
  (vl-vbaload "C:\Program Files\Autodesk\leecad\bobwahr.dvb")
  (vl-vbarun "colwahrlength")
  (princ)
  )

where  C:\Program Files\Autodesk\leecad contains both the dvb & the lsp


Command: _appload bobwahr.lsp successfully loaded.
Command: colwahrlength
Initializing VBA System...; error: Automation Error. Problem in loading DVB file


where'd I go wrong Bob?........

deegeecees

  • Guest
Re: plz point me in the right direction VB, LISP??
« Reply #15 on: September 09, 2005, 02:03:57 PM »
Change this:

(vl-vbaload "C:\Program Files\Autodesk\leecad\bobwahr.dvb")

to this:

(vl-vbaload "C:\\Program Files\\Autodesk\\leecad\\bobwahr.dvb")

*Notice the double backslash*

leebrown5

  • Guest
Re: plz point me in the right direction VB, LISP??
« Reply #16 on: September 09, 2005, 02:43:19 PM »
ooh- questions, lots of em-
1-why the dbl backslash? never seen that convention before- is it a VBA thing or what?
2- why does this routine see an esc as an enter?  it's non-interuptible when set to the msg box version
3-when it is set to the Debug.Print it doesn't.  print, that is.  or do anything observable except pause.  all those sums are inside somewhere, but I don't know how to retrieve them.
4-units- what does it take to override the default decimal summation ILO architectural?
5-what is the best book to buy?  keeping in mind (a)-I haven't seen anything about programming since BASIC in high school  and (b)-sometimes if I don't feel like I'm getting a clue, I have the attention span of a, well, a mosquito!

lee

Bob Wahr

  • Guest
Re: plz point me in the right direction VB, LISP??
« Reply #17 on: September 09, 2005, 03:26:45 PM »
ooh- questions, lots of em-
good.
Quote from: leebrown5
1-why the dbl backslash? never seen that convention before- is it a VBA thing or what?
Lisp uses backslash as an indicator for special functions so if you want a backslash to work as a backslash, you have to double it.  You can also use a single foreslash in lieu of backslashes for paths in lisp.
Quote from: leebrown5
2- why does this routine see an esc as an enter? it's non-interuptible when set to the msg box version
It's not actually seing esc as enter, when you hit esc, you cancel the message box and the command continues on.  If you want to be able to cancel the routine, you first have to tell the program what cancels the program.
Quote from: leebrown5
3-when it is set to the Debug.Print it doesn't. print, that is. or do anything observable except pause. all those sums are inside somewhere, but I don't know how to retrieve them.
It "prints" to the "Immediate" window in the IDE.  If the Immediate Window isn't showing, you can make it show in the view menu.  Something that you need to decide is what result you want.  The message box is not what you want I'm sure, nor the immediate window, but do you want it to write to a file or what?
Quote from: leebrown5
4-units- what does it take to override the default decimal summation ILO architectural?
That's a little more involved.  VBA doesn't do fractions so if you want the result in feet-inches-fraction, you need to do replace the decimals with fractions.  A function would be a good way to achieve this.
Quote from: leebrown5
5-what is the best book to buy? keeping in mind (a)-I haven't seen anything about programming since BASIC in high school and (b)-sometimes if I don't feel like I'm getting a clue, I have the attention span of a, well, a mosquito!
For VB(A) in General, I would recomend O'Reilly's VB(A) In A Nutshell.  For AutoCAD specific VBA, I would recomend Joe Sutphin's AutoCAD 200x VBA: Programmer's Reference

Bob Wahr

  • Guest
Re: plz point me in the right direction VB, LISP??
« Reply #18 on: September 09, 2005, 03:28:22 PM »
Instead of trying to tackle everything at once, Why don't you pick a single one of the things that you want to change and we'll work through them one at a time.

deegeecees

  • Guest
Re: plz point me in the right direction VB, LISP??
« Reply #19 on: September 09, 2005, 03:57:38 PM »
Quote
For VB(A) in General, I would recomend O'Reilly's VB(A) In A Nutshell. For AutoCAD specific VBA, I would recomend Joe Sutphin's AutoCAD 200x VBA: Programmer's Reference

I've always been partial to George O. Head...

http://www.fetchbook.info/search_George_O._Head/searchBy_Author.html

But its been a long time.

leebrown5

  • Guest
Re: plz point me in the right direction VB, LISP??
« Reply #20 on: September 12, 2005, 08:51:10 AM »
I've got George's AutoLISP in Plain English.  It really is!  Unfortunately I want to go beyond what he covers and I don't seem to have 'gotten it' because I can't use what he describes outside of the examples he gives.   dejavous-calculus and relay circuits.  I get very frustrated until finally the lightbulb goes on.  But I've taken my Ritalin now so I should be better :laugh:

first thing- where can I find an outline of what the nomenclature conventions are.  I've looked in the Acad-of-no-help files and they lead me in circles and down dead-end garden paths!  arghhhh  I want a list of phrases like Dim and Sub and KillSet along with the rules and conventions ForEach.  hee hee. nevermind.

Where can I find the VB4dummies that explains what the formatting rules are- where do hard returns matter, when do I need a space, what is case sensitive?

Bob Wahr

  • Guest
Re: plz point me in the right direction VB, LISP??
« Reply #21 on: September 12, 2005, 11:05:14 AM »
Definitely O'Reilly's In a Nutshell for that.  The in a nutshell books are great.  The first couple of chapters of the Sutphin book give you VBA basics as well though and would give you a more comprehensive reference for the ACAD object model.

deegeecees

  • Guest
Re: plz point me in the right direction VB, LISP??
« Reply #22 on: September 12, 2005, 11:18:18 AM »
Have you taken a look at the books that Bob Wahr suggested? They may have something more than George.

If you open your VBAIDE (command line: vbaide) and access the help files from VBA, you'll get all the functions for VBA (i.e. Sub, Dim, Foreach...). These functions are native to Visual Basic, and can only be found in the VBA help files. AutoCad pays no mind to describing them as it has already been done by MS. There are some AutoCad VBA functions can only be found in the AutoCad Developers Help files. Explore these areas thoroughly and you will soon find out that, short of having someone write a macro for you, these are your reference tools. This is how I learned VB, and I do not recommend learning this way as it has totally tweaked my brain.  :-P


Bob Wahr

  • Guest
Re: plz point me in the right direction VB, LISP??
« Reply #23 on: September 12, 2005, 04:06:26 PM »
Lee,

Have you thought about taking part in CmdrDuh's class?  It is not too far along at the moment.  I think that you could easily catch up and would learn a lot.

leebrown5

  • Guest
Re: plz point me in the right direction VB, LISP??
« Reply #24 on: September 12, 2005, 04:42:46 PM »
 Sorry I sometimes don't follow along well- this is only part of my daily challenge :roll:  I'll look up books at home on amazon.  As far as CmdrDuh- I  forgot about that- who what where?   If it's no bother to add my name on to an email distribution, I can go for that but I'm starting a welding course tommorrow- Tues/Thurs 4:30-7 till Thanksgiving plus I do have a family etc so I don't want to commit someone else's time for my sporadic involvement :wink:

Thanks Bob for the push along to the VB world.  The idea of linking into an xls format, etc is too cool!  I rechecked my AU classes, to make sure I didn't overlook a VB session in favor of lisp, when actually I think now a balance, maybe even in favor of VB.  Correct me if I'm wrong, but I feel like I need the lisp foundation, because it seems to be the primary link between non-native programs and the autocad platform itself.

Bob Wahr

  • Guest
Re: plz point me in the right direction VB, LISP??
« Reply #25 on: September 12, 2005, 05:14:49 PM »
I know enough lisp to run VBA programs and that's about it.  I can semi-follow programs written in lisp but there is no way in hell that I could actually write something in lisp.  It hurts my brain too badly to try.  For writing applications in autocad, flip a coin, they will both do the job admirably.  If you want to get into excel programming or even stand alone programs via VB or VB.NET, then VBA is probably a better route to go.

I linked both of those books on amazon when I first mentioned them although the Sutphin isn't released yet so if you don't want to wait you will have to get the 2004 release.

For the class, it is self paced and takes place on this forum so you should be able to fit it in around your life.  PM CmdrDuh and he can fix you up.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: plz point me in the right direction VB, LISP??
« Reply #26 on: September 15, 2005, 12:02:00 PM »
I got Lee signed up and he is starting to look at the first few docs.  He should be on his way soon.
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: plz point me in the right direction VB, LISP??
« Reply #27 on: September 15, 2005, 12:23:47 PM »
Welcome to the dark side ;)

Andrea

  • Water Moccasin
  • Posts: 2372
Keep smile...

Peter Jamtgaard

  • Guest
Re: plz point me in the right direction VB, LISP??
« Reply #29 on: September 16, 2005, 10:06:32 AM »
I would append some information to the list presented earlier


LISP = LISt Processing or

Strengths
 It is native to the AutoCad command line.
 Doesn't require dimensioning of variables.
 Produces shorter routines, and therefore is faster to code.
 Has good user interface commands for working inside drawings, like selection sets, filters, getxxx functions...
 Lists are very powerful and are not in VB(a)!!!

Weaknesses:
 It is a document Level programming Language
 Dialog control language is more difficult to program than VBA forms.

Visual LISP = Visual LISt Processing
All of the strengths and weaknesses of LISP plus the addition of over 1000 new commands including access to the entire com object model of Autocad and the ability to import and manipulate other applications like word, excel,...


VBA = Visual Basic for Applications
Strengths
 It is an Application Level programming Language
 VBA forms are easier to develop.
 Intellisense in the VBAIDE helps new programmers to navigate the application model
 Operates external applications easier than lisp
Weaknesses
 Requires Dimensioning Variables
 Code is usually longer and requires more time to develop.
 Does allow use of Lists and Arrays are not as versitile and more difficult to manipulate.
 Is not native to the Autocad command line and require extra steps to call from Autocad.
 More difficult user entry.


My 2 cents is:
Use VLISP for all drawing level programs and drafting tools that do not require dialog controls.
Use VBA for dialog controls and for dealing with other applications.

Peter Jamtgaard P.E.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: plz point me in the right direction VB, LISP??
« Reply #30 on: September 16, 2005, 10:18:10 AM »
http://management.cadalyst.com/cadman/article/articleDetail.jsp?id=101853

I found it amusing that of the 4 things that article says can't be done from Visual LISP, 3 can be done with a little imagination.

(1) Integration with external databases. Hello, I've been talking to databases from Visual LISP for years. Initially I had done it by compiling a dll that wrapped ADO calls, but recently I decided to translate portions of this book to Visual LISP calls. Surprise, not that much code and execution is surprisingly fast.

(2) Open and close multiple drawings. A little clever self referencing lisp that writes scripts on the fly should be able to do this.

(3) Work with multiple files/share data. Hello, ObjectDBX and Item (1) above.

:P
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

deegeecees

  • Guest
Re: plz point me in the right direction VB, LISP??
« Reply #31 on: September 16, 2005, 12:46:11 PM »
I hear ya MP. This is a fragment from an old ADOLisp file I had laying around, and this is 5 years old:

Code: [Select]
  (setq ConnectString "Provider=MSDASQL;Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\\ADOLISP_test.mdb")
  (prompt (strcat "\n\nConnecting to the database using \n\""
          ConnectString
                  "\""
          )
  )

Open and close multiple drawings!!!??? Are you kidding me!!  :realmad:
Code: [Select]
;batch_anything.lsp
;Created for G.E.I.S. by P.R. Donnelly
;Date: Sept of 2002
;Description: Batch Process
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;start prog

(DEFUN C:batch_anything ()

;;;;;;;;;;;;;;;;;;;;;;;;;Select directory to be processed

(setq dfil (getfiled "Select A File In The Directory You Want To Batch Process" "p:/" "dwg" 0))
(setq wutdir (vl-filename-directory dfil))
(setq wutfiles (vl-directory-files wutdir "*.dwg"))

(setq scrfile (open "c:\\scrfile.scr" "w"))
(close scrfile)
(setq scrfile (open "c:\\scrfile.scr" "a"))

(foreach n wutfiles
(setq n2 (strcat "\""wutdir "\\" n "\""))
(setq n2 (vl-string-translate "\\" "\\" n2))
(setq scrline (strcat "open" " " n2 " " "(load\"batch_core\")" " " "batch_insert" " " "qsave" " " "close"));;;;;;;COMMANDS FOR BATCH GO HERE
(write-line scrline scrfile)
(princ)
)

(close scrfile)
(command "script" "c:\\scrfile")

(princ "\n***Batch complete.***")
(princ)


);;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;DEFUN