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

0 Members and 1 Guest are viewing this topic.

HasanCAD

  • Swamp Rat
  • Posts: 1422
I created this lisp to add a string to a set of attributes
When run gives this error
Code: [Select]
bad argument type: consp <Selection set: 75d3>
The lisp
Code: [Select]
(defun c:StAdd2 (/ doc spc _StartUndo _EndUndo DocActv spc
st s ss c
ent obj att atta attsa)
  (vl-load-com)

  (defun *error* ( msg ) (and doc (_EndUndo doc)) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **"))) (princ))
  (defun _StartUndo ( doc ) (_EndUndo doc) (vla-StartUndoMark doc))
  (defun _EndUndo ( doc ) (if (= 8 (logand 8 (getvar 'UNDOCTL))) (vla-EndUndoMark doc)))
  (defun DocActv (/ doc spc ) (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))) (setq spc (if (or (eq AcModelSpace (vla-get-ActiveSpace doc)) (eq :vlax-true   (vla-get-MSpace doc))) (vla-get-ModelSpace doc) (vla-get-PaperSpace doc))))

  
  (WHILE
    (setq c -1)
    (setq St (getstring "\nString to be Added: "))
    (setq ss (ssget '((0 . "INSERT") (66 . 1))))
    
    (foreach x ss
      (setq ent (ssname ss (setq c (1+ c))))
      (setq obj (vlax-ename->vla-object ent))
      (setq att (vla-get-textstring obj))
      (setq atta (strcat st att))
      (setq AttSA (vla-put-TextString att atta))
      )
    )
  )

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: bad argument type: consp <Selection set: 75d3> When run this lisp
« Reply #1 on: February 21, 2011, 07:24:17 AM »
Hi,

Without reading your code, this error message means that you're trying to pass a selection set to a function which requieres a list.
Speaking English as a French Frog

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: bad argument type: consp <Selection set: 75d3> When run this lisp
« Reply #2 on: February 21, 2011, 07:38:36 AM »
It's already made by Lee in a few hours a go.

http://www.cadtutor.net/forum/showthread.php?56993-Change-text-inside-blocks

EDIT: If server is not working at the moment , you can try later .
« Last Edit: February 21, 2011, 07:41:59 AM by Tharwat »

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: bad argument type: consp <Selection set: 75d3> When run this lisp
« Reply #3 on: February 21, 2011, 08:28:52 AM »
Code: [Select]
(foreach x ss
Just as Gile said. You are trying to step through your selection set with foreach (works on lists). Use while or repeat.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

SOFITO_SOFT

  • Guest
Re: bad argument type: consp <Selection set: 75d3> When run this lisp
« Reply #4 on: February 21, 2011, 04:24:43 PM »
Hello
This function is very useful to pass a SELECTION SET to a LIST.

Code: [Select]
( DEFUN SS-TO-LIST ( SS / CONT LIS)
( IF ( AND
       SS
       ( EQUAL ( TYPE SS ) 'PICKSET )
     )
  ( PROGN
    ( SETQ LIS NIL CONT 0 )
    ( WHILE ( < CONT ( SSLENGTH SS ) )
      ( SETQ LIS ( APPEND LIS ( LIST ( SSNAME SS CONT ) ) ) )
      ( SETQ CONT ( 1+ CONT ))
    )
  )
  ( SETQ LIS '() )
)
LIS
)
Greetings  :-)

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: bad argument type: consp <Selection set: 75d3> When run this lisp
« Reply #5 on: February 21, 2011, 05:01:45 PM »
Sofito,

append is pretty slow - better to use cons as shown in these examples.

Also, no need for:

Code: [Select]
( SETQ LIS NIL or
Code: [Select]
( SETQ LIS '() )
Since 'LIS' is localised in the code.

SOFITO_SOFT

  • Guest
Re: bad argument type: consp <Selection set: 75d3> When run this lisp
« Reply #6 on: February 21, 2011, 05:56:07 PM »
Hello people of the swamp.
Lee: I also tend to use cons better than append , but sometimes (as in this case) I use append to the list has the same order of elements as the SS. Sometimes this is important.
And yes ... LIS is localised "(DEFUN SS-TO-LIST (SS / CONT LIS <<<!!!) " but so the code is more clear to Hassan. If he has tried a foreach with a SELECTION SET, he needs a few things clear.
My DEFUN can be improved,sure, but it sure Hassan is clearly understood (I think !!!  :-) )
Thank you for your good and expert  advices.
Greetings from Madrid. :-)

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: bad argument type: consp <Selection set: 75d3> When run this lisp
« Reply #7 on: February 21, 2011, 05:58:56 PM »
but sometimes (as in this case) I use append to the list has the same order of elements as the SS. Sometimes this is important.

Very rarely :? And if the order is important, a reverse/cons combination is still quicker than append.

And yes ... LIS is localised "(DEFUN SS-TO-LIST (SS / CONT LIS <<<!!!) " but so the code is more clear to Hassan.

I don't see how redundant code is 'clear' for a beginner to learn from.

SOFITO_SOFT

  • Guest
Re: bad argument type: consp <Selection set: 75d3> When run this lisp
« Reply #8 on: February 22, 2011, 03:05:00 AM »
Hello:
best redundant code that requires 2 or 3 deductions code ... skills are developed gradually.
Except for those who are very smart, who are experts of birth. :lol:
Greetings. :-)

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: bad argument type: consp <Selection set: 75d3> When run this lisp
« Reply #9 on: February 22, 2011, 07:49:47 AM »
Dumped
I think that, I'll go back to old lisp and choose one by one and bick one by one

Code: [Select]
(defun c:SA (/ doc spc)
  (vl-load-com)

  (defun *error* ( msg ) (and doc (_EndUndo doc)) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **"))) (princ))
  (defun _StartUndo ( doc ) (_EndUndo doc) (vla-StartUndoMark doc))
  (defun _EndUndo ( doc ) (if (= 8 (logand 8 (getvar 'UNDOCTL))) (vla-EndUndoMark doc)))
  (defun DocActv (/ doc spc ) (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))) (setq spc (if (or (eq AcModelSpace (vla-get-ActiveSpace doc)) (eq :vlax-true   (vla-get-MSpace doc))) (vla-get-ModelSpace doc) (vla-get-PaperSpace doc))))

  (while
    (setq St (getstring "\nString to be Added: "))

    (WHILE
      (setq ATT (car (nentsel "\nSelect attribute: ")))
      (SETQ ATTVL (vlax-ename->vla-object ATT))
      (SETQ ATTSTR (VLA-GET-TEXTSTRING ATTVL))
      (setq StAdd (strcat ATTSTR st))
      (setq AttStAdd (vla-put-TextString ATTVL StAdd))
      )
    )
  )

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: bad argument type: consp <Selection set: 75d3> When run this lisp
« Reply #10 on: February 22, 2011, 01:23:34 PM »
but sometimes (as in this case) I use append to the list has the same order of elements as the SS. Sometimes this is important.

Very rarely :? And if the order is important, a reverse/cons combination is still quicker than append.

And yes ... LIS is localised "(DEFUN SS-TO-LIST (SS / CONT LIS <<<!!!) " but so the code is more clear to Hassan.

I don't see how redundant code is 'clear' for a beginner to learn from.

Even (reverse...) isn't needed if you start at the back end of the list then step the index backwards.  Then you can (cons...) to your hearts content and still keep the original list order.
If you are going to fly by the seat of your pants, expect friction burns.

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

cadman6735

  • Guest
Re: bad argument type: consp <Selection set: 75d3> When run this lisp
« Reply #11 on: April 21, 2011, 11:56:07 AM »
Hi dgorsman,

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

Thanks

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: bad argument type: consp <Selection set: 75d3> When run this lisp
« Reply #12 on: April 21, 2011, 11:57:47 AM »
Code: [Select]
(repeat (setq i (sslength ss))
  (setq l (cons (ssname ss (setq i (1- i))) l))
)

 :-)

cadman6735

  • Guest
Re: bad argument type: consp <Selection set: 75d3> When run this lisp
« Reply #13 on: April 21, 2011, 12:09:09 PM »
Ok

I would have never of thought to count backwards...    :ugly:

thanks for showing me a new technique.
« Last Edit: April 21, 2011, 12:19:20 PM by cadman6735 »

cadman6735

  • Guest
Re: bad argument type: consp <Selection set: 75d3> When run this lisp
« Reply #14 on: April 21, 2011, 12:39:47 PM »
So what is a selection set?

I always thought of a selection set to be a list of entities or a table of entities.

While and repeat evaluate expressions, repeating a course of action over and over again till stopped somehow. 
Foreach evaluates expressions on a list.  A concept I had not caught onto till now.

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?