Building a list using ename to use the ename again.

Building a list using ename to use the ename again.

kpennell
Collaborator Collaborator
865 Views
2 Replies
Message 1 of 3

Building a list using ename to use the ename again.

kpennell
Collaborator
Collaborator

Earlier today I received some help regarding building a list of tables with the ename and the number of rows, and sorting the tables from the most number of rows to the least number of rows.

 

The resulting retuning code is:

 

(sort_num (list '(1 ename1) '(3 ename3) '(2 ename2) '(4 ename4)))

 

and what gets returned is sorted correctly.

 

I would have thought that I could use:

 

(setq EntName (cdr (nth 0 sort_num)))

 

to select the entity and modify the location of the table.

 

Can I not use the ename to build a list and then use it again from the list?

 

I hope I explained this clearly enough.

 

Thanks in advance,

Kyran

 

 

0 Likes
Accepted solutions (1)
866 Views
2 Replies
Replies (2)
Message 2 of 3

Kent1Cooper
Consultant
Consultant
Accepted solution

@kpennell wrote:

.... 

The resulting retuning code is:

 

(sort_num (list '(1 ename1) '(3 ename3) '(2 ename2) '(4 ename4)))

 

and what gets returned is sorted correctly.

 

I would have thought that I could use:

 

(setq EntName (cdr (nth 0 sort_num)))

 

to select the entity .... 


If 'ename1' etc. are variables holding entity names, they can't be in "quoted" lists [with the apostrophe prefix], because the variable requires evaluation [read about the (quote) and (list) functions in Help].  I think you would need to have:

 

(sort_num (list (list 1 ename1) (list 3 ename3) (list 2 ename2) (list 4 ename4)))

 

But correcting that if necessary [maybe they really are <entity names>], then try:

 

(setq EntName (cadr (nth 0 sort_num)))

 

The way you have it, what will be returned is a one-item list, containing the entity name, not the entity name itself.  The (cdr) function returns the item itself, not in a list, from a dotted-pair list, such as an entity name in (assoc 0) from an entity data list, Layer name from (assoc 8), etc., but dotted-pair lists are handled differently in that regard -- yours is a list of "ordinary" lists.

 

Oh, but wait....  Is sort_num a function, or a variable name?  If you're going to use it in (nth 0 sort_num), it looks like a variable name, holding a list, and you should have something like:

 

(setq sort_num (list (list 1 ename1) (list 3 ename3) (list 2 ename2) (list 4 ename4)))

 

But if it's a function as the first line of code suggests, then getting something from it would need to be something more like:

 

(setq EntName (cadr (nth 0 (sort_num (list..... )))))

 

or you should use another variable:

 

(setq sortedlist (sort_num (list (list 1 ename1) (list 3 ename3) (list 2 ename2) (list 4 ename4))))

... and later ...

(setq EntName (cadr (nth 0 sortedlist)))

 

 

 

Kent Cooper, AIA
0 Likes
Message 3 of 3

kpennell
Collaborator
Collaborator

Hey KC,

 

To answer your question, sort_num is a function:

 

(defun sort_num (lst / lst1 )
(setq lst1 (vl-sort lst '(lambda (e1 e2) (> (car e1)(car e2)))))
);defun

 

then I go get my row numbers and entity names and then I:

 

(setq SortedList (sort_num (list AssemblyRows PlateRows ProfileRows)))
(setq EntName (cadr (nth 0 SortedList)))
(command "move" EntName "")

 

Thanks for articulating.  I've read it all, but I haven't fully understood it yet.  I'll have to piece it together one by one.

 

 

0 Likes