Beeftimer Posted February 11, 2015 Posted February 11, 2015 Hello all, I'm attaching a piece of code that I found online (it seems that maybe many of you will already be familiar with it). It seems like it would do exactly what I'm needing, but the problem is that one function will only allow me to insert a string into a cell, but I need to insert the value of a variable instead. This would allow me to modify the code for my own purposes, but I do not know how to go about doing this. I've attached the entire "GetExcel" code here. The particular function I'm referring to is the "PutCell" function portion of the code. I need to modify PutCell to allow me to insert a variable instead of a string. Any ideas? getExcel.lsp Quote
Commandobill Posted February 11, 2015 Posted February 11, 2015 If you look at the code more closely, what it is actually looking for is a list. When you send a string to it, it will turn it into a list. Without re-writing that section of code, what you could do is send your variables as a list to the function. Otherwise I'm pretty sure you could change this bit of code (if (= (type Data@) 'STR) (setq Data@ (list Data@)) ) To This (not tested) (if (not (= (type Data@) 'LIST)) (setq Data@ (list Data@)) ) Then you should be able to send any single variable to it. Quote
Beeftimer Posted February 11, 2015 Author Posted February 11, 2015 That did the trick. Thank you, Commandobill. I think I understand what you did. Quote
Commandobill Posted February 11, 2015 Posted February 11, 2015 No problem. If you did change his code, make sure you note that somewhere as a comment just in case you ever post the code again. Quote
Beeftimer Posted February 12, 2015 Author Posted February 12, 2015 No problem. If you did change his code, make sure you note that somewhere as a comment just in case you ever post the code again. Indeed. Thank you. Quote
RLispLearner Posted August 21, 2021 Posted August 21, 2021 Is it possible to show your code along with the Putcell function? I've been trying to figure out how to add values to the Putcell command from GetExcel.lsp myself by using variables but cant get it so far. Example: Manually (PutCell "B10" '("A006" 3)); It puts A006 into Column B/row 10. Put number 3 in Column C row 10. I will need an If Statement to grab values out of blocks and save them as variables because I dont know what will be found per drawing. Im getting an Attribute Tag ID name from a block and also its count (duplicates). Save each of those values to its own variable and then add variable to the Pullcell command. Need to make an If statement kind of like this: "If you find a block attribute tag name "A006" in a this drawing, make the variable "mytagid" with that value. Get the count of identical blocks with that Name and save count number as variable Mytagcount. Then trying something like this: (PutCell "B10" '(mytagid Mytagcount)) When I try that and open Excel it only puts in the variable names I create (mytagid and Mytagcount) into the cells instead of the actual values ( "A006" and "3"). Any help is greatly appreciated... R. Quote
CADTutor Posted August 22, 2021 Posted August 22, 2021 Note that the OP was made 6 years ago and those involved haven't visited for a few years. Still, it's worth a punt - this community likes to help Quote
RLispLearner Posted August 22, 2021 Posted August 22, 2021 Thanks. I guess I'm late to the party. Ha! I did post a question on this subject here earlier but still haven't gotten a response so trying other posts: If you come across any place that has discussed the "Putcell" function from Getexcel.lsp and how to use it, please pass it on. I've looked everywhere and cant seem to find what I need. Thanks! Quote
BIGAL Posted August 23, 2021 Posted August 23, 2021 (edited) My version is based on getexcel the difference in this case was a single variable, I made mine as I could not see value in making a list for a single variable. This definately works for numbers as that was the required task (defun putcell (cellname val1 / ) (setq myRange (vlax-get-property (vlax-get-property myxl "ActiveSheet") "Range" cellname)) (vlax-put-property myRange 'Value2 val1) ) (defun getcell (cellname / ) (setq myRange (vlax-get-property (vlax-get-property myxl "ActiveSheet") "Range" cellname)) (princ (vlax-variant-value (vlax-get-property myRange 'Value2))) ) (putcell "E7" x) ; a number (putcell "E11" y) (putcell "E15" ans) ; a string This may be useful it is a work in progress. Alan Excel library.lsp There is also a bundle of functions by Denton written in C# that can be used much like what I posted. Edited August 23, 2021 by BIGAL Quote
RLispLearner Posted August 26, 2021 Posted August 26, 2021 Thanks BigAl for the input. Sorry for the late reply. I'm finally back into things now and I appreciate your response. Quick Question: Does your Putcell function replace the Putcell function found in the Getexcel.lsp or is it an addition to the routine? I am down to three objectives with my overall task: 1. Get block names and their counts in a drawing. 2. Match any block name found in drawing to an existing list of block names in column A of an Excel file. If a block name is found that matches... 3. Put the count number of that block in same row as block name but under Column C. For your example (putcell "E7" x) ; a number Would "X" be a variable that holds a value found in the drawing. Then that value is placed into Column E row 7? Just making sure I understand correctly.. All help is appreciated! Thanks BigAl! R. Quote
BIGAL Posted August 27, 2021 Posted August 27, 2021 (edited) I need to rename the defuns to say ah:putcell and will do. The main reason was I found getexcel insisted on the excel not being open and for my client needed to check is it already open and if so dont close when finished. I do appreciate the original code provided by getexcel and helped a lot. Where are we at with the forums/autodesk post about this topic, try to keep multi forums up to date. I would use the getexcel get & put a range of cells method. Edited August 27, 2021 by BIGAL Quote
RLispLearner Posted September 6, 2021 Posted September 6, 2021 Thanks BigAl. Here is the link to a solution from pbejse. https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/autolisp-to-pass-block-attribute-id-name-and-block-count-of-a/td-p/10545894 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.