Author Topic: selection of blocks  (Read 4959 times)

0 Members and 1 Guest are viewing this topic.

TAIKI

  • Guest
Re: selection of blocks
« Reply #15 on: May 14, 2014, 04:22:10 PM »
Hello

Just for information of my progression for the moment insuffisant numbers of argument on setq ename.


Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ ename fence ss i pl)
  2.   (or
  3.     (setq js (ssget "_I"))
  4.     (setq js (ssget "_P"))
  5.   )
  6.   (cond
  7.     (js
  8.      (sssetfirst nil js)
  9.      (initget "Existant Nouveau _Existent New")
  10.      (if
  11.        (eq (getkword
  12.              "\nTraiter jeu de sélection [Existant/Nouveau] <Existant>: "
  13.            )
  14.            "New"
  15.        )
  16.         (progn (sssetfirst nil nil)
  17.                (setq js (ssadd)
  18.                      js (ssget)
  19.                )
  20.         )
  21.      )
  22.     )
  23.     (T (setq js (ssget)))
  24.     (cond
  25.      (js
  26.        (repeat (setq i (sslength js))
  27.          (setq ename (ssname js (setq i (1- i)))
  28.                fence (listpol ename)
  29.                ss (ssget "_F" fence '((0 . "INSERT")))
  30.                (repeat (setq i (sslength ss))
  31.                  (setq pl
  32.                         (cons
  33.                           (cdr (assoc 10
  34.                                       (entget (ssname ss (setq i (1- i))))
  35.                                )
  36.                           )
  37.                           pl
  38.                         )
  39.                  )
  40.                )
  41.          )
  42.        )
  43.  
  44. ;;; listpol   by Gille Chanteau                                               ;
  45. ;;; Returns the vertices list of any type of polyline (WCS coordinates)       ;
  46. ;;;                                                                           ;
  47. ;;; Argument                                                                  ;
  48. ;;; en, a polyline (ename or vla-object)                                      ;
  49.  
  50.        (defun listpol (en / i p l)
  51.          (setq i (if (vlax-curve-IsClosed en)
  52.                    (vlax-curve-getEndParam en)
  53.                    (+ (vlax-curve-getEndParam en) 1)
  54.                  )
  55.          )
  56.          (while
  57.            (setq p (vlax-curve-getPointAtParam en (setq i (1- i))))
  58.             (setq l (cons (trans p 0 1) l))
  59.          )
  60.        )
  61.      )
  62.     )
  63.   )
  64. )
« Last Edit: May 16, 2014, 03:00:31 PM by TAIKI »

ymg

  • Guest
Re: selection of blocks
« Reply #16 on: May 14, 2014, 05:01:01 PM »
TAIKI,

The two repeat loops are nested.
You cannot use the same variable as index.

Code: [Select]
(repeat (setq i (sslength js))
    (setq ename (ssname js (setq i (1- i)))
          fence (listpol ename)
          ss (ssget "_F" fence '((0 . "INSERT")))
    )  
    (repeat (setq j (sslength ss))
       (setq pl (cons (cdr (assoc 10 (entget (ssname ss (setq j (1- j)))))) pl))
    )


Do use code tags around your code when posting in the Forum.

To do so Highlight the code you pasted in the reply window
and press on the # button.

ymg

TAIKI

  • Guest
Re: selection of blocks
« Reply #17 on: May 15, 2014, 04:46:57 PM »
hello

OK i have correct some parenthesis probleme the lisp charge succesfuly but now i have this error:

no function definition: LISTPOL

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ ename fence listpol ss j pl)
  2.   (or
  3.     (setq js (ssget "_I"))
  4.     (setq js (ssget "_P"))
  5.   )
  6.   (cond
  7.     (js
  8.       (sssetfirst nil js)
  9.       (initget "Existant Nouveau _Existent New")
  10.       (if (eq (getkword "\nTraiter jeu de sélection [Existant/Nouveau] <Existant>: ") "New")
  11.         (progn
  12.           (sssetfirst nil nil)
  13.           (setq
  14.             js (ssadd)
  15.             js (ssget)
  16.           )
  17.         )
  18.       )
  19.     )
  20.     (T
  21.       (setq js (ssget))
  22.     )
  23.   )
  24.   (cond
  25.     (js
  26.       (repeat (setq i (sslength js))
  27.         (setq
  28.           ename (ssname js (setq i (1- i)))
  29.           fence (listpol ename)
  30.           ss (ssget "_F" fence '((0 . "INSERT")))
  31.         )
  32.       )
  33.       (repeat (setq j (sslength ss))
  34.         (setq pl
  35.           (cons
  36.             (cdr (assoc 10 (entget (ssname ss (setq j (1- j))))))
  37.             pl
  38.           )
  39.         )
  40.       )
  41.     )
  42.   )
  43. ;;; listpol by Gille Chanteau ;
  44. ;;; Returns the vertices list of any type of polyline (WCS coordinates) ;
  45. ;;; ;
  46. ;;; Argument ;
  47. ;;; en, a polyline (ename or vla-object) ;
  48.   (defun listpol (en / i p l)
  49.     (setq i
  50.       (if (vlax-curve-IsClosed en)
  51.         (vlax-curve-getEndParam en)
  52.         (+ (vlax-curve-getEndParam en) 1)
  53.       )
  54.     )
  55.     (while
  56.       (setq p (vlax-curve-getPointAtParam en (setq i (1- i))))
  57.       (setq l (cons (trans p 0 1) l))
  58.     )
  59.   )
  60. )

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: selection of blocks
« Reply #18 on: May 15, 2014, 04:52:26 PM »
It appears that the function "listpol" is within the "c:test" function.

Place it prior to the rest of the code in "c:test" function, then it should work.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: selection of blocks
« Reply #19 on: May 15, 2014, 04:53:37 PM »
It's because you have it localized (defun c:test (/ ename fence listpol ss j pl) and it is defined after your routine runs. Put it at the top of your code.


*too slow

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

TAIKI

  • Guest
Re: selection of blocks
« Reply #20 on: May 15, 2014, 05:09:50 PM »
it's not resolved listpl on the top or not i have the same problem.

thank you.

ymg

  • Guest
Re: selection of blocks
« Reply #21 on: May 15, 2014, 05:41:01 PM »
TAIKI,

I told you the repeat Loop are nested.
and they must be nested.

In your last code this is not what you are doing.

JS est une selection de polyligne.

Pour chaque polyligne de la selection JS tu crees
une selection de blocs dans SS, c'est la premiere boucle repeat

Pour chacun des blocs dans SS tu obtiens la coordonnee
du point d'insertion que tu accumules dans la liste PL,
c'est la seconde boucle repeat

Tu traites le prochain polyligne.

Tous les polylignes sont traites PL contiens tous
les points d'insertion.


Autre point, je crois que ton "cond" ne vas pas.

Pour debuter oublie la preselection ne fais qu'une
selection de polyligne avec (SSGET)

Une fois que tu maitrises, tu pourras rajouter la preselection.

Je vois que tu as trouve comment faire pour inserer le code dans le forum.
C'est bien, maintenant tu devrais modifier tes anciens "post" pour les rajouter.

Code: [Select]
(defun c:test (/ ename fence listpol ss  i j pl)
   ;;; listpol by Gille Chanteau                                              ;
   ;;; Returns the vertices list of any type of polyline (WCS coordinates)    ;
   ;;;                                                                        ;
   ;;; Argument                                                               ;
   ;;; en, a polyline (ename or vla-object)                                   ;
   (defun listpol (en / i p l)
       (setq i (if (vlax-curve-IsClosed en)
                  (vlax-curve-getEndParam en)
                  (+ (vlax-curve-getEndParam en) 1)
               )
       )
       (while (setq p (vlax-curve-getPointAtParam en (setq i (1- i))))
          (setq l (cons (trans p 0 1) l))
       )
    )

  ;---------Corps du Programme------------------------------------------------;
    (prompt "\nSelectionnez les Polylignes a traiter: ")
    (if (setq js (ssget '((0 . "*POLYLINE"))))
       (repeat (setq i (sslength js))
           (setq  ename (ssname js (setq i (1- i)))
                  fence (listpol ename)
                     ss (ssget "_F" fence '((0 . "INSERT")))
           )     
           (repeat (setq j (sslength ss))
              (setq pl (cons (cdr (assoc 10 (entget (ssname ss (setq j (1- j)))))) pl))
           ); Fin Seconde Boucle repeat
       ); Fin Premiere Boucle repeat
   ) 
)

ymg
« Last Edit: May 15, 2014, 06:08:19 PM by ymg »

TAIKI

  • Guest
Re: selection of blocks
« Reply #22 on: May 17, 2014, 07:18:07 PM »
hello
Thanks a lot ymg, i think i have do some improvement but i have an error bad argument numberp: nil.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ listpol ename fence ss j k pl all)
  2. ;;; listpol by Gille Chanteau ;
  3. ;;; Returns the vertices list of any type of polyline (WCS coordinates) ;
  4. ;;; ;
  5. ;;; Argument ;
  6. ;;; en, a polyline (ename or vla-object) ;
  7.   (defun listpol (en / i p l)
  8.     (setq i
  9.       (if (vlax-curve-IsClosed en)
  10.         (vlax-curve-getEndParam en)
  11.         (+ (vlax-curve-getEndParam en) 1)
  12.       )
  13.     )
  14.     (while
  15.       (setq p (vlax-curve-getPointAtParam en (setq i (1- i))))
  16.       (setq l (cons (trans p 0 1) l))
  17.     )
  18.   )
  19.   ;---------Corps du Programme------------------------------------------------;
  20.  (princ "\nSélectionnez les polylignes: ")
  21.  (or
  22.     (setq js (ssget "_I"))
  23.     (setq js (ssget "_P"))
  24.   );or
  25.   (cond
  26.     (js
  27.       (sssetfirst nil js)
  28.       (initget "Existant Nouveau _Existent New")
  29.       (if (eq (getkword "\nTraiter jeu de sélection [Existant/Nouveau] <Existant>: ") "New")
  30.         (progn
  31.           (sssetfirst nil nil)
  32.           (setq
  33.             js (ssadd)
  34.             js (ssget)
  35.           )
  36.         )
  37.       );js
  38.     );cond
  39.     (T
  40.       (setq js (ssget))
  41.     );t
  42.   );or
  43. ;---------------------fin de preselection------------------------;
  44.  (setq all (ssadd))
  45.   (cond      ;1
  46.     (js
  47.       (repeat (setq i (sslength js))   ;1
  48.         (setq
  49.           ename (ssname js (setq i (1- i)))
  50.           fence (listpol ename)
  51.           ss (ssget "_F" fence '((0 . "INSERT")))
  52.         );setq
  53. ;----------------------------------------------------------------;
  54.         (cond     ;2
  55.           (ss
  56.         (repeat (setq i (sslength ss))    ;2
  57.           (setq pl (cons (cdr (assoc 10 (entget (ssname ss (setq j (1- j))))))pl))
  58. ;----------------------------------------------------------------;
  59.          (cond   ;3
  60.            (pl
  61.              (repeat (setq k (sslength pl))   ;3
  62.                (ssadd (ssname pl (setq k (1- k))) all)
  63.               );repeat3
  64.             );pl
  65. ;-----------------------------------------------------------------;
  66.                );cond3
  67.               );repeat2
  68.              );ss
  69.             );cond2
  70.         );repeat1
  71.    (sssetfirst nil all)
  72.           );js
  73.     );cond1
  74.  (prin1)
  75. );defun

i've write some note but i don't know if it was a probleme

ymg

  • Guest
Re: selection of blocks
« Reply #23 on: May 17, 2014, 08:16:49 PM »
TAIKI,

Did you try last code I posted ?

Problem is you want to play with pre-selection
forget it for the moment.

You don't use the cruise control while learning to drive.

Another reason not to use pre-selection you would need
to check every item to filter out anything that is not a
polyline.

Another question why do you use cond when an if will do ?

ymg
« Last Edit: May 17, 2014, 08:54:21 PM by ymg »

TAIKI

  • Guest
Re: selection of blocks
« Reply #24 on: May 22, 2014, 03:46:58 PM »
ymg

sorry for the time i'm worked on night.

ok i forget pre-selection but if i've undertand correcly  pl return list of insertion point of all bloc on ss but for select just bloc who have insertion point on polylin, i'll compare whith js.

My question is what function do that

Thanks

ymg

  • Guest
Re: selection of blocks
« Reply #25 on: May 22, 2014, 05:07:52 PM »
TAIKI,

pl is the list of Insertion Points for every blocks that is
we accumulate in pl every blocks picked up by each
polyline that are in js.

So the code segment that does the accumulating
is the second repeat loop.

Code: [Select]
(repeat (setq j (sslength ss))
     (setq pl (cons (cdr (assoc 10 (entget (ssname ss (setq j (1- j)))))) pl))
)

Now the above repeat loop is being repeated for each polyline in js
That why we say that the second loop is nested inside the first one.



ymg
« Last Edit: May 22, 2014, 05:13:09 PM by ymg »

TAIKI

  • Guest
Re: selection of blocks
« Reply #26 on: May 26, 2014, 04:20:43 PM »
hello

Ymg, I want to thanks you for your time, but i think i'm not ready for this lisp. For the moment I learn with easiest code and when I'll be better I'll do this code.

So thank you and see you soon for my future lisp.

Taiki