Author Topic: selection of blocks  (Read 4960 times)

0 Members and 1 Guest are viewing this topic.

TAIKI

  • Guest
selection of blocks
« on: May 10, 2014, 03:56:05 PM »
Hello

First I’m sorry for my English, I’m French.

Just i want to pick a polyline and the result is a selection of all blocks who have the insertion point on this polyline.

After all bloc selected move on the layer of the polyline.

And do it on all polyline on the same layer.

Thanks

ymg

  • Guest
Re: selection of blocks
« Reply #1 on: May 10, 2014, 07:48:59 PM »
TAIKI,

Use your polyline as a fence for a selection and filter for block only.

Code: [Select]
(defun c:test (/ fence)
   (setq fence (listpol (car (entsel "\nSelectionnez le polyligne: "))))
   (sssetfirst nil (ssget "_F" fence '((0 . "INSERT"))))
)

;;; 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))
  )
)

ymg

TAIKI

  • Guest
Re: selection of blocks
« Reply #2 on: May 11, 2014, 02:10:07 AM »
Thank you

It’s a good start, just it is possible that filtered more to not take attributes on blocks but just the insertion point or all object.

And the most important do it on all polyline on the same layer, so when lisp prompt to select a polyline the code take all polyline in the same layer that the polyline you pick. To displace all blocks on all polyline on the same layers.

Thanks for your time.

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: selection of blocks
« Reply #3 on: May 11, 2014, 07:41:44 AM »
Another drive-thru lisp order.

mailmaverick

  • Bull Frog
  • Posts: 493
Re: selection of blocks
« Reply #4 on: May 11, 2014, 01:03:24 PM »
Assuming your polyline is 2D, you can use (vla-getboundingbox ....) method to find out the bounding box of the polyline.
Then you can do (ssget "_CP" (list Pt1 Pt2 Pt3 Pt4) (list (cons 0 "INSERT"))) .... of all block entities within this bounding box.
where Pt1, Pt2, Pt3 and Pt4 are the vertices of this bounding box. Note to do  (vla-zoomwindow (vlax-get-acad-object) (vlax-3d-point pt1) (vlax-3d-point pt3)) before you do above ssget because it is important that the vertices of the polygon within which you want to get entities must be zoomed in on screen. Here Pt1 and Pt3 are (minx, miny) and (maxx, maxy) coordinates of the bounding box.

Then you can iterate through all the objects to find their insertion point and check whether the point lies on the polyline or not using (vlax-curve-getDistAtPoint..... method.


ymg

  • Guest
Re: selection of blocks
« Reply #5 on: May 11, 2014, 03:06:05 PM »
TAIKI,

Assuming you assign the Selection Set to variable ss.

Now iterate through it, the insertion point will be given by:

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

ymg

TAIKI

  • Guest
Re: selection of blocks
« Reply #6 on: May 11, 2014, 03:44:49 PM »
thanks a lot

Sorry i'm starting with autolisp.

YMG your first code worked fine, but can you explain me how you create a variable ss to intergrate the code who give the insertion point for filtered.

if it take too time i would know if it possible to intergate a code like that:
Code - Auto/Visual Lisp: [Select]
  1. [/  (cond
  2.     (js
  3.       (sssetfirst nil js)
  4.       (initget "Existant Nouveau _Existent New")
  5.       (if (eq (getkword "\nTraiter jeu de sélection [Existant/Nouveau] <Existant>: ") "New")
  6.         (progn (sssetfirst nil nil) (setq js (ssadd) js (ssget)))
  7.       )
  8.     )
  9.     (T (setq js (ssget)))
  10.   )
  11. ]
  12.  

ymg

  • Guest
Re: selection of blocks
« Reply #7 on: May 11, 2014, 04:04:59 PM »

Code: [Select]
(defun c:test (/ fence)
   (setq fence (listpol (car (entsel "\nSelectionnez le polyligne: "))))
   (setq ss (ssget "_F" fence '((0 . "INSERT"))))
   (repeat (setq i (sslength ss))
       (setq pl (cons (cdr (assoc 10 (entget (ssname ss (setq i (1- i)))))) 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))
  )
)

(setq ss (ssget "_F" fence '((0 . "INSERT")))) you are assigning your selection set to variable ss

TAIKI

  • Guest
Re: selection of blocks
« Reply #8 on: May 11, 2014, 04:27:05 PM »
okay

it work fine but not easy to use. For me if your first code can do the job on many polyline at once it would be fantastique.

thank you for your help.

ymg

  • Guest
Re: selection of blocks
« Reply #9 on: May 11, 2014, 04:44:11 PM »
TAIKI,

All the ingredients are there.

Now you need to create a selection set of all the polylines.

Iterates the solution for as many polyline as you have.
Basically the same thing as when we go through the block.

Wrap your head around it, try to come up with the solution.

Post your code and If you need help, will do.

ymg

Bhull1985

  • Guest
Re: selection of blocks
« Reply #10 on: May 12, 2014, 02:21:04 PM »
Hint:
'((0 . "LINE,LWPOLYLINE"))))

TAIKI

  • Guest
Re: selection of blocks
« Reply #11 on: May 12, 2014, 04:13:25 PM »
i think i have a bug:

(
Code - C#: [Select]
  1. defun c:test (/ js 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 (eq (getkword "\nTraiter jeu de sélection [Existant/Nouveau] <Existant>: ") "New")
  11.         (progn (sssetfirst nil nil) (setq js (ssadd) js (ssget)))
  12.       )
  13.     )
  14.  (cond
  15.     (js
  16. (setq fence (listpol(car js)))
  17.          setq ss (ssget "_F" fence '((0 . "INSERT"))))
  18.   (repeat (setq i (sslength ss))
  19.       (setq pl (cons (cdr (assoc 10 (entget (ssname ss (setq i (1- i)))))) pl))
  20.    )
  21.    )     
  22. )
  23.  
  24. ;;; listpol   by Gille Chanteau                                               ;
  25. ;;; Returns the vertices list of any type of polyline (WCS coordinates)       ;
  26. ;;;                                                                           ;
  27. ;;; Argument                                                                  ;
  28. ;;; en, a polyline (ename or vla-object)                                      ;
  29.  
  30. (defun listpol (en / i p l)  
  31.   (setq i (if (vlax-curve-IsClosed en)
  32.              (vlax-curve-getEndParam en)
  33.              (+ (vlax-curve-getEndParam en) 1)
  34.           )
  35.   )          
  36.  (while (setq p (vlax-curve-getPointAtParam en (setq i (1- i))))
  37.      (setq l (cons (trans p 0 1 ) l))
  38.  )
  39. )
  40.  
  41.  
  42.  
  43.  
« Last Edit: May 16, 2014, 02:52:36 PM by TAIKI »

ymg

  • Guest
Re: selection of blocks
« Reply #12 on: May 12, 2014, 04:38:50 PM »
TAIKI,

You got more than one bug.

First and foremost subfunction listpol is expecting
an ename as argument.  You are supplying (car js).

Variable js is a selection set, you have to iterate through it,
or transform it in a list of ename.

ymg

TAIKI

  • Guest
Re: selection of blocks
« Reply #13 on: May 13, 2014, 03:16:51 PM »
it's better but idon't understand;

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

ymg

  • Guest
Re: selection of blocks
« Reply #14 on: May 13, 2014, 08:30:23 PM »
TAIKI,

I believe you have problem making the difference between a selection set and an ename.

A Selection Set is a special list of ename, you access it like so:

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 n (sslength ss))
       (setq pl (cons (cdr (assoc 10 (entget (ssname ss (setq n (1- n)))))) pl))
   )


Try to plug this in your routine.

ymg