CoCreate User Forum  

Go Back   CoCreate User Forum > Support > Customization

Reply
 
Thread Tools Search this Thread Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
  #1  
Old 04-03-2014, 05:38 AM
tom kirkman's Avatar
tom kirkman tom kirkman is offline
Registered User
 
Join Date: Oct 2002
Location: Perrysburg, Ohio
Posts: 397
Selecting a directory with lisp

I would like the user to select a save directory, but have the lisp program generate the file name.

FILE :value-type :filename

allows the user to select a directory and type in a file name. Is there a way just to capture the directory information?

Thanks

Tom
__________________
Tom Kirkman

Creo Elements/Direct 20.1
Dell Precision 3581
https://www.o-i.com
Reply With Quote
  #2  
Old 04-03-2014, 03:34 PM
Andy Poulsen Andy Poulsen is offline
Administrator
 
Join Date: Apr 2003
Location: Fort Collins, Colorado
Posts: 273
Re: Selecting a directory with lisp

Quote:
Originally Posted by tom kirkman View Post
I would like the user to select a save directory, but have the lisp program generate the file name.

FILE :value-type :filename

allows the user to select a directory and type in a file name. Is there a way just to capture the directory information?
Hi Tom,

Try
mydir :value-type :directory

Does that do what you need?
__________________
Andy Poulsen
AI MAXTools: Dream. Design. Done. It's that easy!
Add-ins bringing new functionality and speed to Creo Elements/Direct and CoCreate products. Now available for v17-v20+!
See them in action at www.ai-maxtools.com and then try them for yourself -- FREE!
Reply With Quote
  #3  
Old 04-08-2014, 09:59 AM
tom kirkman's Avatar
tom kirkman tom kirkman is offline
Registered User
 
Join Date: Oct 2002
Location: Perrysburg, Ohio
Posts: 397
Re: Selecting a directory with lisp

I need some more help with this one.

I modified an existing working lisp program to now allow the user to select the save directory. However; the variable does not seem to pass onto the function.

I get the following error

LISP error:
"The variable FILEDIR is unbound. This may have been caused by:
(1) Entering a string that wasn't enclosed in quotes.
(2) Entering a command belonging to a module that has not been activated.
(3) Trying to load a file that has an incorrect format.
(4) Calling a function that has not been enclosed in parenthesis ()."

Any ideas?

Thanks

Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Author:       Thomas Kirkman
; Created:      4-8-2014
; Modified:     --
; Language:     LISP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(in-package :OI_TOOLS)
(use-package :oli)
;(sd-define-available-command "Annotation" "O-I Commands" "Print_sheets_to_PDF_dir"
;	:action			"Print_sheets_to_PDF_dir"
;	:description	"Prints individual sheets to individual pdf files"
;	:commandTitle	"Print Sheets to PDF"
;	:image			"Annotation/O-I_Commands/Print_sheets_to_PDF_dir")

(sd-defdialog 'Print_sheets_to_PDF_dir
	:dialog-title "Sheets -> PDF"
   :toolbox-button t	
	:variables
	'(
	    (filedir  :value-type :directory
           :initialdirectory (sd-get-current-working-directory)
            :title "directory"
    )
	("Suffix (for example _A)")
		(suf
			:value-type :String
			:prompt-text "Enter a suffix such as the revision letter"
			:title "Suffix"
			:initial-value "")
	);variables
:ok-action '(OI_TOOLS::all-sheets-to-pdf))


(defun all-sheets-to-pdf ()

;checks for c:\working\out and creates it if it does not exist
(if (not (sd-directory-p "c:/working"))  (sd-make-directory "c:/working"))
(if (not (sd-directory-p "c:/working/out"))  (sd-make-directory "c:/working/out"))


	(dolist (a-s (sd-am-inq-all-sheets))
		(let ((sheet-num nil))
			(setf sheet-num (sd-am-sheet-struct-name (sd-am-inq-sheet a-s)))
			(setf dwgnm (format nil "~A" (subseq  (docu::docu_inq_drawing_number_text) 0 (search "-DWG" (docu::docu_inq_drawing_number_text)))))
				;;increment to the next sheet
			(am_current_sheet sheet-num) 
				;; display the name of the files created 
			(display 
				(format nil "~A~A~A_~A~A.pdf~A" "\"" filedir dwgnm sheet-num suf "\""))
		;;plot the pdf files 
			(am_plot_ex
				:PLOT_STYLE :PDF_-_SINGLE_PAGE
				:DESTINATION (format nil "~A~A_~A~A.pdf" filedir dwgnm sheet-num suf) :done
				:plot)
		);let
	);dolist
)
__________________
Tom Kirkman

Creo Elements/Direct 20.1
Dell Precision 3581
https://www.o-i.com
Reply With Quote
  #4  
Old 04-08-2014, 10:20 AM
Andy Poulsen Andy Poulsen is offline
Administrator
 
Join Date: Apr 2003
Location: Fort Collins, Colorado
Posts: 273
Re: Selecting a directory with lisp

Hi Tom,

The reason you're getting the error is that the dialog is calling a function that's defined outside of the dialog, but the function is trying to reference a variable that exists only within the dialog.

The easiest way to fix this is to move the function inside the dialog, in the :local-functions section. Here's a slightly cleaned-up version, including using "(unless ..." instead of "(if (not ..." as well as moving the "(let ..." section outside of the loop to reduce overhead. I also included "dwgnm" in the "let" definition as well since it wasn't being defined anywhere else.

I haven't tested any of this -- I just essentially moved your code into the dialog definition. If you need that function accessible for other dialogs/functions, we just need to make sure it gets called with the right parameters so it will know about the desired destination directory.
Code:
(sd-defdialog 'Print_sheets_to_PDF_dir
  :dialog-title "Sheets -> PDF"
  :toolbox-button t	
  :variables
  '(
    (filedir  :value-type :directory
	      :initialdirectory (sd-get-current-working-directory)
	      :title "directory"
	      )
    ("Suffix (for example _A)")
    (suf
     :value-type :String
     :prompt-text "Enter a suffix such as the revision letter"
     :title "Suffix"
     :initial-value "")
    );variables
  :local-functions
  '(
    (all-sheets-to-pdf ()
      ;;checks for c:\working\out and creates it if it does not exist
      (unless (sd-directory-p "c:/working") (sd-make-directory "c:/working"))
      (unless (sd-directory-p "c:/working/out") (sd-make-directory "c:/working/out"))

      ;; create the temp vars here instead of in the loop -- less overhead
      (let (sheet-num dwgnm)
	(dolist (a-s (sd-am-inq-all-sheets))
	  (setf sheet-num (sd-am-sheet-struct-name (sd-am-inq-sheet a-s)))
	  (setf dwgnm (format nil "~A" (subseq (docu::docu_inq_drawing_number_text) 0 (search "-DWG" (docu::docu_inq_drawing_number_text)))))
	  ;;increment to the next sheet
	  (am_current_sheet sheet-num) 
	  ;; display the name of the files created 
	  (display  (format nil "~A~A~A_~A~A.pdf~A" "\"" filedir dwgnm sheet-num suf "\""))
	  ;;plot the pdf files 
	  (am_plot_ex
	   :PLOT_STYLE :PDF_-_SINGLE_PAGE
	   :DESTINATION (format nil "~A~A_~A~A.pdf" filedir dwgnm sheet-num suf) :done
	   :plot)
	  ) ;dolist
	) ;let
      ) ; all-sheets-to-pdf
    ) ; local functions
  :ok-action '(OI_TOOLS::all-sheets-to-pdf))
I hope this helps!

andy
__________________
Andy Poulsen
AI MAXTools: Dream. Design. Done. It's that easy!
Add-ins bringing new functionality and speed to Creo Elements/Direct and CoCreate products. Now available for v17-v20+!
See them in action at www.ai-maxtools.com and then try them for yourself -- FREE!
Reply With Quote
  #5  
Old 04-08-2014, 11:44 AM
tom kirkman's Avatar
tom kirkman tom kirkman is offline
Registered User
 
Join Date: Oct 2002
Location: Perrysburg, Ohio
Posts: 397
Re: Selecting a directory with lisp

Andy

Thank you, that worked very well. I just added "/" after filedir for the complete directory name.

In the future, if I want to define a separate function, do I need to define the variables with "defvar" first? What is the proper syntax.

Thanks

Tom
__________________
Tom Kirkman

Creo Elements/Direct 20.1
Dell Precision 3581
https://www.o-i.com
Reply With Quote
  #6  
Old 04-09-2014, 09:21 AM
Andy Poulsen Andy Poulsen is offline
Administrator
 
Join Date: Apr 2003
Location: Fort Collins, Colorado
Posts: 273
Re: Selecting a directory with lisp

Quote:
Originally Posted by tom kirkman View Post
Thank you, that worked very well. I just added "/" after filedir for the complete directory name.

In the future, if I want to define a separate function, do I need to define the variables with "defvar" first? What is the proper syntax.
Hi Tom,

Excellent! Glad that it worked for you.

If you want to have an external function, there are a couple of ways to do it. You can use the defvar approach, which defines "global" variables (within your own lisp package). There are certainly times when this approach works well.

However, in most cases, global variables aren't recommended, so you'd want to pass any desired variables as parameters to the function.

To do this for the above example, you could have the function defined outside of the dialog, but starting the definition something like
Code:
(defun all-sheets-to-pdf (filedir)
Then your :ok-action could be
Code:
:ok-action '(all-sheets-to-pdf filedir)
It's very important to note that the dialog variable filedir and the function parameter filedir can be named different things, as they are different variables. You could call all-sheets-to-pdf from a different function using a different variable name, and get the same results -- the function parameter name could be whatever you want, as it's just a placeholder that gets assigned to be whatever parameter is sent to the function.

In other words, the parameter name could be anything you want (such as mydir instead of filedir). In this case, you'd just need to make sure that the function references "mydir" everywhere it looks for the relevant directory.

Does this make sense?
__________________
Andy Poulsen
AI MAXTools: Dream. Design. Done. It's that easy!
Add-ins bringing new functionality and speed to Creo Elements/Direct and CoCreate products. Now available for v17-v20+!
See them in action at www.ai-maxtools.com and then try them for yourself -- FREE!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 04:32 AM.



Hosted by SureServer    Forums   Modeling FAQ   Macro Site   Vendor/Contractors   Software Resellers   CoCreate   Gallery   Home   Board Members   Regional User Groups  By-Laws  

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
You Rated this Thread: