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

Uses of progn Function

3 REPLIES 3
Reply
Message 1 of 4
sovby
465 Views, 3 Replies

Uses of progn Function

One of the uses of the progn function from what i have been told is that so you can have a strcase that is multiple lines. In other words so that your code doesnt go all the way across the page. Is that correct & if so am i using this properly in my code.

(PROGN
(IF (or (= (strcase (GETVAR "PROJECTNAME")) "3076N")(= (strcase (GETVAR "PROJECTNAME")) "3076N")(= (strcase (GETVAR "PROJECTNAME")) "CG3480N")(= (strcase (GETVAR "PROJECTNAME")) "CG3480R")
(= (strcase (GETVAR "PROJECTNAME")) "4058N")(= (strcase (GETVAR "PROJECTNAME")) "4058R")(= (strcase (GETVAR "PROJECTNAME")) "E2000N")(= (strcase (GETVAR "PROJECTNAME")) "E2000R")
(= (strcase (GETVAR "PROJECTNAME")) "NREN")(= (strcase (GETVAR "PROJECTNAME")) "NREN")(= (strcase (GETVAR "PROJECTNAME")) "SBN")(= (strcase (GETVAR "PROJECTNAME")) "SBR")
(= (strcase (GETVAR "PROJECTNAME")) "SQEN")(= (strcase (GETVAR "PROJECTNAME")) "SQER")
(= (strcase (GETVAR "ORIENTATION")) "VERTICAL")(= (strcase (GETVAR "LOCATION")) "RIGHT"))(= (strcase (GETVAR "SHTSIZE")) "11X17"))
(setq foldr&flname_2copy
'("C:\\Documents and Settings\\wizman\\My Documents\\" ;<<< input here folder path of source
"Drawing1.dwg" ;<<< input here filename to be copied
)
) ;_ end_setq
);_ end_PROGN
(if (findfile (apply 'strcat foldr&flname_2copy))
(if (findfile (strcat (getvar "dwgprefix") (cadr foldr&flname_2copy)))
(alert "\n File Exists in Destination Folder")
(progn
(setq curr_dir (strcat (getvar "dwgprefix") (cadr foldr&flname_2copy)))
(vl-file-copy (apply 'strcat foldr&flname_2copy) curr_dir)
(prompt (strcat (strcase (cadr foldr&flname_2copy))
" copied to "
(strcase (getvar "dwgprefix"))
) ;_ end_strcat
) ;_ end_prompt
) ;_ end_progn
) ;_ end_if
(alert "\n Source File Does not Exist")
) ;_ end_if
(princ)
) ;_ end_defun

3 REPLIES 3
Message 2 of 4
dbroad
in reply to: sovby

I can't understand your code.  PROGN is just a wrapper for various expressions.  It returns the value of the last expression.  There should be no need to strcase the same variable 20 times.  Consider the revised fragment.

(IF (member (strcase (getvar "projectname"))
'("3076N" "3076N" "CG3480N" "CG3480R" "4058N" "4058R"
"E2000N" "E2000R" "NREN" "NREN" "SBN" "SBR" "SQEN"
"SQER"))
(progn ;|then some actions...|;)
(progn ;|else some actions...|;)
);endif

Architect, Registered NC, VA, SC, & GA.
Message 3 of 4
Kent1Cooper
in reply to: sovby


@sovby wrote:

One of the uses of the progn function from what i have been told is that so you can have a strcase that is multiple lines. In other words so that your code doesnt go all the way across the page. Is that correct & if so am i using this properly in my code.

....


You don't need it for that.  You could apply a (strcase) function to a long string broken up to keep it from being too long for one line with the use of (strcat), something like this:

 

(strcase

  (strcat

    "The beginning part of a really long text string, followed by "

    "the next part of that really long string, followed by "

    "the last part of it."

  ); strcat

); strcase

 

In your example, if I understand what's going on, you don't need the first (progn), but you do need the second one.  That combines more than one thing [what should happen if the file isn't there] into one thing as the 'else' argument for the (if) function.  That's the primary use of (progn), since (if) functions can take only one function for either the 'then' or 'else' expression.

 

You can avoid all those repetitive (strcase (GETVAR "PROJECTNAME")) entries by consolidating the project names into a list, and checking simply whether that variable is in the list:

 

(defun ...whatever...
....
;;;; don't need (progn
  (IF
    (or
      (member
        (strcase (GETVAR "PROJECTNAME")); one time
        '("3076N" "CG3480N" "CG3480R" "4058N" "4058R" "E2000N"
          "E2000R" "NREN" "NREN" "SBN" "SBR" "SQEN" "SQER")
      ); member
      (= (strcase (GETVAR "ORIENTATION")) "VERTICAL")
      (= (strcase (GETVAR "LOCATION")) "RIGHT"); [had extra right parenthesis here, if I'm reading things right]
      (= (strcase (GETVAR "SHTSIZE")) "11X17")
    ); or
    (setq foldr&flname_2copy
      '(
        "C:\\Documents and Settings\\wizman\\My Documents\\" ;<<< input here folder path of source
        "Drawing1.dwg" ;<<< input here filename to be copied
      ); quoted list
    ) ;_ end_setq
  ); if [was missing this]
;;;; don't need ); progn
  (if (findfile (apply 'strcat foldr&flname_2copy))
    (if (findfile (strcat (getvar "dwgprefix") (cadr foldr&flname_2copy))); then for outer (if)
      (alert "\n File Exists in Destination Folder"); then argument for inner (if)
      (progn ; one function for else argument for inner (if) -- this is where you do need (progn)
        (setq curr_dir (strcat (getvar "dwgprefix") (cadr foldr&flname_2copy)))
        (vl-file-copy (apply 'strcat foldr&flname_2copy) curr_dir)
        (prompt
          (strcat
            (strcase (cadr foldr&flname_2copy))
            " copied to "
            (strcase (getvar "dwgprefix"))
          ) ;_ end_strcat
        ) ;_ end_prompt
      ) ;_ end_progn
    ) ;_ end_if
    (alert "\n Source File Does not Exist"); else argument for outer (if)
  ) ;_ end_if
  (princ)
) ;_ end_defun

Kent Cooper, AIA
Message 4 of 4
sovby
in reply to: dbroad

ok thanks. I'm still a newbie at this so this is very helpful. i've copied some code from various lisp rotines from my company & also from various rotines that i have found online. what i'm trying to do is to create a routine that copies a certain title block based on the projectname variable. It will either be an 8.5x11 border or a 11x17 border. i will have a dialog box associated with it to where the user will select the options & based on what is selected the correct border will be copied into the current directory. Next, i will have to figure out how to create a new tab in my current drawing @ have the xrefed border attached. I was hoping to do this in one routine but i may have to do it in two. One to copy & one to create the new tab, & attach the xrefed border

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

Post to forums  

Autodesk Design & Make Report

”Boost