Jump to content

LISP List Search


JSYoung81

Recommended Posts

Hi I need some help. I am stuck on part of a lisp I am writting. What I am stuck on is having the LISP search a list, if that item is not in the list then add it, if not go on to the next item in the selection set. The idea is that this list will then be used to build an array. Right now it is getting stuck on the second pass of the ASSOC command. Any and all help will be appreciated.

 

(if				;check to see if pipe
      (= check "AeccDbPipe")		;if logic statement for pipe
(progn				; starts comppiling
  (setq psn (vlax-get-property item 'PartSizeName))
  (setq	check3 (assoc 'psn   part_size_list  ) )
  (if				;start if statement
    (= check3 nil)		; logic statement to see if item is in list

     (setq part_size_list (append part_size_list (list psn)))
  )				;end if
)				;end progn
    )					;end if

Edited by JSYoung81
Link to comment
Share on other sites

It would be intersting to see the format of part_size_list variable. Based on that you will decide to check its content by ASSOC or by MEMBER.

(assoc "a" '(("a" 1) ("b" 2) ("c" 3)))

(member "a" '("a" "b" "c"))

Please edit your post and add the required code tags.

Link to comment
Share on other sites

It would be intersting to see the format of part_size_list variable. Based on that you will decide to check its content by ASSOC or by MEMBER.

(assoc "a" '(("a" 1) ("b" 2) ("c" 3)))

(member "a" '("a" "b" "c"))

Please edit your post and add the required code tags.

 

it returns a string, "300 mm PVC Pipe". So as it goes through the drawing, I only want it to add new items, and skip the duplicates. My plan is then to take the list length and use that to create the array.

Link to comment
Share on other sites

I'm afraid that you didn't answered to my question; what I was asking for is what is stored in part_size_list variable:

Command: !part_size_list

???

 

Please do not quote the previous message, it just make the thread difficult to follow. And, also do me a favor and edit you first post to add the code tags.

Link to comment
Share on other sites

It would be intersting to see the format of part_size_list variable. Based on that you will decide to check its content by ASSOC or by MEMBER.

 

1+

 

It would be helpful to have more information.

 

 

 

it returns a string, "300 mm PVC Pipe". So as it goes through the drawing, I only want it to add new items, and skip the duplicates. My plan is then to take the list length and use that to create the array.

 

If your logic is to only determine if the current value is already an element of your stored value list, then there's no need to use either ASSOC, or MEMBER while they'd work just fine; they're just a bit more labor intensive on the efficiency as they actually return a result other than T/Nil. Perhaps consider VL-POSITION instead, particularly if iterating a large selection set, as you'll likely see improved performance.

 

Pseudo code:

 

(vl-load-com)

(defun _SimpleRemoveDuplicates (dataList / myList)
 ;; Example:
 ;; (_SimpleRemoveDuplicates '("1" "2" "3" "1" "4" "5"))
 ;;
 ;; Returns:
 ;; ("1" "2" "3" "4" "5")
 (foreach x dataList
   (if (not (vl-position x myList))
     (setq myList (cons x myList))
   )
 )
 (reverse myList)
)

Link to comment
Share on other sites

So, for this case your cannot use ASSOC; this is a job for MEMBER function:

(member "250 mm PVC Pipe" ("250 mm PVC Pipe" "300 mm PVC Pipe" "350 mm PVC Pipe"))

 

Thank you for fixing the above issues.

Link to comment
Share on other sites

You're welcome, JSYoung81!

 

Regarding the array, its equivalent in AutoLISP is the list. Can you post an example of the list/array structure you want to build?

Link to comment
Share on other sites

What it needs to do is go through the selection set again, and for each Pipe size add to the length of pipe to it.

 

IE: "150 mm PVC PIPE" "150.000"

 

So the next encounter of the "150mm PVC PIPE" say has a length of 55.000m, that would get added to the 150.000, so total length then would be 205.000m

Link to comment
Share on other sites

So someting like this?

'(("150 mm PVC PIPE" 150.0) ("250 mm PVC PIPE" 250.0))

 

Then initiate the list with 0 as length and adjust it later; this time will have to look indeed for ASSOC:

(setq listPipes '(("150 mm PVC PIPE" 0.0) ("250 mm PVC PIPE" 0.0)))
(if (setq subList (assoc "150 mm PVC PIPE" listPipes))
(setq listPipes (subst (list (car subList) (+ (cadr subList) 150.0))
                       subList
                       listPipes)
)
)

Link to comment
Share on other sites

So someting like this?

'(("150 mm PVC PIPE" 150.0) ("250 mm PVC PIPE" 250.0))

 

Then initiate the list with 0 as length and adjust it later; this time will have to look indeed for ASSOC:

(setq listPipes '(("150 mm PVC PIPE" 0.0) ("250 mm PVC PIPE" 0.0)))
(if (setq subList (assoc "150 mm PVC PIPE" listPipes))
(setq listPipes (subst (list (car subList) (+ (cadr subList) 150.0))
                       subList
                       listPipes)
)
)

 

As luck would have it... You might instead consider the ATOF function. :)

Link to comment
Share on other sites

Here is my current state of code, just trying to figure out where/how to place your code in there

 

 

(defun c:test
      (/	  ANS	     n		sset	   count
       check	  item	     test	2dl	   psn
       size_arrary	     list_counter	   tester
       check2	  pipe_size_list	check3
      )
 (vl-load-com)
 (setq test 0)				; tester
 (setq n 0)				;loop counter
 (setq list_counter 0)			;list counter
 (setq part_size_list nil)


 (PRINC "SELECT ALL OR MANUAL...")
 (PRINC)
 (INITGET 2 "ALL MANUAL")

 (SETQ ANS (GETKWORD "(A)LL (M)ANUAL)"))

 (IF					; CHECK ANSWER FOR SELECTION ALL
   (= ANS "ALL")
    (PROGN
      (setq sset (ssget "X"))		;selection set
      (setq count (sslength sset))	;total number of selection set
    )					;END PROGN
 )					;END IF - ALL

 (IF					; CHECK ANSWER FOR SELECTION ALL
   (= ANS "MANUAL")
    (PROGN
      (setq sset (ssget))		;selection set
      (setq count (sslength sset))	;total number of selection set
    )					;END PROGN
 )					;END IF - MANUAL

 (while

   (< n count)				;while logic statement
    (setq item (ssname sset n))	;get item from selection set
    (setq item (vlax-ename->vla-object item))
    (setq check (vlax-get-property item 'objectname))


    (if				;check to see if pipe
      (= check "AeccDbPipe")		;if logic statement for pipe
(progn				; starts comppiling
  (setq psn (vlax-get-property item 'PartSizeName))
  (setq part_size_list (append part_size_list (list psn)))
)				;end progn
    )					;end if
    (setq n (+ 1 n))			; increase loop counter
 )					;end while


 (foreach x part_size_list
   (if	(not (vl-position x myList))
     (setq myList (cons x myList))
   )
 )
 (reverse myList)

    
 
 (princ)

 (alert
   (strcat "Total length of selected objects is " (rtos test))
 )					;report pipe length
 (princ part_size_list)
 (princ MYLIST)
)

Link to comment
Share on other sites

"Total length of selected objects is "

Can you not use a property of the pipe which is the length would make it so much simpler if you dont need to produce each group size as a length. Sneaky suspison something like "pipelength"

 

If you use the dump function on a pipe it should appear. I use this all the time on other CIV3d stuff, eg vlax-get point 'rawdescription

 

;;; Dump all methods and properties for selected objects              ;
;;;===================================================================; 
;;; DumpIt                                                            ; 
;;;-------------------------------------------------------------------; 
;;;===================================================================; 
(defun C:DumpIt ( / ent) 
 (while (setq ent (entsel)) 
   (vlax-Dump-Object 
     (vlax-Ename->Vla-Object (car ent)) T
   ) 
 ) 
 (princ) 
)

Link to comment
Share on other sites

No, I need it broken out by size.

 

And it is pipelength2d, or maybe just lenght2d, or there is the 3d lenght as well

Link to comment
Share on other sites

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