Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

(member) function, need a boolean return, help!!

4 REPLIES 4
Reply
Message 1 of 5
bhull1985
431 Views, 4 Replies

(member) function, need a boolean return, help!!

Hey all, still progressing as best I can with this application to send attribute information to excel.

 

In order to handle duplicate tags we've decided that the app should flag the items within excel, and the easiest way that I've seen to do this programmatically is to color the excel cells based on if the values for that cell are part of a list of duplicate tag values.

 

The problem I'm facing is that if I use the (member) function in this manner:

 

(setq ldata (list bdata adata))
("18" "TT")
Command: !ldata
("18" "TT")
Command: (member @dupeslist ldata)
nil
Command: (member ldata @dupeslist)
(("18" "TT") ("612" "FQ") ("312" "TI") ("12" "FT") ("22" "FE") ("313" "TI"))

 

 

and as you can see there , and as to be expected the member function is returning the @dupeslist. I need to fire a subfunction off if "ldata" is in @dupeslist, because this will tell me that it's a duplicate tag and that the cell it's being placed into should be colored. I've got that code accomplished, i'm having trouble finding a way to be able to set up a conditional that will work with the member function.

 

I'm sure it's just lack of experience in doing this, because I know it can be done. I tried looking into (boole) but that required bit-code arguments that did not seem helpful or useful.

 

For completeness, here's more of the subfunction that i'll be using the call to member in, so you all can see how it's being used.

 

 

(setq cell (strcat "B" @excel_row))
;;starting cell value to leave one line from the top for a column header
;;subfunction (string_ cell) will increment to "A2" and then
;;"A3", incrementing each pass of the repeat loop until the end of the list.

(setq dupedlist (list nil))
(setq c 0)
(setq len (length vallist))
(repeat len
(setq data (nth c vallist))
(setq adata (cadr data))
(setq bdata (car data))
(if (not fdata)
(setq fdata (strcat adata "-" bdata)))
(setq cell (string_ cell))
(putcell cell fdata)

(setq ldata (list adata bdata))

(member ldata @dupeslist);; putcolor function would need to follow this line IF an item matches an item in the @dupeslist

(setq fdata nil)

(setq c (1+ c))
);repeat

(if (= c len)(doname len))
;;passes number of items entered to next subroutine to enter
;;information into the next column of excel. This time it's
;;the dwg-name, which should be the same per dwg.
);defun

 

 

 

 

Thanks to all of you , very much!

Any assistance is greatly appreciated, this one is a headache for me but i'm getting through it, no small thanks to the community

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
4 REPLIES 4
Message 2 of 5
bhull1985
in reply to: bhull1985

Okay

Managed to wrap my head around the logic for this, don't know why it didn't come to me earlier.

I wrapped the member call in an if statement, and then simply raise a flag if the condition is met.

This isn't boolean, and it'd be nice to know how to do this without the extra unnecessary (maybe) conditional

(if

(member ldata @dupeslist)

(setq objx 1)

);if

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
Message 3 of 5
Kent1Cooper
in reply to: bhull1985

I don't think anything boolean is required.

 

....

(setq ldata (list adata bdata))

(if (member ldata @dupeslist);; putcolor function would need to follow this line IF an item matches an item in the @dupeslist

  (... do the putcolor function ...); thenexpr

); end if

(setq fdata nil)

....

 

It doesn't matter that (member) returns the particular sublist and all the rest of the overall list -- that's just the way (member) works.  As long as it returns anything other than nil, the thenexpr in the (if) function will be performed.

Kent Cooper, AIA
Message 4 of 5
bhull1985
in reply to: Kent1Cooper

Nod, yes, thank you very much for confirming that for me Kent.

I'm running into another issue, that is somewhat boggling....

I'm getting a consp error that vlide shows is part of the (putexcel) function!!!

it's erroring in this line..(first i'll paste the entire sub)

(defun PutCell (StartCell$ Data@ / Cell$ Column# ExcelRange Row#)
  (if (= (type Data@) 'STR)
    (setq Data@ (list Data@))
  )
  (setq ExcelRange (vlax-get-property *ExcelApp% "Cells"))
  (if (Cell-p StartCell$)
    (setq Column# (car (ColumnRow StartCell$))
          Row# (cadr (ColumnRow StartCell$))
    );setq
    (if (vl-catch-all-error-p
          (setq Cell$ (vl-catch-all-apply 'vlax-get-property
            (list (vlax-get-property *ExcelApp% "ActiveSheet") "Range" StartCell$))
          );setq
        );vl-catch-all-error-p
        (alert (strcat "The cell ID \"" StartCell$ "\" is invalid."))
        (setq Column# (vlax-get-property Cell$ "Column")
              Row# (vlax-get-property Cell$ "Row")
        );setq
    );if
  );if
  (if (and Column# Row#)
    (foreach Item Data@
      (vlax-put-property ExcelRange "Item" Row# Column# (vl-princ-to-string Item))
      (setq Column# (1+ Column#))
    );foreach
  );if
  (princ)
);defun PutCell

 The forreach is failing, giving a consp bad argument error. The data being passed to it, fills out the excel sheet so I'm not sure why it's erroring on me suddenly!! 😕

It errors after filling out the first column of information, it reaches the bottom where it should go back up and start the next column, but instead it errors.

Take a look..consp.jpg

 

So it's for whatever reason doing the (putcolor) on *ALL* of the items.....is it because the "ldata" being checked has two parts to it's value that are concatenated. Is it finding just one of the parts and assuming it's a duplicate??

 

And here's the code that's running that portion...not sure why it was working well yesterday and now all sorts of funky issues 😕

(defun putexcells ( vallist dupeslist / c data adata bdata fdata ldata cell)
;;main subfunction that will process the selection set gathered by C:Putex
;;this subfunction will place tag strings into excel columns and rows
;;then will number all of the items in excel in column "A", listing only
;;a number that increments for each tag in the list.
;;the program will then put the drawing number beside the tag values within excel


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;COL "B";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;do-tag# subfunction;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;putex-->tag#-->name;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq cell (strcat "B" @excel_row))
;;starting cell value to leave one line from the top for a column header
;;subfunction (string_ cell) will increment to "A2" and then
;;"A3", incrementing each pass of the repeat loop until the end of the list.

(setq dupedlist (list nil))
(setq c 0)
(setq len (length vallist))
(repeat len
(setq data (nth c vallist))
(setq adata (cadr data))
(setq bdata (car data))
(if (not fdata)
(setq fdata (list (strcat adata "-" bdata))))
(setq cell (string_ cell))
(putcell cell fdata)

(setq ldata (list bdata adata))
(if
(member ldata @dupeslist)
(setq objx 1)
);if
(setq fdata nil)

(if (= objx 1)
(putcolor cell 15)
);if

(setq c (1+ c))
);repeat

(if (= c len)(doname len))
;;passes number of items entered to next subroutine to enter
;;information into the next column of excel. This time it's
;;the dwg-name, which should be the same per dwg.
);defun

 

 

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
Message 5 of 5
martti.halminen
in reply to: bhull1985

Try setting in VLIDE Debug>Break on Error. then run until the error, and see View>Trace Stack to see what the actual values used in the calls are.

 

--

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost