Author Topic: Whats a good start for Visual Lisp?  (Read 6954 times)

0 Members and 1 Guest are viewing this topic.

CECE_CAD

  • Guest
Whats a good start for Visual Lisp?
« on: September 13, 2006, 05:46:28 PM »
I was told that this was the place to come to learn. I have been using CAD over a few years, for the past year I have slowly been introducing myself into the lisp world. I see the potential for growth and want to learn. What would someone suggest for starters?

Greg B

  • Seagull
  • Posts: 12417
  • Tell me a Joke!
Re: Whats a good start for Visual Lisp?
« Reply #1 on: September 13, 2006, 05:49:13 PM »
Figure out a routine you regularly do when working and can be automated.

Explain what you are trying to achieve with the program you want to create and learn lisp as you develop the program here.

I'd say start out simple...

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Whats a good start for Visual Lisp?
« Reply #2 on: September 13, 2006, 05:52:15 PM »
You could also look at Afralisp.net for some help.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Re: Whats a good start for Visual Lisp?
« Reply #3 on: September 13, 2006, 05:58:11 PM »
<snip> I see the potential for growth and want to learn. What would someone suggest for starters?

Ask a ``question'' pertaining to a ``problem'' and we will beat it to death and give you so many options to choose from you will almost certainly have a conniption fit.

No seriously, do you want to learn VL and applications or did you want to stick with pure AutoLisp and theory or a combo of both? (I highly recommend the 'AutoLisp theory' class, Its buckets of fun.)
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

LE

  • Guest
Re: Whats a good start for Visual Lisp?
« Reply #4 on: September 13, 2006, 06:01:35 PM »
Go directly to C#, VB.NET or VBA

CECE_CAD

  • Guest
Re: Whats a good start for Visual Lisp?
« Reply #5 on: September 13, 2006, 06:03:06 PM »
Ok! For example: I was talking with someone on Autodesk chat. He was helping me create a lisp. The lisp is to find a certain block and redefine it, set it to Zero layer then take that same block take it off its current layer and put it to a new layer or create a new layer. I understand what the code is doing but not how to read it. when I try to use the lisp I get (FixLiteBlock ; error: bad argument type: VLA-OBJECT nil)

I work in AutoCAD 2007. I would like to learn this was created. Or try to create it in another way to help me learn it.



Code: [Select]
(vl-load-com)

(defun jb:BlockLayerZero(nameStr newLayer / )
(if (not (tblsearch "layer" newLayer))
(alert (strcat newLayer " does not exist - please creat it first!"))
(progn
(if (tblsearch "block" nameStr)
(progn
(vlax-for x (vla-item (vla-get-blocks jbThisDrawing) nameStr)
(vlax-put-property x 'layer "0")
(vlax-put-property x 'color acByLayer)
(princ "\nLayer changed!"))

(vlax-for blks (vla-get-blocks jbThisDrawing)
(vlax-for blk blks
(if (vlax-property-available-p blk 'name)
(if (=(vla-get-name blk) nameStr)
(vla-put-layer blk newLayer)))))
)
(alert (strcat NameStr " not found!")))))
(princ))

(COMMAND "LAYER" "M" "A-Lite-01")

(defun c:FixLiteBlock( / )
(jb:BlockLayerZero "AL2x4" "A-Lite-01"))


Edit... fixed code tags - Jonesy
« Last Edit: September 14, 2006, 03:08:34 AM by jonesy »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Whats a good start for Visual Lisp?
« Reply #6 on: September 13, 2006, 06:06:03 PM »
OMG,  poor CECE_CAD, getting bombarded at post one.

For Starters , with VL :
The Object Model,
The Help Files,
The Samples installed with AutoCAD,

... and when you hit a wall, ask ..


kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Whats a good start for Visual Lisp?
« Reply #7 on: September 13, 2006, 06:07:23 PM »
Your problem is this line
(vlax-for x (vla-item (vla-get-blocks jbThisDrawing) nameStr)
I'm pretty sure 'jbThisDrawing' is a global variable to hold the active document.  I would just rewrite that line like
Code: [Select]
(vlax-for x (vla-Item (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-Acad-Object))) nameStr)And it should work then.

Edit:  And when you post code, place it in code tags [ code ] to start the code, and [ /code ] to end it (without the spaces).
« Last Edit: September 13, 2006, 06:08:29 PM by T.Willey »
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Birdy

  • Guest
Re: Whats a good start for Visual Lisp?
« Reply #8 on: September 13, 2006, 06:07:35 PM »
Greg's advice is good.  Here's a simple example:
We used to have to switch to a dimension layer everytime we wanted to dimension something, or put the dimensions on their proper layer after the fact.

create a routine that will automatically switch to your proper dim layer every time you invoke a dimension command.
Then take it a step farther... have the routine automatically switch you back to your previous layer when you are done.

Do something similar for your Text annotations.  And hatching... etc.

Again, Greg nailed it.  Start out simple.  Build from there.

Finally, Welcome to the swamp.  Post early, post often.  There's lots of help here.

*Warning - while you were typing3 4n new replies have been posted. You may wish to review your post.* See what I mean!

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Re: Whats a good start for Visual Lisp?
« Reply #9 on: September 13, 2006, 06:07:43 PM »
Well theres your problem right there! Never listen to anyone from AutoDesk chat. *grin* (Okay, never heard of `autodesk chat' but...)

The object missing is the ``thisdrawing'' object.

BUT, do you understand the syntax of the AutoLisp language? For instance: Do you know what a conditiona statment is?
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Re: Whats a good start for Visual Lisp?
« Reply #10 on: September 13, 2006, 06:08:22 PM »
Holly cow, you guz got to be fast posters!!
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Birdy

  • Guest
Re: Whats a good start for Visual Lisp?
« Reply #11 on: September 13, 2006, 06:12:27 PM »
<trumped by the gurus>
:)
Don't mind me CECE_CAD.... cept for the welcome.

CECE_CAD

  • Guest
Re: Whats a good start for Visual Lisp?
« Reply #12 on: September 13, 2006, 06:15:05 PM »
<trumped by the gurus>
:)
Don't mind me CECE_CAD.... cept for the welcome.



A BIG THANKS TO ALL!

Birdy

  • Guest
Re: Whats a good start for Visual Lisp?
« Reply #13 on: September 13, 2006, 06:17:25 PM »
<tips hat (for doing nothing)>
These guys are good

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Whats a good start for Visual Lisp?
« Reply #14 on: September 13, 2006, 06:26:13 PM »
<trumped by the gurus>
:)
Don't mind me CECE_CAD.... cept for the welcome.



A BIG THANKS TO ALL!
You're welcome.  If you are willing to learn, people here are willing to teach.  Just come ready to see it from several different views.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

psuchewinner

  • Guest
Re: Whats a good start for Visual Lisp?
« Reply #15 on: September 14, 2006, 07:25:15 AM »
I am glad Afralisp is back!  I learned so much from that site and the newsletters.  The tutorials and the function explanations make it really easy to understand.  Be careful though, it could become an obsession.  I like to figure out how people do different things.  It is challenging and fun.  Good luck!

CECE_CAD

  • Guest
Re: Whats a good start for Visual Lisp?
« Reply #16 on: September 18, 2006, 05:22:50 PM »
Your problem is this line
(vlax-for x (vla-item (vla-get-blocks jbThisDrawing) nameStr)
I'm pretty sure 'jbThisDrawing' is a global variable to hold the active document.  I would just rewrite that line like
Code: [Select]
(vlax-for x (vla-Item (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-Acad-Object))) nameStr)And it should work then.

Edit:  And when you post code, place it in code tags [ code ] to start the code, and [ /code ] to end it (without the spaces).



Ok, so the block changes to zero but it does not get set to the new layer..? Hey what does the "Jb" mean when used like
this -> (jbthisdrawing)

Code: [Select]

(vl-load-com)

(defun jb:BlockLayerZero(nameStr newLayer / jbThisDrawing)
(setq jbThisDrawing(vla-get-activedocument(vlax-get-acad-object)))
(if (not (tblsearch "layer" newLayer))
(alert (strcat newLayer " does not exist - please creat it first!"))
(progn
(if (tblsearch "block" nameStr)
(progn
(vlax-for x (vla-Item (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-Acad-Object))) nameStr)
(vlax-put-property x 'layer "0")
(vlax-put-property x 'color acByLayer)
(princ "\nLayer changed!"))

(vlax-for blks (vla-get-blocks jbThisDrawing)
(vlax-for blk blks
(if (vlax-property-available-p blk 'name)
(if (=(vla-get-name blk) nameStr)
(vla-put-layer blk newLayer)))))
)
(alert (strcat NameStr " not found!")))))
(princ))

(COMMAND "LAYER" "M" "A-Lite-01")

(defun c:FixLiteBlock( / )
(jb:BlockLayerZero "AL2x4" "A-Lite-01"))


T.Willey

  • Needs a day job
  • Posts: 5251
Re: Whats a good start for Visual Lisp?
« Reply #17 on: September 18, 2006, 05:30:10 PM »
jb = The authors initials.

It should work, I don't see anything out of the ordinary.  It changes the blocks objects to layer 0, and then it searchs the block collection (which is where the definition for the spaces are) and if it finds your block, it changes it to the new layer.  The only thing I can think of is that your block is a nested one, or with the new dynamic blocks.  If the block is a dynamic one, and has been changed, then the name isn't the one that defines it.

Hope that makes sense.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CECE_CAD

  • Guest
Re: Whats a good start for Visual Lisp?
« Reply #18 on: September 18, 2006, 05:42:30 PM »
jb = The authors initials.

It should work, I don't see anything out of the ordinary.  It changes the blocks objects to layer 0, and then it searchs the block collection (which is where the definition for the spaces are) and if it finds your block, it changes it to the new layer.  The only thing I can think of is that your block is a nested one, or with the new dynamic blocks.  If the block is a dynamic one, and has been changed, then the name isn't the one that defines it.

Hope that makes sense.


Hey I added the

Code: [Select]

(COMMAND "LAYER" "M" "A-Lite-01")


is there a better way to write that? is that a generic way to creat a layer?

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Whats a good start for Visual Lisp?
« Reply #19 on: September 18, 2006, 05:51:54 PM »
The command isn't finished.  Have to put that one the comamnd line, and see if it works?  You will need one more enter to exit the command. An enter in lisp if a pair of double quotes.  So you would want
Code: [Select]
(command "_.layer" "_m" "A-Lite-01" "")
The underscore before native commands is so that the routine will run with internation versions (I just have a habit now of doing it), and the period before the layer command is so it will use the the built in command instead of one that has been redefined, if it has been redefined.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Whats a good start for Visual Lisp?
« Reply #20 on: September 18, 2006, 06:03:20 PM »
CECE,
Just make sure you understand what that command is doing.
Code: [Select]
(COMMAND "LAYER" "M" "A-Lite-01")
is there a better way to write that? is that a generic way to creat a layer?

It makes the layer (if not existing) and sets it current when you load the routine.
If it was me, I'd rather not have that happen.
There is no checking that the layer exists when it is needed.

This may give you some ideas :
Code: [Select]
(setq newLayer "TestLayer")
(if (not (tblsearch "layer" newLayer))
  (progn
    (vl-cmdf "._LAYER" "_NEW" newLayer "")
    (alert (strcat "LAYER " newLayer
                   " Has been created, Please confirm it's COLOR and LINETYPE."
           )
    )
  )
« Last Edit: September 18, 2006, 06:06:23 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

LE

  • Guest
Re: Whats a good start for Visual Lisp?
« Reply #21 on: September 18, 2006, 06:03:47 PM »
just to get a little confused:

(command "_.layer" "_m" "A-Lite-01" "")

Quote
(command "_.layer" "_m" "A-Lite-01" ^)
(command "_.layer" "_m" "A-Lite-01" p)
(command "_.layer" "_m" "A-Lite-01" nil)
(command "_.layer" "_m" "A-Lite-01" enter)

will work too....   :-P

CECE_CAD

  • Guest
Re: Whats a good start for Visual Lisp?
« Reply #22 on: September 18, 2006, 06:07:24 PM »
Do I have to note the layer that the block is on to change to the layer that i'm trying to put it on?

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Whats a good start for Visual Lisp?
« Reply #23 on: September 18, 2006, 06:12:13 PM »
Do I have to note the layer that the block is on to change to the layer that i'm trying to put it on?
Nope, not with the way this routine is written.  It just cares about the block name, and the new layer.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.