Author Topic: .cat files? How do they work in LISP??  (Read 16688 times)

0 Members and 1 Guest are viewing this topic.

AVCAD

  • Guest
.cat files? How do they work in LISP??
« on: May 25, 2007, 11:16:11 AM »
I am starting a new project...yes a new one...even though I am not tha good at code but...it keeps me busy tring to learn some new things.

This new one is a Detail manager. Yes I know there are plenty out there but I would like to make my own.

Just a basic manager, you select a catalogue the list comes up, you select your block you hit insert. done.

here is a screen of the ui I have. All my blocks are made or being made. Layering and colors and what layer to insert them on isnt a bigdeal cause they are all created on their correct layers so inserting them on layer 0 is fine and not a big deal to so do a (setvar "clayer" 0) in the code.



I have some Lisp code written for this already but its by far no where near being right or even at apoint where I am not imbarrassed to post it lol.

Now the reason i asked about .cat files is cause I was talking to some here and he said he used a file that was a .cat file that held the list info and block info in there and just had to call that file out. Ofcourse he said he doesnt remember how it worked.....which jsut leads me to believe he didnt actually code it lol.

But thought I would ask here seeing as smart r gents u :-)


edited it cause i had forget to take off my real name on the ui... i dont want you too track me down and kill me...
« Last Edit: May 25, 2007, 11:20:21 AM by AVCAD »

T.Willey

  • Needs a day job
  • Posts: 5218
Re: .cat files? How do they work in LISP??
« Reply #1 on: May 25, 2007, 11:21:02 AM »
If the .cat file is just a text based file, then you can just use 'open' to open the correct file, and the use 'read-line' to get each line of text in the file within a 'while' loop.
Tim

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

Please think about donating if this post helped you.

AVCAD

  • Guest
Re: .cat files? How do they work in LISP??
« Reply #2 on: May 25, 2007, 11:50:09 AM »
ya a .cat file is just text

Code: [Select]
Description ---------------------- File ----------------------------------- Block --- Slide --- Slide Lib --------
"C1: RECESSED PTZ CAMERA"        "C:/CHI-CUSTOMCAD/Details/AV-DETAILS"      "C1"      "C1"      "AV-Details"

right now thats what it looks like...I have a .ini file set up...my thought was that i need this file to call out where too look for the files

Code: [Select]
Description ----------------- File
"Books"                       "c:/CHI-CustomCAD/Sybman/Booklist.cat"
"AV Details"                  "c:/CHI-CustomCAD/Sybman/AVdetails.cat"
"TC Details"                  "c:/CHI-CustomCAD/Sybman/TCdetails.cat"
"SC Details"                  "c:/CHI-CustomCAD/Sybman/SCdetails.cat"
"AC Details"                  "c:/CHI-CustomCAD/Sybman/ACdetails.cat"
"TE Details"                  "c:/CHI-CustomCAD/Sybman/TEdetails.cat"
"People/Humans Details"       "c:/CHI-CustomCAD/Sybman/PHdetails.cat"
"TB Details"                  "c:/CHI-CustomCAD/Sybman/TBdetails.cat"
"Misc Details"                "c:/CHI-CustomCAD/Sybman/MISCdetails.cat"

So I was thinking that the Catalog/books would look at the Booklist.cat file wich would hold the list of catalogs in it basically just the drop menu selection. and depending on what book is selected would then call up which list of details to bring up.

it even possible to do this with in vlisp or is this a differant type of programing? This is all new to me, i guess I am just feeling out the landscape.

T.Willey

  • Needs a day job
  • Posts: 5218
Re: .cat files? How do they work in LISP??
« Reply #3 on: May 25, 2007, 12:13:13 PM »
If you save all your files (.cat) in the acad search path, then there is no need to have an '.ini' file to locate them.  You can just use the 'findfile' function within lisp to locate the '.cat' files.
Tim

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

Please think about donating if this post helped you.

AVCAD

  • Guest
Re: .cat files? How do they work in LISP??
« Reply #4 on: May 25, 2007, 01:57:47 PM »
how would you call out the lines in the cat file? or an ini file for that matter? I just want to see how this all works

T.Willey

  • Needs a day job
  • Posts: 5218
Re: .cat files? How do they work in LISP??
« Reply #5 on: May 25, 2007, 02:08:22 PM »
Once you have the path to the file use 'open' and set what is returned to a variable.  Then use 'read-line' on that variable within a 'while' loop.  I'm only giving you hints this time  :wink: so you will have to look into the help to see how to use them.  If you don't understand after that, then maybe I will provide code.  We shall see......  :-)
Tim

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

Please think about donating if this post helped you.

AVCAD

  • Guest
Re: .cat files? How do they work in LISP??
« Reply #6 on: May 25, 2007, 02:27:12 PM »
there isnt really a good help file for the read-line function can you explain it a bit?

so far i have..

Code: [Select]
(setq blist (open "c:/chi-customcad/symbman/booklist.cat" "r"))
its a start! lol

Maverick«

  • Seagull
  • Posts: 14777
Re: .cat files? How do they work in LISP??
« Reply #7 on: May 25, 2007, 02:32:09 PM »
there isnt really a good help file for the read-line function can you explain it a bit?

Googly Moogly
Quote
[Function]
read-line &optional input-stream eof-error-p eof-value recursive-p

read-line reads in a line of text terminated by a newline. It returns the line as a character string (without the newline character). This function is usually used to get a line of input from the user. A second returned value is a flag that is false if the line was terminated normally, or true if end-of-file terminated the (non-empty) line. If end-of-file is encountered immediately (that is, appears to terminate an empty line), then end-of-file processing is controlled in the usual way by the eof-error-p, eof-value, and recursive-p arguments.

The corresponding output function is write-line.

T.Willey

  • Needs a day job
  • Posts: 5218
Re: .cat files? How do they work in LISP??
« Reply #8 on: May 25, 2007, 02:32:34 PM »
What read-line does is read the lines within a file, one by one.  Each call to it increases to the next line.  So you will want to read all the lines, put them into a list, and then when it's done, put that list into you dcl file.  So to use read-line you would do (with your code provided)
Code: [Select]
(while (setq tempTextLine (read-line blist))
 (setq TextList (cons tempTextLine TextList))
 )
... here add the list to the dcl, and close the file you opened
Tim

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

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5218
Re: .cat files? How do they work in LISP??
« Reply #9 on: May 25, 2007, 02:34:49 PM »
there isnt really a good help file for the read-line function can you explain it a bit?

Googly Moogly
Quote
[Function]
read-line &optional input-stream eof-error-p eof-value recursive-p

read-line reads in a line of text terminated by a newline. It returns the line as a character string (without the newline character). This function is usually used to get a line of input from the user. A second returned value is a flag that is false if the line was terminated normally, or true if end-of-file terminated the (non-empty) line. If end-of-file is encountered immediately (that is, appears to terminate an empty line), then end-of-file processing is controlled in the usual way by the eof-error-p, eof-value, and recursive-p arguments.

The corresponding output function is write-line.
Common Lisp is a little different than AutoLisp within Acad though, but a good find and tip nontheless.
Tim

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

Please think about donating if this post helped you.

AVCAD

  • Guest
Re: .cat files? How do they work in LISP??
« Reply #10 on: May 25, 2007, 02:58:46 PM »
Thats what I have so far...

Code: [Select]
(defun c:symbman ( / dcl_id)

  (setq booklist (open "C:/Chi-CustomCAD/Symbman/Booklist.cat" "r")
(while (setq tempTextLine (read-line booklist))
  (setq TextList (cons tempTextLine TextList)))
  (start_list "books")
  (mapcar 'add_list booklist)
  (end_list)
        (close booklist))

;;----------------------dcl stuff-----------------------------
  (setq dcl_id (load_dialog "symb_man.dcl"))
  (if (not (new_dialog "symb_man" dcl_id))
    (exit)
  ) ;if

is that on the right path? cause it isnt working...

AVCAD

  • Guest
Re: .cat files? How do they work in LISP??
« Reply #11 on: May 25, 2007, 03:18:09 PM »
hmm....i got the list too work.

part of the code..

Code: [Select]
  (setq booklist (open "C:/Chi-CustomCAD/Symbman/Booklist.cat" "r"))
(while (setq tempTextLine (read-line booklist))
  (setq blist (cons tempTextLine blist)))
        (close booklist)


;;----------------------dcl stuff-----------------------------
  (setq dcl_id (load_dialog "symb_man.dcl"))
  (if (not (new_dialog "symb_man" dcl_id))
    (exit)
  ) ;if

  (start_list "books")
  (mapcar 'add_list blist)
  (end_list)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10366
Re: .cat files? How do they work in LISP??
« Reply #12 on: May 25, 2007, 03:23:05 PM »
Here is some old code you can use.
Code: [Select]
  ;;  TxtFile2List by CAB
  ;;  open the file, read the data
  ;;  returns data from file
  (defun File2list (filename ; file name
                    onestr ; t = all lines 2 one string
                    case ; nil = no change
                    ;;         U = force to upper case
                    ;;         L = force to lower case
                    / handle stream itm FileData
                   )
    (if
      (and
        (eq 'str (type filename))
        (setq filename (findfile filename))
        (setq handle (open filename "r"))
      )
       (progn
         (while (setq stream (read-line handle))
                  (setq  FileData (cons stream FileData))
         ) ; while
         (close handle)
         
         (if FileData
           (setq FileData
                   (mapcar '(lambda(itm) 
                        (cond
                          ((= case "U") (setq itm (strcase itm)))
                          ((= case "L") (setq itm (strcase itm t)))
                        ) ; cond stmt
                        (if (/= (vl-string-trim " \t\n" itm) "")
                          (if onestr
                            (setq itm (strcat itm (chr 13) itm))
                            (setq itm (cons itm result))
                          )
                        )
                     )
                  (reverse FileData)
                  )
       )
       ) ; progn
    ) ; endif
     FileData
  )
I've reached the age where the happy hour is a nap. (░┐░)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

AVCAD

  • Guest
Re: .cat files? How do they work in LISP??
« Reply #13 on: May 25, 2007, 04:34:32 PM »
how can I get the variable that is selected with in a popup_box in the DCL?

SO when "option 1" is selected in the popup_box a new list is then added too the list box..

Code: [Select]
;;*************************************************************
;;*************************************************************
;;***                                                       ***
;;***            S Y M B _ M A N . L S P                    ***
;;***                                                       ***
;;***         Version 1.0   05/10/07 - STARTED              ***
;;***                                                       ***
;;*************************************************************
;;*************************************************************

;; use this line to run program
(defun c:symbman ( / dcl_id)

;; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
;; X =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= X
;; X =             Main Routine                  = X
;; X =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= X
;; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
(get_blist_list)
(get_avdetails_list)
(get_tcdetails_list)

(get_books) 

;;----------------------dcl stuff-----------------------------
  (setq dcl_id (load_dialog "symb_man.dcl"))
  (if (not (new_dialog "symb_man" dcl_id))
    (exit)
  )

  (start_list "books")
  (mapcar 'add_list blist)
  (end_list)

  (start_list "dlist")
  (mapcar 'add_list details)
  (end_list)

  (action_tile "accept" "(insert_blocks)")
  (action_tile "cancel" "(done_dialog) (setq click nil) (set_var_nil)")

  ;;-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
 
  (start_dialog)
  (unload_dialog dcl_id)

  (if click
    (insert_block)
  )
  (princ)
); end defun

;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;;             End Of Main Routine             
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

;; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
;; X =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= X
;; X =          S u b  R o u t i n e s           = X
;; X =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= X
;; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

;;-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
(defun get_blist_list()
  (setq booklist (open "C:/Chi-CustomCAD/Symbman/Booklist.cat" "r"))
(while (setq temp1 (read-line booklist))
  (setq blist (cons temp1 blist)))
        (close booklist)
  )

(defun get_avdetails_list() 
  (setq avdetails (open "C:/Chi-CustomCAD/Symbman/AVdetails.cat" "r"))
(while (setq temp2 (read-line avdetails))
(setq avlist (cons temp2 avlist)))
        (close avdetails)
  )

(defun get_tcdetails_list() 
  (setq tcdetails (open "C:/Chi-CustomCAD/Symbman/TCdetails.cat" "r"))
(while (setq temp3 (read-line tcdetails))
(setq tclist (cons temp3 tclist)))
        (close tcdetails)
  )

(defun get_stuff()
  (get_books)
  (get_detail_lists)
  (setq click T)
  )

(defun get_books()
  (setq bookD (get_tile "books"))
   (cond
    ((= bookD "AV Details")
  (setq details avdetails))
    ((= bookD "TC Details")
  (setq details tcdetails))
    )
  )

(defun set_var_nil()
  (setq blist nil)
  )

(defun insert_blocks()
  (set_var_nil) 
  (setq click T)
  (done_dialog)
  )

;; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
;; X =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= X
;; X =          E n d   O f   F i l e            = X
;; X =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= X
;; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

the DCL

Code: [Select]
symb_man : dialog
{
label = "Detail Manager";        // label for GUI
: popup_list {                                  // starts popup_list
          label = "Catalog:";
          key = "books";           
          edit_width = 20;         
          fixed_width = true;
          }                                     // ends popup_list
// keeps next in the same row
: row {                                         // start row
          fixed_width = true;

// starts to rack information selection box
: boxed_column {                                // start boxed column
          label = "Detail Block Names:";
         
: list_box {                                    // starts list box
          key = "dlist";
          is_tab_stop = true;
          width = 30;
          }                                     // ends edit box
        }                                      // ends boxed column
         
// This image is for the preview box
: boxed_column {                                // start boxed column
          label = "Detail Image:";

: image {                                       // define image tile
         key = "detailimage";                   // give it a name
         color = 0;
         aspect_ratio = 1;                      // aspect of slide file
         width = 30;                  // and now a width
         fixed_height = true;
         }                                      // ends image
       } // ends boxed column
     }
// end of the preview box code
     
// starts cancel, ok buttons
: row {          // defines the OK/Cancel button row
  : spacer { width = 1; }
  : button {    // defines the OK button
    label = "&Ok";
    is_default = true;
    key = "accept";
    width = 8;
    fixed_width = true;
  }
  : button {    // defines the Cancel button
    label = "&Cancel";
    is_cancel = true;
key = "cancel";
    width = 8;
    fixed_width = true;
  }
  : spacer { width = 1;}
} // starts cancel, ok buttons
: row {
  :text {
     label = "";
     }
     }
  // starts the logo and paragraph
}                                               // ends dialog

Heres what I got...so far....To be coontinued...i am going to get my drink on....
« Last Edit: May 25, 2007, 04:35:39 PM by AVCAD »

T.Willey

  • Needs a day job
  • Posts: 5218
Re: .cat files? How do they work in LISP??
« Reply #14 on: May 25, 2007, 05:08:07 PM »
You have (within the lisp) an action_tile call that watches when the value of the popup_list is changed.  When it is changed, it will call a sub-routine that will
First: clear the list
Second: populate the list again with the new value

It might also have to recognized what value is select, and then find the correct '.cat' file to fill the list_box with.
Tim

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

Please think about donating if this post helped you.