nmulder Posted April 18, 2011 Posted April 18, 2011 I am looking for help with a routine I am trying to make. Our company "pastes as link" Excel files containing panel schedule information for electrical service in to our sheets. There can be anywhere from 1 to 12 per sheet. They would like a way to track what panels are on what sheet, either as an entirely separate sheet or on each sheet as a "footer" of the sheet. I was surprised to find so little information available on OLE objects. But I did come across DOSlib which has an olelist function. It produces a list of OLE objects in the drawing, including file path. (For DOSlib to work it was must be loaded--it is available for download from here: http://download.rhino3d.com/McNeel/1.0/doslib/. I then remove the file path and extension and pass it to a variable. Where I need the most help is how to write code so the routine will count the OLE's in the drawing and pass each to its own variable, with file path and extension removed. Below is what code I have, mangled as it is from trying different things. Any help is appreciated. Thanks! (defun oleVars (/ olefiles olepath olename) (vl-load-com) (setq olelist (dos_olelist 2)) (setq oll (length olelist)) (setq cntr 1) (while (< cntr oll) (setq cntr (+ cntr 1)) ) (mapcar 'set '(o1 o2 o3 o4 o5 o6) olefiles) (setq olename (vl-filename-base olepath)) (princ) ) Quote
alanjt Posted April 18, 2011 Posted April 18, 2011 (edited) LoL, I feel like we go through this about once a month. Why not just have a list that you can take items from (use nth) instead of assigning variables to each item. eg. (setq lst (mapcar 'vl-filename-base (dos_olelist 2))) eg. (nth 3 lst) Edited April 18, 2011 by alanjt Quote
nmulder Posted April 19, 2011 Author Posted April 19, 2011 I had to laugh myself when I used your line of code using mapcar. It sure was a lot quicker then the way I was doing it! Thanks for your help. I am not very experienced and what I learn is by trial and error and lots of code sampling. So, in your example, lst is in fact a list right? Why is a field not picking up that variable? I don't fully understand "foreach" or "nth" yet...your little nth example makes sense...but if I don't know how many items will be in the list in any given drawing how do I make "nth" work? Thanks again for your help. LoL, I feel like we go through this about once a month. Why not just have a list that you can take items from (use nth) instead of assigning variables to each item. eg. (setq lst (mapcar 'vl-filename-base (dos_olelist 2))) eg. (nth 3 lst) Quote
Lee Mac Posted April 19, 2011 Posted April 19, 2011 Look into using foreach perhaps: (foreach item lst (print item) ) Here 'item' is just a symbol representing an item in the supplied list (lst) - for each iteration this symbol takes the value of an item in the list until all items are processed. For example: (foreach x '(1 2 3 4 5) (princ x) ) Will print: 12345 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.