Jump to content

Recommended Posts

Posted
Correct, then populate the list with the strings - but, really, the list_box is meant for user selection, not message display...

 

 

Thank you Lee Mac! You are right - list_box is for selections, but for now this is the situations.

Thanks of all guys!

  • Replies 29
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    10

  • sharpooth

    9

  • BlackBox

    6

  • Lt Dan's legs

    3

Top Posters In This Topic

Posted Images

Posted (edited)

untested

 

 
(defun c:test (/ lst dcl filename f)
 (setq lst '("this is a test!" "this is only a test" "line 3" "line4" "line 5" "6" "7" "8" "9" "10"))
 (if (eq (findfile (setq filename (strcat (getvar 'roamablerootprefix) "Support\\test.dcl"))) nil)
   (progn
     (setq f (open filename  "w"))
     (foreach str '("main"
  ": dialog {"
  "  label = \"test\";"
  "  : list_box {"
  "    alignment = centered;"
  "    key = \"list\";"
  "    width = 35;"
  "    height = 10;"
  "    fixed_width = true;"
  "    fixed_height = true;"
  "  }"
  "  ok_only;"
  "}")
(write-line str f))
     (setq f (close f))
   )
 )
 (setq dcl (load_dialog filename))
 (if (not (new_dialog "main" dcl))
   (progn
     (prompt "\nDCl not found!")
     (exit)
   )
 )
 (start_list "list")(mapcar 'add_list lst)(end_list)
 (start_dialog)
 (unload_dialog dcl)
 (princ)
)

Edited by Lt Dan's legs
Posted

FYI: there is no start_dialog call, this will cause the dialog to appear but the user to have no way to terminate it without terminating AutoCAD through the Task manager...

Posted

Had fun with this one :D

 

LISP (change red part to suit)

 

(defun c:Tip! ( / *error* LM:WriteDCL tipfile tips tip SavePath dcfname dcHan )
 (vl-load-com)
 ;; © Lee Mac 2010

[color=red][b]  ;; Tip of the Day Source File
 (setq tipfile "C:\\Tips.txt")[/b][/color]

 (defun *error* ( msg )
   
   (if ofile (close ofile))
   (if dcHan (unload_dialog dcHan))
   
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ)
 )

 (defun LM:WriteDCL ( filename / ofile )

   (cond
     ( (findfile filename) )
     
     ( (setq ofile (open filename "w"))

       (foreach str
          '("tip : dialog { label = \"Tip of the Day\";"
            "  spacer;"
            "  : list_box { key = \"list\"; width = 60; height = 20; fixed_width = true; fixed_height = true; }"
            "  spacer;"
            "  ok_only;"
            "}"
           )
         (write-line str ofile)
       )          
       (setq ofile (close ofile))

       (while (not (findfile filename)))
      
       filename
     )
   )
 )

 (cond
   (
     (not (setq tipfile (findfile tipfile)))

     (princ "\n** Tip File not Found **")
   )
   (
     (not (setq tips (GetTips tipfile)))

     (princ "\n** No Tips Found **")
   )
   (
     (not (vl-file-directory-p (setq SavePath (LM:GetSavePath))))

     (princ "\n** Save Path not Valid **")
   )
   (
     (not (LM:WriteDCL (setq dcfname (strcat SavePath "\\LMAC_TipoftheDay.dcl"))))

     (princ "\n** DCL could not be written **")
   )
   (
     (<= (setq dcHan (load_dialog dcfname)) 0)

     (princ "\n** DCL could not be found **")
   )
   (
     (not (new_dialog "tip" dcHan))

     (princ "\n** DCL could not be loaded **")
   )
   (t
     (setq tip (nth (rand 0 (1- (length tips))) tips))

     (start_list "list")
     (mapcar 'add_list tip)
     (end_list)

     (start_dialog)
     (setq dcHan (unload_dialog dcHan))
   )
 )

 (princ)
)


(defun LM:GetSavePath ( / tmp )
 (cond      
   ( (setq tmp (getvar 'ROAMABLEROOTPREFIX))

     (or (eq "\\" (substr tmp (strlen tmp)))
         (setq tmp (strcat tmp "\\"))
     )
     (strcat tmp "Support")
   )
   ( (setq tmp (findfile "ACAD.pat"))

     (setq tmp (vl-filename-directory tmp))

     (and (eq "\\" (substr tmp (strlen tmp)))
          (setq tmp (substr tmp (1- (strlen tmp))))
     )
     tmp
   )
 )
)

(defun GetTips ( fname / ofile nl lst sub )
 (cond
   ( (setq ofile (open fname "r"))

     (while (setq nl (read-line ofile))
       
       (if (eq "***" nl)
         (setq lst (cons (reverse sub) lst) sub nil)
         (setq sub (cons nl sub))
       )
     )

     (reverse (setq ofile (close ofile) lst (cons (reverse sub) lst)))
   )
 )
)

;; SMadsen
(defun rand ( minN maxN / rnd )
 
 (defun rnd ( / modulus multiplier increment )
   (if (not seed) (setq seed (getvar 'DATE)))

   (setq modulus 65536 multiplier 25173 increment 13849)

   (setq seed (rem (+ (* multiplier seed) increment) modulus))

   (/ seed modulus)
 )

 (fix (+ minN (* (rnd) (- (1+ maxN) minN))))
)

Tips!

Separate each tip with *** :)

 

Tip Number 1
Before starting work, be sure to turn computer on.
***
Tip Number 2
Make sure coffee cup is full.
***
Lee Mac's Bonus Tip
Learn to write AutoLISP 

 

Tips are selected at random :)

Posted

thanks. I actually modified mine from a previous post for vector_image. I just removed too many things

Posted

Thank you Lee! Your idea it is working very well :) last sentance from Tips is very important :D

Thank you Lt Dan's legs!

Posted
Thank you Lee! Your idea it is working very well :) last sentance from Tips is very important :D

Thank you Lt Dan's legs!

 

Excellent - I'm glad you like it :)

 

Now its up to you to populate the Tips :) How many are you going to make?

Posted
last sentance from Tips is very important :D

Thank you Lt Dan's legs!

No problem

 

*Warning*

Once you start writing programs you may not be able to stop. :)

Posted
Excellent - I'm glad you like it :)

 

Now its up to you to populate the Tips :) How many are you going to make?

 

 

30 tips. One per day. The tips are very usefully thinks.

For example : after working time shut down the computer;

after working time shut down the printer;

Today is Christmas!

tasks for today : 1...............

2...............

 

 

and so on .

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...