Author Topic: bad argument type: consp <Selection set: 75d3> When run this lisp  (Read 14254 times)

0 Members and 1 Guest are viewing this topic.

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: bad argument type: consp <Selection set: 75d3> When run this lisp
« Reply #15 on: April 21, 2011, 12:46:24 PM »
Hi dgorsman,

May I ask how you start at the back end of a list and index backwards?

Thanks

Code: [Select]
(setq i (- (sslength ss_set) 1))
(while (> i -1)
   ...
   (setq i (- i 1))
)

No point in recalculating the length of a selection set/list/whatever each loop if its not going to change during the loop.  As noted, with lists it has the added advantage that using (cons...) to build a sub-list will result in the same relative order as the original list.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: bad argument type: consp <Selection set: 75d3> When run this lisp
« Reply #16 on: April 21, 2011, 12:54:26 PM »
No point in recalculating the length of a selection set/list/whatever each loop if its not going to change during the loop.

It doesn't, consider the following:

Code: [Select]
(setq l '(1 2 3 4 5)) 

(repeat (setq i (length l))
  (setq l (cdr l))
  (print i)
)

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: bad argument type: consp <Selection set: 75d3> When run this lisp
« Reply #17 on: April 21, 2011, 01:07:29 PM »
So what is a selection set?

A SelectionSet is a SelectionSet - SelectionSets have their own data type in LISP: PICKSET

Code: [Select]
Command: (setq ss (ssget))
Select objects: 2 found
Select objects:
<Selection set: 5>

Command: (type ss)
PICKSET

In a sense, a SelectionSet is an array of entities, with each entity residing at an index in the array. Formally, it cannot be called a 'LIST' since it is not of LIST type and cannot be manipulated as such.

Note also that when manipulating SelectionSets, the variable does not 'store' the SelectionSet, but rather 'points' to it (the same applies to Entity Names), hence, we can modify the SelectionSet using such functions as ssdel/ssadd without needing to change the value of the variable pointing to the SelectionSet:

Code: [Select]
Command: (sslength ss)
2
Command: (ssdel (ssname ss 0) ss)
<Selection set: 5>

Command: (sslength ss)
1

Notice we didn't use:

Code: [Select]
(setq ss (ssdel (ssname ss 0) ss))
Also, the index of entities in a SelectionSet is dynamic - if you delete an entity at index 0 say, the indexes of all the other entities will be shifted down 1:

Code: [Select]
Command: (sslength ss)
2
Command: (ssdel (ssname ss 0) ss)
<Selection set: 5>
Command: (sslength ss)
1

Command: (ssname ss 0)
<Entity name: 7ef03a78>
Command: (ssname ss 1)
nil

While and repeat evaluate expressions, repeating a course of action over and over again till stopped somehow.

While: Loop expression evaluation until a test expression returns nil.

Repeat: Loop expression evaluation a set number of times.

Foreach: evaluate one or more expressions on every item of a list in turn.

Note that when we use such functions with SelectionSets, we are only constructing a loop in which to use ssname.

I have seen vlax-for functions used on tables so this tells me that a selection set is not a table and it is not a list, so what is a selection set?  Is it its own thing?

vlax-for is for use on VLA Collection Objects, i.e. the Layer Collection, Block Collection, but also Dictionaries.

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: bad argument type: consp <Selection set: 75d3> When run this lisp
« Reply #18 on: April 21, 2011, 01:08:10 PM »
With repeat, no.  But to each their own.

I settled on using (while...) constructs for most cases of iteration a while back.  Makes coding a little faster (benefits of consistency :-) ), especially since there is usually some exit condition that needs to be checked for aside from index underflow.  It also has the benefit of visually separating out the length calculation from the continue/exit logic.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: bad argument type: consp <Selection set: 75d3> When run this lisp
« Reply #19 on: April 21, 2011, 01:09:24 PM »
I'd say they both have their uses.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: bad argument type: consp <Selection set: 75d3> When run this lisp
« Reply #20 on: April 21, 2011, 01:09:34 PM »
With repeat, no.  But to each their own.

Apologies, I thought your remark was directed at my code.

cadman6735

  • Guest
Re: bad argument type: consp <Selection set: 75d3> When run this lisp
« Reply #21 on: April 21, 2011, 01:41:25 PM »
Quote
vlax-for is for use on VLA Collection Objects, i.e. the Layer Collection, Block Collection, but also Dictionaries.

This is what I thought a selection set was, A Collection of Objects or (entities).  But I have sinced learned that entities are on the screen and objects are not.  

Line = entity, Layer = Object.

So Foreach functions, vanila and visual work on Objects (layers, dimstyles, textstyles etc...)

but the foreach function does not work on Entities, such as line, circles, text, polyline etc..  
A selection set is nothing more than a collection of entities and to manipulate this collection I have the ssFunctions with While or Repeat functions.

Just trying to verbalize my thoughts to grasp a new concept, (new concept to me that is)  Am I on the right path?

Edit:  I just reread the quote I quoted from lee and I completly contradict myself,  I need to think more on this.
« Last Edit: April 21, 2011, 01:46:27 PM by cadman6735 »

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: bad argument type: consp <Selection set: 75d3> When run this lisp
« Reply #22 on: April 21, 2011, 01:49:14 PM »
This is what I thought a selection set was, A Collection of Objects or (entities).

Accessed through the SelectionSets Collection using Visual LISP, a SelectionSet can be manipulated as a VL Collection Object, as one can use vlax-for to iterate through the VLA-Objects contained therein.

However, note that in the examples in my previous post I am not using Visual LISP.

 
But I have sinced learned that entities are on the screen and objects are not.

This is not true.

Note that Entities can be converted to VLA-Objects using vlax-ename->vla-object and vice versa using vlax-vla-object->ename

 
So Foreach functions, vanila and visual work on Objects (layers, dimstyles, textstyles etc...)

but the foreach function does not work on Entities, such as line, circles, text, polyline etc.. 

Clarify: 'work on Entities'

Foreach is a function to evaluate expressions on items in a list, nothing more.

I suggest you re-read my previous post :-)

cadman6735

  • Guest
Re: bad argument type: consp <Selection set: 75d3> When run this lisp
« Reply #23 on: April 21, 2011, 02:23:17 PM »
 :-)  Thanks Lee

I almost understand,  I am on the verge of understanding a concept and just trying to discuss my thoughts.

Quote
Note that Entities can be converted to VLA-Objects using vlax-ename->vla-object and vice versa using vlax-vla-object->ename

This is a good point, my comment comes from a blog I stumbled across and it seemed a simple enough concept.  This is why I verbalize my thoughts, so I can get different points of view for a straighter line of sight.

Thanks to all

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: bad argument type: consp <Selection set: 75d3> When run this lisp
« Reply #24 on: April 21, 2011, 02:28:30 PM »
You're welcome CADMan. :-)

I suppose the concept to keep in mind is that where the Drawing Database manipulation (modifying graphical/non-graphical entities) is concered, Vanilla AutoLISP and Visual LISP run in parallel. Some things are easier accomplished with Vanilla, some with Visual.

However, Visual LISP gives you access to the ActiveX object model, exposing methods/properties that Vanilla can't emulate.

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: bad argument type: consp <Selection set: 75d3> When run this lisp
« Reply #25 on: April 21, 2011, 02:47:01 PM »
... like things outside of AutoCAD: MSXML DOM, ADO, Excel object model, Scripting FileSystemObjects, to name a few.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}