The Buzzard Posted May 17, 2010 Author Share Posted May 17, 2010 It looks to me like you are not doing anything with the return of GetDimVariables - look at my example. I was under the assumption it was to be used as I show here. Are you telling me this returns the values? This is not clear to me in your example. (cond ((= CLASS "150#") (setq FNAM (findfile "AF150.dim"))(GetDimVariables FNAM SLST)) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 17, 2010 Share Posted May 17, 2010 Yes, look at the last return of the function. This is how the majority of subfunctions are engineered - to take input(s) and return output(s). Look at my example in post #18. Quote Link to comment Share on other sites More sharing options...
The Buzzard Posted May 17, 2010 Author Share Posted May 17, 2010 Sorry, I must have missed that post, I was wondering about how much further I would need to go to separate the values, But that clears things up. Thanks pointing that out. Looks like I have some fixes to make before I get to that. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 17, 2010 Share Posted May 17, 2010 No worries If I were you, I would make sure I understood the function completely, then you can use that knowledge to better your programming ability Quote Link to comment Share on other sites More sharing options...
The Buzzard Posted May 17, 2010 Author Share Posted May 17, 2010 Ok I ran the Test.lsp from post 18. I see that you concatenate the file name and I also see you are setting three variables (a b c). It does not seem like I have to add anything to this code to see it run, So I took out the variable localization of a b c and run the program. It does not seem to do anything. When I check the variables, there are no values. I even added (vl-load-com) and still nothing. Quote Link to comment Share on other sites More sharing options...
The Buzzard Posted May 17, 2010 Author Share Posted May 17, 2010 Lee, I managed to fix the code that I had to my liking. Although I did not use the code you provided I got quite a bit from this thread and some ideas you provided in the codes you posted. 1. I fixed the issue you mentioned about the protected symbol. 2. I changed the comma character to "|" and provided extra spacing in the dim file. This makes it now easier to read. 3. I provided a conditional to look for the file name. If the file is missing the program goes to an alert letting the user know what file is missing. It then returns to the menu after clicking Ok allowing the user to exit the program without an embarrassing crash so they can remedy the problem. Even though this may seem petty, The method used provides good error trapping to inform the user of a problematic issue they could run in to. I really appreciate your help on this as well as the push in the right direction. As always Thanks a million. The Buzzard Below are the fixes: AF_SFS local function ; ; Set Flange Selection Function. ; ; OD = Outside Dia. ; TH = Thickness for all flanges except Lap Joint ; TJ = Thickness for Lap Joint ; RD = Raised Face Dia. ; HD = Hub Dia. ; HK = Hub OD at conn. for Weld Neck ; NH = Number of Holes ; HR = Hole Radius ; BC = Bolt Circle ; B1 = Flange ID for Slip-On ; B2 = Flange ID for Weld Neck & Socket Weld ; B3 = Flange ID for Lap Joint ; B4 = Flange ID for Threaded ; FT = Raised Face Thickness ; L1 = Flange Length for Threaded, Slip-On & Socket Weld ; L2 = Flange Length for Weld Neck ; L3 = Flange Length for Lap Joint ; CE = Center Line Extention ; (defun AF_SFS () (AF_CPS) (setq SELECTION (nth (atoi AF:FTYP) DATA1) FTYP (car SELECTION) AF:CLASSES (nth (atoi AF:CLASS)(cdr SELECTION)) CLASS (car AF:CLASSES) SIZE (nth (atoi AF:SIZE)(cdr AF:CLASSES)) VIEW AF:VIEW DFLG AF:DFLG FACE AF:FACE DUNT AF:DUNT SLST nil SIZE (strcat "*"SIZE) FNAM (strcat "AF"CLASS".dim")) (cond ((<= (setq FILE (findfile FNAM)) nil) (alert (strcat "\n"FNAM" file missing."))(AF_MF)) (t (setq F (open FILE "R") ITEM (read-line F)) (while ITEM (if (= ITEM SIZE) (setq DATA2 (read-line F) ITEM nil) (setq ITEM (read-line F)))) (if DATA2 (progn (setq MAXS (strlen DATA2) CNT 1 CHR 1) (while (< CNT MAXS) (if (/= "|" (substr DATA2 CNT 1)) (setq CHR (1+ CHR)) (setq NUM (atof (substr DATA2 (1+ (- CNT CHR)) CHR)) DLST (append DLST (list NUM)) CHR 1)) (setq CNT (1+ CNT))) (setq NUM (atof (substr DATA2 (1+ (- CNT CHR)))) DLST (append DLST (list NUM))))) (close F))) (mapcar 'set '(OD TH TJ RD HD HK NH HR BC B1 B2 B3 B4 FT L1 L2 L3 CE) DLST) (setq NH (rtos NH 2 0)) (setq NH (atoi NH)) (cond ((= AF:VIEW "FACE")(AF_CFV)) ((= AF:VIEW "SIDE")(AF_CSV))) (AF_PL) (princ)) ; ;///////////////////////////////////////////////////////////////////////////////////////// AF150#.dim ; ; 150# Flange Dimension List ; ; OD = Outside Dia. ; TH = Thickness for all flanges except Lap Joint ; TJ = Thickness for Lap Joint ; RD = Raised Face Dia. ; HD = Hub Dia. ; HK = Hub OD at conn. for Weld Neck ; NH = Number of Holes ; HR = Hole Radius ; BC = Bolt Circle ; B1 = Flange ID for Slip-On ; B2 = Flange ID for Weld Neck & Socket Weld ; B3 = Flange ID for Lap Joint ; B4 = Flange ID for Threaded ; FT = Raised Face Thickness ; L1 = Flange Length for Threaded, Slip-On & Socket Weld ; L2 = Flange Length for Weld Neck ; L3 = Flange Length for Lap Joint ; CE = Center Line Extention ; ;OD | TH | TJ | RD | HD | HK | NH | HR | BC | B1 | B2 | B3 | B4 | FT | L1 | L2 | L3 | CE *1/2 3.50 | 0.38 | 0.44 | 1.38 | 1.19 | 0.84 | 4.0 | 0.31 | 2.38 | 0.88 | 0.62 | 0.90 | 0.5 | 0.0625 | 0.56 | 1.81 | 0.62 | 0.5 Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 17, 2010 Share Posted May 17, 2010 Oh I missed one variable set: (defun c:test ( / class size a b c ) (setq class "150#" size "*1/2") (if (mapcar (function set) '( a b c ) (GetDimVariables (strcat "AF" (substr class 1 (1- (strlen class))) ".dim") size ) ) (mapcar (function print) (list a b c)) ) (princ) ) (defun GetDimVariables ( file flag / _ReadNextifFoo StringParser l ) (defun _ReadNextifFoo ( file foo) ;; Lee Mac (cond ( (not (setq f (open file "r"))) nil) (t (while (and (setq n (read-line f)) (not (foo n)))) (setq n (read-line f)) (close f) ) ) n ) (defun StringParser ( str del ) ;; Lee Mac (if (setq pos (vl-string-search del str)) (cons (substr str 1 pos) (StringParser (substr str (+ pos 1 (strlen del))) del)) (list str) ) ) (mapcar (function distof) (cond ( (not [color=Red][b](setq file[/b][/color] (findfile file)[b][color=Red])[/color][/b]) nil) ( (setq l (_ReadNextifFoo file (lambda ( line ) (eq line flag)))) (StringParser l ",") ) ) ) ) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 17, 2010 Share Posted May 17, 2010 By the way, I'm not sure that I understand your logic here: (<= (setq FILE (findfile FNAM)) nil) If the symbol FILE is successfully bound to a value it will be in a sense greater than nil, else it will be equal to nil. But at no point will it ever be less than nil. In my opinion the inequality operators are better served for use with numerical arguments, I would use boolean operators like OR,AND,NOT for a validity check. Quote Link to comment Share on other sites More sharing options...
The Buzzard Posted May 17, 2010 Author Share Posted May 17, 2010 By the way, I'm not sure that I understand your logic here: (<= (setq FILE (findfile FNAM)) nil) If the symbol FILE is successfully bound to a value it will be in a sense greater than nil, else it will be equal to nil. But at no point will it ever be less than nil. In my opinion the inequality operators are better served for use with numerical arguments, I would use boolean operators like OR,AND,NOT for a validity check. Actually I tried that and had a problem with it. Who knows, I may have got ahead of myself at those times and forgot to do something else needed. I will look in to that, But for now it seems to be alright. With regard to the missing variable set... Now he tells me! Quote Link to comment Share on other sites More sharing options...
The Buzzard Posted May 17, 2010 Author Share Posted May 17, 2010 Just test all four and heres what I get: not - Error: too many arguments when OK is selected or - will post the ALERT if the file exists then give Error: bad argument type on exit and - Error: bad argument type, stringp nil if file is missing I guess it does not figure, But I cannot argue with the fact that Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 17, 2010 Share Posted May 17, 2010 Think about what you are doing - don't just try a bunch of different functions... You are testing for a null value, so why use OR or AND... Just (cond ( (not (setq file (findfile <filename>))) (princ "\n** File not Found **") ) (t ... I use the very same construct in the example I provided... As I said: If I were you, I would make sure I understood the function completely, then you can use that knowledge to better your programming ability Quote Link to comment Share on other sites More sharing options...
The Buzzard Posted May 17, 2010 Author Share Posted May 17, 2010 Think about what you are doing - don't just try a bunch of different functions... You are testing for a null value, so why use OR or AND... Just (cond ( (not (setq file (findfile <filename>))) (princ "\n** File not Found **") ) (t ... I use the very same construct in the example I provided... As I said: Ok, I just tried that with the ALERT and it works. I just had to remove the "nil)" from it. When I tested it, I had that in there. Thats where the problem was. Thanks again. Quote Link to comment Share on other sites More sharing options...
The Buzzard Posted May 17, 2010 Author Share Posted May 17, 2010 Lee, I went back to your Test.lsp and this is what you had: (cond ( (not (findfile file)) nil) With that in my code mixed with not and the alert did not work. My first impression would be that "nil)" was required. Dammed if you do and Dammed if you don't. Tested again and I get this Error on exit: ; error: bad argument type: numberp: nil Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 17, 2010 Share Posted May 17, 2010 Yes that is in my subfunction to return nil should the file not be found, the nil being in place of the 'princ'. Quote Link to comment Share on other sites More sharing options...
The Buzzard Posted May 17, 2010 Author Share Posted May 17, 2010 I closed out the conditional at the point where my loop function starts up. I had the conditional closed out at the end of (close F), I believe thats where the error was being created. No more error now. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 17, 2010 Share Posted May 17, 2010 But that would mean the function would still try to execute even if the file was not found... Don't worry, I give up. Quote Link to comment Share on other sites More sharing options...
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.