jonathann3891 Posted January 10 Posted January 10 I want to edit my lisp below so that if the user enters "?" at the prompt, it will open an excel file. What is the best way to approach this? (defun c:SetRole (/ MRole ss) (vl-load-com) (setq MRole ((lambda ( input ) (if (eq "" input) MRole input)) (getstring (strcat "\nEnter Model Role: <" (setq MRole (cond ( MRole ) ( "Column" ))) "> : "))) ss (ssget) nn (sslength ss) i 0 );setq (while (< i nn) (progn (setq ee (cdr (car (entget (ssname ss i))))) (hype_setBeamEntity ee) (hype_getBeamData) (if (= 0 (hype_getError)) (progn (hype_setBeamRole MRole) (hype_modifybeam) ) (progn (hype_setPlateEntity ee) (hype_getPlateData) (if (= 0 (hype_getError)) (progn (hype_setPlateRole MRole) (hype_modifyplate) ) ) ) ) (setq i (1+ i)) ) ) (princ) ) Quote
pkenewell Posted January 10 Posted January 10 @jonathann3891 I think you need to supply more information. From your post I don't know what this routine is doing or how it's doing it, let alone where you want to open an Excel file. Quote
jonathann3891 Posted January 10 Author Posted January 10 (edited) This lisp is specific to Advance Steel. I'm looking for a general example of how to accomplish this. Edited January 10 by jonathann3891 Quote
pkenewell Posted January 10 Posted January 10 (edited) @jonathann3891 If you just want to open an Excel file using the computers default shell open location for a registered extension: EDIT: Correction made to substitute the %1 in the shell open with the file (vl-load-com) (defun _GetShellOpen (ext / id) (if (setq id (vl-registry-read (strcat "HKEY_CLASSES_ROOT\\" ext))) (vl-registry-read (strcat "HKEY_CLASSES_ROOT\\" id "\\shell\\Open\\command")) ) ) (defun c:startExcel () (startapp (vl-string-subst ;; NOTE: include your file on line below with path if not in search path "MyExcelfile.xlsx" "%1" (_GetShellOpen ".xlsx") ) ) ) Edited January 10 by pkenewell Quote
jonathann3891 Posted January 10 Author Posted January 10 (edited) @pkenewell the actual opening of the excel file isn't where I'm stuck, but I appreciate your help. What I'm asking is if there is a way to open the excel file is the user's input is "?". Edited January 10 by jonathann3891 Quote
pkenewell Posted January 10 Posted January 10 (edited) @jonathann3891 Oh OK. Yes (getkword) is probably what you are looking for, but if you don't have other keywords, then (getstring) or another input method will work depending on what you need. (defun c:foo () (initget "Yes No ?") (if (= "?" (setq res (getkword "Select Option [Yes/No/?]: <Yes> "))) (c:startexcel) ) ) Edited January 10 by pkenewell Quote
BIGAL Posted January 10 Posted January 10 Once you have the ? and a filename. (defun openexcel-sheetname (filename sheetname / ) (setq myBook (vl-catch-all-apply 'vla-open (list (vlax-get-property myXL "WorkBooks") fileName))) (setq mySheet (vl-catch-all-apply 'vlax-get-property (list (vlax-get-property myBook "Sheets") "Item" sheetName))) (vlax-invoke-method mySheet "Activate") ) (or (setq myxl (vlax-get-object "Excel.Application")) (setq myxl (vlax-get-or-create-object "excel.Application")) ) Do you know how to put & get cells in the excel ? Quote
Steven P Posted January 11 Posted January 11 (edited) Are you wanting something as easy as an "IF" statement then. What are you trying to do with the lambda for MRole input? Keeping it simple won't just the "(getstring (strcat...... ") part work just the same? (defun c:SetRole (/ MRole ss) (vl-load-com) (setq MRole ((lambda ( input ) (if (eq "" input) MRole input)) (getstring (strcat "\nEnter Model Role (or '?' for Excel): <" (setq MRole (cond ( MRole ) ( "Column" ))) "> : "))) ); end setq (if (= MRole "?") (Princ "Open Excel Here") ) ; end if (setq ss (ssget) nn (sslength ss) i 0 );setq (while (< i nn) (progn (setq ee (cdr (car (entget (ssname ss i))))) (hype_setBeamEntity ee) (hype_getBeamData) (if (= 0 (hype_getError)) (progn (hype_setBeamRole MRole) (hype_modifybeam) ) (progn (hype_setPlateEntity ee) (hype_getPlateData) (if (= 0 (hype_getError)) (progn (hype_setPlateRole MRole) (hype_modifyplate) ) ) ) ) (setq i (1+ i)) ) ) (princ) ) Edited January 11 by Steven P Quote
BIGAL Posted January 11 Posted January 11 (edited) Multi radio buttons.lspAnother, (if (not AH:Butts)(load "Multi radio buttons.lsp")) ; loads the program if not loaded already (if (= ahdef nil)(setq ahdef 1)) ; this is needed to set default button ; you can reset default button to user pick (setq ans (ah:butts ahdef "V" '("Please choose " "Model Role" "Excel"))) ; ans holds the button picked value as a string Edited January 12 by BIGAL Quote
jonathann3891 Posted January 11 Author Posted January 11 I got it working with some help. The solution was very simple! (defun c:SetRole (/ ss) (setq MRole ((lambda ( input ) (if (eq "" input) MRole input))(getstring (strcat "\nEnter Model Role: <" (setq MRole (cond ( MRole ) ( "Column" ))) "> or ?: "))) );setq (if(eq MRole "?") (progn (startapp "explorer" (findfile "AST Roles.xlsx")) );progn (progn ;else (setq ss (ssget) nn (sslength ss) i 0 );setq (while (< i nn) (progn (setq ee (cdr (car (entget (ssname ss i))))) (hype_setBeamEntity ee) (hype_getBeamData) (if (= 0 (hype_getError)) (progn (hype_setBeamRole MRole) (hype_modifybeam) );progn (progn (hype_setPlateEntity ee) (hype_getPlateData) (if (= 0 (hype_getError)) (progn (hype_setPlateRole MRole) (hype_modifyplate) );progn );if );progn );if (setq i (1+ i)) ) ;progn ) ;while ) ;progn else ) ;if (princ) ) 2 Quote
Recommended Posts
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.