Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Contributor
DJB7
Posts: 13
Registered: ‎03-03-2010
Message 1 of 21 (622 Views)

Help with LISP Code

622 Views, 20 Replies
05-28-2010 07:36 AM
I cant figure out how to get one slide image to preview instead of the other when you push the diferent radio buttons. Any help would be great thanks in advance. heres the code.....




(defun do_preview_1()

(start_image "im1")
(fill_image 0 0 x1 y1 0)
(end_image)



(if (action_tile "rb13" "(setq sv \"3D\")")

(progn

(start_image "im1")
(SLIDE_IMAGE -20 -125 350 350 "AAA0001I3D")

(end_image)


(if not(action_tile "rb13" "(setq sv \"3D\")")

(progn
(setq h1 (dimx_tile "AAA0001A3D")
h2 (dimy_tile "AAA0001A3D")
)
(start_image "im1")
(SLIDE_IMAGE -20 -125 350 350 "AAA0001A3D")
(end_image)

)
)
)
)
)
*Some Buddy
Message 2 of 21 (616 Views)

Re: Help with LISP Code

05-28-2010 08:49 AM in reply to: DJB7
Hi,

Your approach is far too complicated. You should define just a little
function which will take an argument. The argument is the key (name) ot the
radio_button passed through a AutoLISP native mechanism. Now, if we assume
that your radio buttons are named "rb1" and rb2" then, the function is
something like this (as you can see you can include more than one
instructions between (start_image ...) and (end_image):

(defun show_slide (key / slide width height)
(if (= value "rb1")
(setq slide "aaa0001i3d")
(setq slide "aaa0001a3d")
)

(setq width (dimx_tile "im1"))
(setq height (dimy_tile "im1"))

(start_image "im1")
(fill_image 0 0 width height 0)
(slide_image 0 0 width height slide)
(end_image)
)

And you will have to call this function within the action_tile callback of
each of your radio_buttons. The $key argument is the key of the calling tile
(radio_button, so that your little function knows who made the call and will
assign the slide accordingly.

(action_tile "rb1" "(show_slide $key)") ;;;[1]
(action_tile "rb2" "(show_slide $key)") ;;;[2]

You could also use a key for your radio_column (or radio_row, if this is the
case) and then call the (show_slide) function within its action_tile
callback. The parent tile of the two radio buttons knows which one of the
children (radio_buttons) was pressed and it will pass the right information.
The advantage with this method is that you use the call only on single time,
no matter how many radio buttons you have in your radio_column (or
radio_row, if this is the case).

So assuming that you name your radio_column (or radio_row, if this is the
case) with something like "options", instead of writing the lines [1] and
[2] from above, you can write just the following::

(action_tile "options" "(show_slide $value)")

and this will work no matter which radio button you click.

HTH




--
The difference between truth and fiction is that fiction has to make sense.



a écrit dans le message de news: 6399431@discussion.autodesk.com...
I cant figure out how to get one slide image to preview instead of the other
when you push the diferent radio buttons. Any help would be great thanks in
advance. heres the code.....




(defun do_preview_1()

(start_image "im1")
(fill_image 0 0 x1 y1 0)
(end_image)



(if (action_tile "rb13" "(setq sv \"3D\")")

(progn

(start_image "im1")
(SLIDE_IMAGE -20 -125 350 350 "AAA0001I3D")

(end_image)


(if not(action_tile "rb13" "(setq sv \"3D\")")

(progn
(setq h1 (dimx_tile "AAA0001A3D")
h2 (dimy_tile "AAA0001A3D")
)
(start_image "im1")
(SLIDE_IMAGE -20 -125 350 350 "AAA0001A3D")
(end_image)

)
)
)
)
)
Contributor
DJB7
Posts: 13
Registered: ‎03-03-2010
Message 3 of 21 (610 Views)

Re: Help with LISP Code

05-28-2010 09:13 AM in reply to: DJB7
Thanks for the help I am going to try and see if i can get this to work. I will let you know how I fair.

Thanks again
*andrew.nao
Message 4 of 21 (611 Views)

Re: Help with LISP Code

05-28-2010 10:07 AM in reply to: DJB7
you should forget the dcl coding and learn opendcl
MUCH for flexible and easier to code with the odcl editor
Contributor
DJB7
Posts: 13
Registered: ‎03-03-2010
Message 5 of 21 (586 Views)

Re: Help with LISP Code

06-11-2010 01:49 PM in reply to: *Some Buddy

took me a little bit but i finally got the code to work the way i wanted it to. Thanks for all your help it worked great for me.:smileyvery-happy:

Contributor
DJB7
Posts: 13
Registered: ‎03-03-2010
Message 6 of 21 (501 Views)

Re: Help with LISP Code

06-21-2010 06:09 AM in reply to: DJB7

Some Buddy

 

I had the code working using your suggestions and now it has started giving me this error: no function definition: SHOW_SLIDE1 when i push the radio buttons. I narrowed the problem to the code that i added to the action tile which looks like this:

 

 (action_tile "rb1" "(setq rf \"0\")(show_slide1 $key1)")

 

the part that this calls out to looks like this:

 

(defun show_slide1(key1 / slide width height)     

(if(= value "rb1")

(setq slide "AAA0001A3D0")
(setq slide "AAA0001A3D0"))
  
(setq width (dimx_tile "im1"))
(setq height (dimy_tile "im1"))

(start_image "im1")
(fill_image 0 0 x1 y1 0)
(SLIDE_IMAGE -20 -125 350 350  "AAA0001A3D0")
 
   (end_image)

 

 

So I dont know where i went wrong but if you could help again I would greatly appreciate it .

 

 

Thanks

DJ

 

*Expert Elite*
scot-65
Posts: 2,178
Registered: ‎12-11-2003
Message 7 of 21 (470 Views)

Re: Help with LISP Code

06-21-2010 02:41 PM in reply to: DJB7

>(show_slide1 $key1)

>

 

Retrieving a key or value is $key and $value.

Others are $data, $reason, $x and $y.

What is $key1?

 

>(if(= value "rb1")

>

 

What is "value"?

Should this read (if (= key1 "rb1")... ?

 

???

Scot-65
Dyslexia is a permanent physical disability that cannot be seen.
Introverts is proof that there is indeed intelligent life on this planet.
Valued Mentor
SomeBuddy
Posts: 372
Registered: ‎06-07-2010
Message 8 of 21 (468 Views)

Re: Help with LISP Code

06-21-2010 04:51 PM in reply to: DJB7

Hi,

 

I think that you didn't really grasp the concept, so maybe you should read again my originl answer. As you can see there, there is no need to define a show_slide1 and a key1 because the same function is called no matter what radio button you select. The difference is made by the variable key, whose value change depending with $key, depending of what radio button is selected. If you select "rb1", then  $key will pass the value "rb1" to the function show_slide, and if you select "rb2", then $key will pas the value "rb2", therefore there is no need to complicate things with show_slide1 and $key1, which as scot-65 says, doesn't even exist.

 

Regards

Contributor
DJB7
Posts: 13
Registered: ‎03-03-2010
Message 9 of 21 (441 Views)

Re: Help with LISP Code

06-22-2010 06:51 AM in reply to: SomeBuddy

Hey

 

Ok so if i understand correctly the $key value tells show_slide what radio button was pushed and what slide to display. Meaning theres no need to put a show_slide 1 or show_slide 2 to match the radio button that you want the slide to display with.

 

Now if thats all right and defined properly why would it still give me this error: no function definition: SHOW_SLIDE.

 

I cant get past that error I got all the slides coming up with the proper radio buttons but if you dont push them in sequence(rb1, rb2, rb3.....etc) then i get the error above. Any ideas?

 

Thanks again in advance

Valued Mentor
SomeBuddy
Posts: 372
Registered: ‎06-07-2010
Message 10 of 21 (441 Views)

Re: Help with LISP Code

06-22-2010 07:19 AM in reply to: DJB7

Yep, you got it right, this is why there is only one show_slide function in my first post, because the same function performs the slides change, depending on what $key value is. This is a built in mechanism and I strongly suggest that you read a little more about action_tile callbacks and about $key, $value, $reason, $data and so on, although the most used are $key and $key and about functions, arguments local and global variables, it will make your (programming) life much easier :smileyhappy:

 

As for your error, I forgot to mention in my last post that the function you posted misses the closing bracket, the one after (end_image) in my original post. I don't know if it was lost in the copy-paste process or it is really missing in the code that you are testing, but just check on this. This error is generated because the show_slide function was not loaded correctly, thus being an unknown function for the LISP interpreter and most of the time this happens because of unbalanced brackets.

 

If this doesn't fix it, you will have to attach here the code you are testing, so that I can take a closer look.

 

And also, as Scot-65 mentions, there is a mistake in my initial code, so you better take this one, which I think is also more explicit:

 

(defun show_slide (selected_radio_button / slide width height)

  (if (= selected_radio_button "rb1")
    (setq slide "aaa0001i3d")
    (setq slide "aaa0001a3d")
  )

  (setq width (dimx_tile "im1"))
  (setq height (dimy_tile "im1"))

  (start_image "im1")
  (fill_image 0 0 width height 0)
  (slide_image 0 0 width height slide)
  (end_image)
 
  (princ)
)

As you can see, the argument selected_radio_button passes the name of the selection in both cases, be it with the $key solution,

or with the $value one, as explained in my first post.

 

 

HTH

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.