Author Topic: plz point me in the right direction VB, LISP??  (Read 12076 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?........