ssadd issue

ssadd issue

zph
Collaborator Collaborator
1,913 Views
13 Replies
Message 1 of 14

ssadd issue

zph
Collaborator
Collaborator

Good day!

 

I am having an issue with the following bit of code:

 

(foreach x i3List 
(if (equal (cadr x) tVal) (setq ssCs (ssadd (car x) ssCs)))
) ;foreach

 

i3List - list containing sublists with two elements each; car is a text entity's ename, cadr is its value (assoc 1).

 

EDIT: an example of one of the sublists:

 

(<Entity name: 7ffffb068e0> CABLE-NUM-001)

 

 

If the cadr of the sublist is equal to the text value tVal, I want to create (and add to) selection set ssCs.

 

If I replace the code in red with (princ "\n test"), the routine finishes as intended...currently, it stops at 'ssadd'.

 

Do you guys know why?

0 Likes
Accepted solutions (1)
1,914 Views
13 Replies
Replies (13)
Message 2 of 14

ВeekeeCZ
Consultant
Consultant
Accepted solution

I would expect value of (cdr (assoc 1)) as a string.

 

(<Entity name: 7ffffb068e0> "CABLE-NUM-001")

but what value is tVal? 

 

Also you need to create empty ssCs first: (setq ssCs (ssadd)), then you can add ents to it.

Message 3 of 14

Kent1Cooper
Consultant
Consultant

zph wrote:

....

If the cadr of the sublist is equal to the text value tVal, I want to create (and add to) selection set ssCs.

 

If I replace the code in red with (princ "\n test"), the routine finishes as intended...currently, it stops at 'ssadd'.

 

Do you guys know why?


You don't show how the tVal variable is set, or an example of that by itself, nor what kind of value is represented by the second item in a sublist.  But if tVal is, as you describe, a text value, then it would presumably be a string variable.  Try either:

 

a)  setting the second-item value in the sublist in a way that makes it a string for the comparison;


(<Entity name: 7ffffb068e0> "CABLE-NUM-001")

 

 

or:

 

b)  un-stringifying the tVal variable for the comparison:

 

  (if (equal (cadr x) (read tVal)) ...

 

Also [this is probably not the cause of the problem you describe, but...], you don't need to surround the (ssadd) function with a (setq) function -- (ssadd) changes what's in the selection-set variable without that.  Try [assuming you use approach a) above, in which case (=) is enough for the comparison]:

 

  (if (= (cadr x) tVal) (ssadd (car x) ssCs))

Kent Cooper, AIA
Message 4 of 14

zph
Collaborator
Collaborator

The test (if) function isn't the issue (I think), because when I use a true test case, the function acts appropriately. The way the result is handled seems to be the issue, or at least the way I've applied the ssadd function.

I added your "(setq ssCs (ssadd))" before each instance and this permitted the routine to finish successfully.

One question, though, does "(setq ssCs (ssadd)" effectively 'reset' ssCs to an empty selection set (if there is already entities contained within)?

0 Likes
Message 5 of 14

zph
Collaborator
Collaborator
The variable 'tVal' is purely the result of (cdr (assoc 1 (ssname....
0 Likes
Message 6 of 14

Ranjit_Singh
Advisor
Advisor

yes, it resets ssCs to empty set

0 Likes
Message 7 of 14

Kent1Cooper
Consultant
Consultant

@zph wrote:

....does "(setq ssCs (ssadd)" effectively 'reset' ssCs to an empty selection set (if there is already entities contained within)?


Yes [though it would need another right parenthesis at the end] -- read about (ssadd) with no arguments in Help.

Kent Cooper, AIA
0 Likes
Message 8 of 14

zph
Collaborator
Collaborator

It seems that


(setq ssCs (ssadd))

 

 

is not the same as

(setq ssCs nil)

?

 

 

EDIT:  it seems that the 'type' of empty is different.  (ssadd) is to create an empty selection set while 'nil' creates an empty variable

0 Likes
Message 9 of 14

Kent1Cooper
Consultant
Consultant

@zph wrote:
The variable 'tVal' is purely the result of (cdr (assoc 1 (ssname....

Then I can only assume your sublist example in Post 1 is not showing the double-quotes that such a list would actually contain, as both BeekeeCZ and I suggested in red in Posts 2 & 3.

Kent Cooper, AIA
0 Likes
Message 10 of 14

Ranjit_Singh
Advisor
Advisor

setq ssc nil basically resets ssc to nil (nothing). whereas, setq ssc (ssadd) makes an empty selection set. So you can think of an empty container object with no items inside. But with setq ssc nil there is no container object, there is nothing. Maybe someone else can explain it better.

0 Likes
Message 11 of 14

zph
Collaborator
Collaborator

My routine functions without the double quotes. This may be due to the use of 'EQUAL' rather than =.

 

I try to use 'EQUAL' for comparisons between two text values and '=' for comparisons between numeric values.  Is there a better way?

0 Likes
Message 12 of 14

Kent1Cooper
Consultant
Consultant

@zph wrote:

It seems that


(setq ssCs (ssadd))

 

is not the same as

(setq ssCs nil)

?

 

EDIT:  it seems that the 'type' of empty is different.  (ssadd) is to create an empty selection set while 'nil' creates an empty variable


Absolutely -- an empty selection simply has 0 items in it, but it still "exists":

 

Command: (setq test (ssadd))
<Selection set: f7>

Command: !test
<Selection set: f7>

Command: (sslength test)
0

 

whereas

 

Command: (setq test nil)
nil

Command: !test
nil

Command: (sslength test)
; error: bad argument type: lselsetp nil

 

This is the same as with text strings [an empty one is "", but still exists], but is not the same as with lists [making an empty list returns nil, and if you remove things from a list variable until it's empty, it ceases to exist].

Kent Cooper, AIA
0 Likes
Message 13 of 14

Kent1Cooper
Consultant
Consultant

@zph wrote:

My routine functions without the double quotes. This may be due to the use of 'EQUAL' rather than =.

 

I try to use 'EQUAL' for comparisons between two text values and '=' for comparisons between numeric values.  Is there a better way?


Does whatever creates those sublists actually make them without double-quotes?  I'm surprised, if it's coming from (assoc 1 ... for any entity type I can think of.  We still haven't seen how 'tVal is set -- is it actually a string, or has it been un-stringified?  A comparison of a text string with its non-string equivalent does not work, for me:

 

Command: (equal "THIS" (read "THIS"))
nil

 

Read about (=) in help -- the arguments can be numbers or strings.  I use it for simple string comparisons instead of (equal) because it's shorter and just as effective -- (equal) is needed only for more complicated circumstances [comparing lists, or numbers with a fuzz factor].

Kent Cooper, AIA
0 Likes
Message 14 of 14

zph
Collaborator
Collaborator

tVal is a string derived from the STRCAT function.

 

I thought tVal was (cdr (assoc 1 (ssname..., but I was mistaken...this was a different routine.

 

However, the STRCAT function is concatenating two string derived from multiple uses of SUBSTR and (cdr (assoc 1 (ssname....

0 Likes