Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Help with LISP Code

20 REPLIES 20
Reply
Message 1 of 21
DJB7
1010 Views, 20 Replies

Help with LISP Code

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)

)
)
)
)
)
20 REPLIES 20
Message 2 of 21
Anonymous
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)

)
)
)
)
)
Message 3 of 21
DJB7
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
Message 4 of 21
Anonymous
in reply to: DJB7

you should forget the dcl coding and learn opendcl
MUCH for flexible and easier to code with the odcl editor
Message 5 of 21
DJB7
in reply to: Anonymous

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.Smiley Very Happy

Message 6 of 21
DJB7
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

 

Message 7 of 21
scot-65
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
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 8 of 21
SomeBuddy
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

Message 9 of 21
DJB7
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

Message 10 of 21
SomeBuddy
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 🙂

 

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

Message 11 of 21
DJB7
in reply to: SomeBuddy

I think to do this i need a full college course..Smiley Very Happy... The missing bracket i missed in the copy and paste sorry about that. I made the changes to the code  heres what i have  

 

(action_tile "rb1" "(setq rf \"0\")(show_slide $key)")
;*store insert rotation factor

(action_tile "rb2" "(setq rf \"90\")(show_slide $key)")
;*store insert rotation factor

(action_tile "rb3" "(setq rf \"180\")(show_slide $key)")
;*store insert rotation factor
 
(action_tile "rb4" "(setq rf \"270\")(show_slide $key)")
;*store insert rotation factor

(action_tile "rb5" "(setq sv \"LEFT\")(show_slide $key)")
;*store selected view

(action_tile "rb6" "(setq sv \"RIGHT\")(show_slide $key)")
;*store selected view


(action_tile "rb7" "(setq sv \"TOP\")(show_slide $key)")
;*store selected view


(action_tile "rb8" "(setq sv \"BACK\")(show_slide $key)")
;*store selected view


(action_tile "rb9" "(setq sv \"FRONT\")(show_slide $key)")
;*store selected view   

(action_tile "rb10" "(setq sv \"FRONT and BACK\")(show_slide $key)")

(action_tile "rb11" "(setq sv \"RIGHT and LEFT\")(show_slide $key)")

(action_tile "rb12" "(setq sv \"ALL\")(show_slide $key)")

(action_tile "rb13" "(setq sv \"3D\")(show_slide $key)")
 

)

 

 

(defun do_preview_1()               ;;; theres a pull down tab that this is refering to
     

(defun show_slide(selected_radio_button / slide width height)     

(if(= selected_radio_button "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)

(defun show_slide(selected_radio_button / slide width height)
(if(= selected_radio_button "rb2")

     (setq slide "AAA0001A3D90")
     (setq slide "AAA0001A3D90"))
  
(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  "AAA0001A3D90")
 
   (end_image)

 

(defun show_slide(selected_radio_button / slide width height)
(if(= selected_radio_button "rb3")

     (setq slide "AAA0001A3D180")
     (setq slide "AAA0001A3D180"))
  
(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  "AAA0001A3D180")
 
   (end_image)


(defun show_slide(selected_radio_button / slide width height)
(if(= selected_radio_button "rb4")

     (setq slide "AAA0001A3D270")
     (setq slide "AAA0001A3D270"))
  
(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  "AAA0001A3D270")
 
   (end_image)
 
 
(defun show_slide(selected_radio_button / slide width height)
(if(= selected_radio_button "rb5")

     (setq slide "AAA0001L")
     (setq slide "AAA0001L"))
  
(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  "AAA0001L")
 
   (end_image)  

 
 
(defun show_slide(selected_radio_button / slide width height)
(if(= selected_radio_button "rb6")

     (setq slide "AAA0001R")
     (setq slide "AAA0001R"))
  
(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  "AAA0001R")
 
   (end_image)   

(defun show_slide(selected_radio_button / slide width height)
(if(= selected_radio_button "rb7")

     (setq slide "AAA0001T")
     (setq slide "AAA0001T"))
  
(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  "AAA0001T")
 
   (end_image)  

 
 
(defun show_slide(selected_radio_button / slide width height)
(if(= selected_radio_button "rb8")

     (setq slide "AAA0001B")
     (setq slide "AAA0001B"))
  
(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  "AAA0001B")
 
   (end_image) 
 

(defun show_slide(selected_radio_button / slide width height)
(if(= selected_radio_button "rb9")

     (setq slide "AAA0001F")
     (setq slide "AAA0001F"))
  
(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  "AAA0001F")
 
   (end_image)  

 
 
(defun show_slide(selected_radio_button / slide width height)
(if(= selected_radio_button "rb10")

     (setq slide "AAA0001FB")
     (setq slide "AAA0001FB"))
  
(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  "AAA0001FB")
 
   (end_image) 
 
(defun show_slide(selected_radio_button / slide width height)
(if(= selected_radio_button "rb11")

     (setq slide "AAA0001LR")
     (setq slide "AAA0001LR"))
  
(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  "AAA0001LR")
 
   (end_image)
 
(defun show_slide(selected_radio_button / slide width height)
(if(= selected_radio_button "rb12")

     (setq slide "AAA0001A")
     (setq slide "AAA0001A"))
  
(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  "AAA0001A")
 
   (end_image)  

 
 
(defun show_slide(selected_radio_button / slide width height)
(if(= selected_radio_button "rb13")

     (setq slide "AAA0001I3d")
     (setq slide "AAA0001I3d"))
  
(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  "AAA0001I3d")
 
   (end_image)      
 
 
))))))))))))))

 

 

let me know what you think

 

Thanks again

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Message 12 of 21
SomeBuddy
in reply to: DJB7

My friend,

 

You really need a DCL 101 class or something, because you miss a lot of concepts and understanding about how these work, and "playing by the ear" it doesn't help too much. There's a lot to correct and comment about your code and I don't even know how and where to start, so I'll be back a little later 🙂

Message 13 of 21
DJB7
in reply to: SomeBuddy

I appreciate all your help and I dont want to take up too much of your time.If its too bad dont worry about it and I will try and get it. But I do appreciate all the help you have already given me.Smiley Wink

 

 

Thanks again

DJ

Message 14 of 21
SomeBuddy
in reply to: DJB7

You have little chance to mak it work the way you started it.

 

1) You do not need to define show_slide so many times, but only once.The difference from case to case is done by $key

2) You can not define functions in this iterative (nested) way that you are traying.

 

Basically what you are doing is something like:

 

(defun do_preview_1()
  (defun show_slide(selected_radio_button / slide width height)
    ;;;...
    (defun show_slide(selected_radio_button / slide width height)
      ;;;...    
      (defun show_slide(selected_radio_button / slide width height)
        ;;;...      
        (defun show_slide(selected_radio_button / slide width height)
          ;;;...        
          (defun show_slide(selected_radio_button / slide width height)
            ;;;...          
            (defun show_slide(selected_radio_button / slide width height)
              ;;;...            
              (defun show_slide(selected_radio_button / slide width height)
                ;;;...              
                (defun show_slide(selected_radio_button / slide width height)
                  ;;;...                
                  (defun show_slide(selected_radio_button / slide width height)
                    ;;;...                  
                    (defun show_slide(selected_radio_button / slide width height)
                      ;;;...                    
                      (defun show_slide(selected_radio_button / slide width height)
                        ;;;...                      
                        (defun show_slide(selected_radio_button / slide width height)
                          ;...
) ) ) ) ) ) ) ) ) ) ) ) )

 while it should be something like:

 

 

(defun do_preview_1()
  (defun show_slide(selected_radio_button / slide width height)
    ;;;...
) )

 3) You define the variable slide, but you don't use it, because you use the fixed (hard coded) name for the slide, so instead

 

(defun show_slide(selected_radio_button / slide width height)
(if(= selected_radio_button "rb13")
(setq slide "AAA0001I3d")
(setq slide "AAA0001I3d")
)
(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 "AAA0001I3d");;; should use slide here
(end_image)
)

 you should have something like:

 

(defun show_slide(selected_radio_button / slide width height)
(if(= selected_radio_button "rb13")
(setq slide "AAA0001I3d")
(setq slide "AAA0001I3d")
)
(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 slide)
(end_image)
)

 

otherwise the variable slide is useless !!!

 

Your code can be dramatically reduced and optimized, but I need all the LISP and the DCL code, if you don't mind. I am going to do the canges and let you to analyse and understand what, why and how.

 

Regards

 

 

 

Message 15 of 21
DJB7
in reply to: SomeBuddy

Is there a way to attach the file, Because the code is huge?

Message 16 of 21
SomeBuddy
in reply to: DJB7

When you answer a message, underneath the text windows there's a zone with a text saying Attachments and underneath this text, you have a [ Browse ] button to search for a file to be attached.

 

Once you attach one file, a second button becomes available and you can attach anoter file, and so on (most probably there is a limit of 5 files or something). After selecting the file to be attached, don't forget  to click on the "Add Attachment" option.

Message 17 of 21
DJB7
in reply to: SomeBuddy

here you go

Message 18 of 21
DJB7
in reply to: DJB7

And Thanks again for all your help really appreciate it!!

Message 19 of 21
SomeBuddy
in reply to: DJB7

OK, I'll get back to you ASAP.

Message 20 of 21
SomeBuddy
in reply to: DJB7

Hi,

 

Your whole code is indeed huge and although I understand how it works, I didn't want to make the changes in the original file, because I considered that all that code will make it hard for you to follow how this mechanism works.

 

So I've built a simplified LISP function which uses the same DCL file, but in the DCL file I've defined a simplified second dialog box to work with this new LISP file.

 

The two files must be placed in th same folder,  and you shouldn't be afraid to overwrite the DCL file, because the original dialog definition is still there, but you can make a safety backup if you want.

 

The name of the function is RBDEMO and this should bring the new dialog box on screen and let you play with the radio buttons. I've replaced the code for displaying the slides (because there is no image on my demo dialog) with an (alert ...) function using the same name of the slide that should be shown in the image tile, so I think it won't be a problem to implement this logic with your code and display the right slide.

 

This demo will seek for the slide exacly the same way you've started to assign the slides in your original code, depending of the selected radio button one at a time, but I'm affraid that the slides management should be a little bit more complicated and there should be some  combinations, depending of both parameters, i.e. the view AND the rotation.

 

Anyway, try to play with these and if you have some other questions, just ask. In order to make it easier for you to understand how this is done, check all the comments in the new LSP file and check for SomeBuddy comments in the DCL file.

 

HTH

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost