Jump to content

If user inputs "?" at prompt then open external file


Recommended Posts

Posted

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)
)

 

Posted

@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.

Posted (edited)

This lisp is specific to Advance Steel.

 

I'm looking for a general example of how to accomplish this. 

Edited by jonathann3891
Posted (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 by pkenewell
Posted (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 by jonathann3891
Posted (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 by pkenewell
Posted

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 ?

Posted (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 by Steven P
Posted (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

image.png.29bb7c55fb1795c37bc298102e23b1da.png

Edited by BIGAL
Posted

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)
  )

 

  • Like 2

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...