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

0 Members and 1 Guest are viewing this topic.

AVCAD

  • Guest
Re: .cat files? How do they work in LISP??
« Reply #45 on: May 31, 2007, 04:33:20 PM »
man this is got me really confused....I cant figure out why it wont insert the block...all the variables are right...the code for the (command ".-insert" (strcat path BlkName) pause "0,0" "" "" "") is right...but i wont insert it.....

LE

  • Guest
Re: .cat files? How do they work in LISP??
« Reply #46 on: May 31, 2007, 04:41:36 PM »
man this is got me really confused....I cant figure out why it wont insert the block...all the variables are right...the code for the (command ".-insert" (strcat path BlkName) pause "0,0" "" "" "") is right...but i wont insert it.....

(command "_.-insert" "MY-BLOCK-NAME-HERE" pause "1.0" "1.0" "") ;; 5 arguments

AVCAD

  • Guest
Re: .cat files? How do they work in LISP??
« Reply #47 on: May 31, 2007, 04:50:06 PM »
man this is got me really confused....I cant figure out why it wont insert the block...all the variables are right...the code for the (command ".-insert" (strcat path BlkName) pause "0,0" "" "" "") is right...but i wont insert it.....

(command "_.-insert" "MY-BLOCK-NAME-HERE" pause "1.0" "1.0" "") ;; 5 arguments

thats what I have (strcat path BlkName) is a block name its just set in a variable

...well i did edit it too (command ".-insert" (strcat path BlkName) pause "1.0" "1.0" "")

still ge the same error
« Last Edit: May 31, 2007, 04:56:04 PM by AVCAD »

LE

  • Guest
Re: .cat files? How do they work in LISP??
« Reply #48 on: May 31, 2007, 05:00:41 PM »
man this is got me really confused....I cant figure out why it wont insert the block...all the variables are right...the code for the (command ".-insert" (strcat path BlkName) pause "0,0" "" "" "") is right...but i wont insert it.....

(command "_.-insert" "MY-BLOCK-NAME-HERE" pause "1.0" "1.0" "") ;; 5 arguments

thats what I have (strcat path BlkName) is a block name its just set in a variable

(command ".-insert" (strcat path BlkName) pause "0,0" "" "" "") ;; those are 6.... I mean not that will matter it will have an extra enter, maybe it is something else, try to enclose the filename with findfile (findfile (strcat path BlkName)) .... and see if that works...
« Last Edit: May 31, 2007, 05:02:02 PM by LE »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: .cat files? How do they work in LISP??
« Reply #49 on: May 31, 2007, 05:07:40 PM »
is this the problem
??
(defun get_details( / path BlkName)
  (setq usrlyr (getvar "clayer"))
  (setq usrosmode (getvar "osmode"))
  (setq dtllyr (setvar "clayer" "0"))
  (setvar "clayer" dtllyr)
  (command "_.insert" (strcat path BlkName) pause pause pause)
  )

Where are the variables path and BlkName set ?
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.

AVCAD

  • Guest
Re: .cat files? How do they work in LISP??
« Reply #50 on: June 01, 2007, 10:05:59 AM »
Enclosing it in a Findfile didnt work either i didnt  think it would but at this point I will try anything....

The Path and BlkName variables are set in 2 defuns..

Code: [Select]
(defun set_paths()
  (cond
    ((= books "0") (setq path "C:/Chi-CustomCAD/Symbman/AV/"))
    ((= books "1") (setq path "C:/Chi-CustomCAD/Symbman/TC/"))
    ((= books "2") (setq path "C:/Chi-CustomCAD/Symbman/SC/"))
    ((= books "3") (setq path "C:/Chi-CustomCAD/Symbman/AC/"))
    ((= books "4") (setq path "C:/Chi-CustomCAD/Symbman/TE/"))
    ((= books "5") (setq path "C:/Chi-CustomCAD/Symbman/PEOPLE/"))
    ((= books "6") (setq path "C:/Chi-CustomCAD/Symbman/TB/"))
    ((= books "7") (setq path "C:/Chi-CustomCAD/Symbman/MISC/"))
    )
  )
 
(defun get_blknm()
  (cond
  ((= books "0") (setq tempStr (nth (atoi block) avlist)))
  ((= books "1") (setq tempStr (nth (atoi block) tclist)))
  ((= books "2") (setq tempStr (nth (atoi block) sclist)))
  ((= books "3") (setq tempStr (nth (atoi block) aclist)))
  ((= books "4") (setq tempStr (nth (atoi block) telist)))
  ((= books "5") (setq tempStr (nth (atoi block) phlist)))
  ((= books "6") (setq tempStr (nth (atoi block) tblist)))
  ((= books "7") (setq tempStr (nth (atoi block) misclist)))
  ) 
  (setq Pos (vl-string-search ":" tempStr))
  (setq BlkName (substr tempStr 1 Pos))
  )

(defun get_details( / path BlkName)
  (progn
    (setq usrlyr (getvar "clayer"))
    (setq usrosmode (getvar "osmode"))
    (setq dtllyr (setvar "clayer" "0"))
    (setvar "clayer" dtllyr)
    (command ".-insert" (strcat path BlkName) pause "1.0" "1.0" "")
   )
  )

LE

  • Guest
Re: .cat files? How do they work in LISP??
« Reply #51 on: June 01, 2007, 10:48:41 AM »
Have not read the whole topic or the most of them, so no idea, anyway

What error you are getting?


Now, can you make a variable from one of your paths and a drawing, like:

Quote
Command: (setq dwg "c:/dwgs/mtext.dwg")
"c:/dwgs/mtext.dwg"

Then just paste the insert code in the command line:
Quote
Command: (command ".-insert" dwg pause "1.0" "1.0" "")

What it does?... something like the quote below?
Quote
.-insert Enter block name or [?]: c:/dwgs/mtext.dwg
Units: Inches   Conversion:    1.0000
Specify insertion point or [Basepoint/Scale/X/Y/Z/Rotate]:
Enter X scale factor, specify opposite corner, or [Corner/XYZ] <1>: 1.0 Enter Y
scale factor <use X scale factor>: 1.0
Specify rotation angle <0>:
Command: nil

HTH

AVCAD

  • Guest
Re: .cat files? How do they work in LISP??
« Reply #52 on: June 01, 2007, 11:17:38 AM »
baiscally thats what it does...there are 2 variables casue its a symbol mananger....the path variable tells it what dir to look in for the blocks...the blkname variable says what block to grab...which is why there is a strcat in there.

Just cant figure out why it doesnt insert it....

I dont really get an "error" per say...i just doesnt do what i want what i get is the following



it jsut doesnt take the strcat and variable names...but all the variables are set correctly and if I type out in the command line (strcat path blkname) i get what I am suppose too. if I run the insert command manually and type that in I get the correct block also...

T.Willey

  • Needs a day job
  • Posts: 5251
Re: .cat files? How do they work in LISP??
« Reply #53 on: June 01, 2007, 11:19:04 AM »
I think Kerry is on the right track.  Take the two variables 'path' and 'BlkName' out of the local variable spots of that defun, and make the local in the main one.  This way they will be use though out the whole lisp.  Late, when you are more comfortable with lisp, we will show you a better way of working with more than one defun (sub-function) within a main defun.  This will show the difference between arguments and variables.

So here
Code: [Select]
(defun get_details( / path BlkName) change to
Code: [Select]
(defun get_details()
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 #54 on: June 01, 2007, 01:05:19 PM »
ok I tried that...

I changed

Code: [Select]
(defun get_details( / path BlkName)
too

Code: [Select]
(defun get_details()
and changed it this...

Code: [Select]
(defun c:symbman ( / dcl_id path BlkName)
but when I ran the program it all worked fine untill I hit OK...it then froze ACAD...


T.Willey

  • Needs a day job
  • Posts: 5251
Re: .cat files? How do they work in LISP??
« Reply #55 on: June 01, 2007, 01:20:27 PM »
Post what you are using, so we can trouble shoot better.
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 #56 on: June 01, 2007, 01:34:31 PM »
As Requested.

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 path BlkName)
 
;; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
;; X =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= X
;; X =             Main Routine                  = X
;; X =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= X
;; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

(set_var_nil)
(get_all_lists)

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

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

  (mode_tile "catalog" 2)
  (mode_tile "catalog" 3)

  (action_tile "catalog" "(setq books $value) (chk_books)") 
  (action_tile "dlist" "(setq block $value)")
  (action_tile "accept" "(insert_block)")
  (action_tile "cancel" "(done_dialog) (setq click nil)")

  ;;(set_slide) ;; for slide setup

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

  (if click
    (insert_block)
  )

); 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_all_lists()
  (setq booklist (open "C:/Chi-CustomCAD/Symbman/Booklist.cat" "r"))
(while (setq temp (read-line booklist))
  (setq blist (cons temp blist)))
        (close booklist)

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

  (setq tcdetails (open "C:/Chi-CustomCAD/Symbman/TCdetails.cat" "r"))
(while (setq temp1 (read-line tcdetails))
(setq tclist (cons temp1 tclist)))
        (close tcdetails)
   
  (setq scdetails (open "C:/Chi-CustomCAD/Symbman/SCdetails.cat" "r"))
(while (setq temp2 (read-line scdetails))
(setq sclist (cons temp2 sclist)))
        (close scdetails)

  (setq acdetails (open "C:/Chi-CustomCAD/Symbman/ACdetails.cat" "r"))
(while (setq temp3 (read-line acdetails))
(setq aclist (cons temp3 aclist)))
        (close acdetails)

  (setq tedetails (open "C:/Chi-CustomCAD/Symbman/TEdetails.cat" "r"))
(while (setq temp4 (read-line tedetails))
(setq telist (cons temp4 telist)))
        (close tedetails)

  (setq phdetails (open "C:/Chi-CustomCAD/Symbman/PHdetails.cat" "r"))
(while (setq temp5 (read-line phdetails))
(setq phlist (cons temp5 phlist)))
        (close phdetails)

  (setq titleblocks (open "C:/Chi-CustomCAD/Symbman/Titleblocks.cat" "r"))
(while (setq temp6 (read-line titleblocks))
(setq tblist (cons temp6 tblist)))
        (close titleblocks)

  (setq miscdetails (open "C:/Chi-CustomCAD/Symbman/MISCdetails.cat" "r"))
(while (setq temp7 (read-line miscdetails))
(setq misclist (cons temp7 misclist)))
        (close miscdetails)
)

(defun chk_books()
;; book = 0 = AV Details
;; book = 1 = TC Details
;; book = 2 = SC Details
;; book = 3 = AC Details
;; book = 4 = TE Details
;; book = 5 = PEOPLE Details
;; book = 6 = TITLEBLOCKS Details
;; book = 7 = MISC Details
  (start_list "dlist" 3)
  (cond
  ((= books "0") (mapcar 'add_list avlist))
  ((= books "1") (mapcar 'add_list tclist))
  ((= books "2") (mapcar 'add_list sclist))
  ((= books "3") (mapcar 'add_list aclist))
  ((= books "4") (mapcar 'add_list telist))
  ((= books "5") (mapcar 'add_list phlist))
  ((= books "6") (mapcar 'add_list tblist))
  ((= books "7") (mapcar 'add_list misclist))
  )
  (end_list)
  )

(defun set_paths()
  (cond
    ((= books "0") (setq path "C:/Chi-CustomCAD/Symbman/AV/"))
    ((= books "1") (setq path "C:/Chi-CustomCAD/Symbman/TC/"))
    ((= books "2") (setq path "C:/Chi-CustomCAD/Symbman/SC/"))
    ((= books "3") (setq path "C:/Chi-CustomCAD/Symbman/AC/"))
    ((= books "4") (setq path "C:/Chi-CustomCAD/Symbman/TE/"))
    ((= books "5") (setq path "C:/Chi-CustomCAD/Symbman/PEOPLE/"))
    ((= books "6") (setq path "C:/Chi-CustomCAD/Symbman/TB/"))
    ((= books "7") (setq path "C:/Chi-CustomCAD/Symbman/MISC/"))
    )
  )
 
(defun get_blknm()
  (cond
    ((= books "0") (setq tempStr (nth (atoi block) avlist)))
    ((= books "1") (setq tempStr (nth (atoi block) tclist)))
    ((= books "2") (setq tempStr (nth (atoi block) sclist)))
    ((= books "3") (setq tempStr (nth (atoi block) aclist)))
    ((= books "4") (setq tempStr (nth (atoi block) telist)))
    ((= books "5") (setq tempStr (nth (atoi block) phlist)))
    ((= books "6") (setq tempStr (nth (atoi block) tblist)))
    ((= books "7") (setq tempStr (nth (atoi block) misclist)))
    )
    (setq Pos (vl-string-search ":" tempStr))
    (setq BlkName (substr tempStr 1 Pos))
  )

(defun get_details()
  (setq Pos (vl-string-search ":" tempStr))
  (setq BlkName (substr tempStr 1 Pos))
  (setq usrlyr (getvar "clayer"))
  (setq usrosmode (getvar "osmode"))
  (setq dtllyr (setvar "clayer" "0"))
  (setvar "clayer" dtllyr)
  (command ".-insert" (strcat path BlkName) pause "1.0" "1.0" "")
  )
(princ)

(defun set_var_nil()
  (setq blist nil)
  (setq booklist nil) 
  (setq avlist nil)
  (setq tclist nil)
  (setq sclist nil)
  (setq aclist nil)
  (setq telist nil)
  (setq phlist nil)
  (setq tblist nil)
  (setq misclist nil)
  (setq avdetails nil)
  (setq tcdetails nil)
  (setq scdetails nil)
  (setq acdetails nil)
  (setq tedetails nil)
  (setq phdetails nil)
  (setq titleblocks nil)
  (setq miscdetails nil) 
  (setq books nil)
  (setq details nil)
  (setq blocks nil)
  (setq usrlyr nil)
  (setq usrosmode nil)
  (setq dtllyr nil)
  (setq BlkName nil)
  (setq path nil)
  (setq tempStr nil)
  (setq Pos nil)
  )

(defun insert_block()
  (set_paths)
  (get_blknm)
  (get_details)
  (setq click T)
  (done_dialog)
  )
     

;;======================================================
;;           Dialog Box - Slide Change                 
;;======================================================
;;  any time a change in "dlist"
;;(defun set_slide (/ x y slide)
;;  (start_image "detail") ; start the image
;;  (setq x (dimx_tile "detail"))
;;  (setq y (dimy_tile "detail"))

;;  (start_image "detail")
;;  (fill_image 0 0 x y 0) ; 0 = black backgroun -15 = gray)
;;  (slide_image 0 -30 x y slide)
;;  (end_image) ; end image
;;) ; defun set_slide

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

DCL code:

Code: [Select]
symb_man : dialog
{
label = "Detail Manager";        // label for GUI
: popup_list {                                  // starts popup_list
          label = "Catalog:";
          key = "catalog";           
          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 = 40;
          }                                     // 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

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: .cat files? How do they work in LISP??
« Reply #57 on: June 01, 2007, 01:57:40 PM »
Change this:
Code: [Select]
(action_tile "accept" "(insert_block)")to this:
Code: [Select]
(action_tile "accept" "(setq click t)")
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.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: .cat files? How do they work in LISP??
« Reply #58 on: June 01, 2007, 02:03:39 PM »
The problem is you are trying to have the user select the insertion point before you end the dialog.  You need to do two things.  First change this
Code: [Select]
  (if click
    (insert_block)
  )
to
Code: [Select]
  (if click
    (get_details)
  )
And then comment out the '(get_details)' function in the 'insert_block' function. Like
Code: [Select]
(defun insert_block()
  (set_paths)
  (get_blknm)
;  (get_details)
  (setq click T)
  (done_dialog)
  )

What Alan said might work, but I would do it this way.
Tim

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

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: .cat files? How do they work in LISP??
« Reply #59 on: June 01, 2007, 02:18:26 PM »
My 2 cents. 8-)
The code as written has too many gotchas in it & too many global variables.
The vars books & block are not set to a default value so if the user clicks accept before picking the
book & block it will crash & burn.

See my code offering for some solutions.

My last suggestion will work. It only gets the dialog closed before proceeding.
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.