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

0 Members and 1 Guest are viewing this topic.

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.