Author Topic: ssget with WP  (Read 2913 times)

0 Members and 1 Guest are viewing this topic.

Robert98

  • Guest
ssget with WP
« on: January 31, 2014, 08:47:46 AM »
HI
I want to change color of some objects from  ByLayer  to desired color , but in ssget line occurs an error .
What is wrong in this code ?

Code - Auto/Visual Lisp: [Select]
  1. (defun C:P2  (/ mspace lst pt points n ss elem sel_OBJ)
  2.                  (vla-get-activeDocument
  3.                    (vlax-get-acad-sel_OBJect)))
  4.         points (list (getpoint "\n Select point : "))) ;setq
  5.   (while
  6.     (setq pt (getpoint "\n other point : "))
  7.      (setqlst (append (list pt) lst))
  8.      ) ;while
  9.  
  10.   (if (setq n  0
  11.             ss ((ssget "_WP" lst '((0 . "LWPOLYLINE") (8 . "7")))))
  12.     (repeat (sslength ss)
  13.       (setq sel_OBJ (vlax-ename->vla-sel_OBJect (ssname ss n)))
  14.       (vla-put-Color sel_OBJ acRed)
  15.       (setq n (1+ n))) ;repeat
  16.     )
  17.   ) ;defun
  18.  
  19.  

Thanks,
    Robert
 

ronjonp

  • Needs a day job
  • Posts: 7529
Re: ssget with WP
« Reply #1 on: January 31, 2014, 09:09:18 AM »
Me thinks it has something to do with vlax-ename->vla-sel_OBJect and vlax-get-acad-sel_OBJect and setqlst.


And too many parens on this line: ((ssget "_WP" lst '((0 . "LWPOLYLINE") (8 . "7"))))
« Last Edit: January 31, 2014, 09:13:46 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

David Bethel

  • Swamp Rat
  • Posts: 656
Re: ssget with WP
« Reply #2 on: January 31, 2014, 09:42:32 AM »
Also line 9 needs to read :

Code: [Select]
   (setq lst (append (list pt) lst)

-David
R12 Dos - A2K

ymg

  • Guest
Re: ssget with WP
« Reply #3 on: January 31, 2014, 09:51:34 AM »
Have you tried this construct for your loop:

Code - Auto/Visual Lisp: [Select]
  1. (if (setq ss (ssget "_WP" lst '((0 . "LWPOLYLINE") (8 . "7"))))
  2.    (repeat (setq i (sslength ss))
  3.        (setq sel_OBJ (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
  4.        (vla-put-Color sel_OBJ acRed)      
  5.    )
  6. )  
  7.  

You read your selection set from last entity to first.

Robert98

  • Guest
Re: ssget with WP
« Reply #4 on: January 31, 2014, 12:25:42 PM »
Hi friends
According to your suggestions I changed codes as below and it works correctly :

Code - Auto/Visual Lisp: [Select]
  1. (defun C:P4     (/ lst pt points n ss sel_OBJ)
  2.      (vl-load-com)
  3.  
  4.      (setq points (list (getpoint "\n Select point : "))) ;setq
  5.      (while
  6.        (setq pt (getpoint "\n other point : "))
  7.         (setq lst (append (list pt) lst))
  8.         ) ;while
  9.  
  10.      (if (setq ss
  11.                 (ssget "_WP" lst '((0 . "LWPOLYLINE") (8 . "7"))))
  12.        (repeat (setq i (sslength ss))
  13.          (setq sel_OBJ (vlax-ename->vla-object
  14.                          (ssname ss (setq i (1- i)))))
  15.          (vla-put-Color sel_OBJ acRed)
  16.          )
  17.        )
  18.  
  19.      ) ;defun
  20.          
  21.  

   But my aim was knowing about selection sets in Activex manner  , are there any example about ( VLAX or VLA ) for selection sets ?
   Please show me some  links .
   
 Thanks (ronjonp , David Bethel and ymg) for your very skilful notes here ,
    Robert   

ronjonp

  • Needs a day job
  • Posts: 7529
Re: ssget with WP
« Reply #5 on: January 31, 2014, 12:54:57 PM »
You might take another look at your code. Line 4 is not doing anything.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: ssget with WP
« Reply #6 on: January 31, 2014, 03:20:41 PM »
Quote
But my aim was knowing about selection sets in Activex manner
http://www.theswamp.org/index.php?topic=44255.msg495037#msg495037
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ymg

  • Guest
Re: ssget with WP
« Reply #7 on: February 01, 2014, 07:23:38 AM »
Robert98,

Here is your code reformatted a little:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:p4 (/ lst pt points n ss sel_OBJ)
  2.      (vl-load-com)
  3.  
  4.      (setq lst nil)
  5.      (while (setq pt (getpoint (if lst "\nOther point : " "\nSelect point : ")))
  6.         (setq lst (cons pt lst))
  7.      )
  8.  
  9.      (if (setq ss (ssget "_WP" lst '((0 . "LWPOLYLINE") (8 . "7"))))
  10.         (repeat (setq i (sslength ss))
  11.            (setq sel_OBJ (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
  12.            (vla-put-Color sel_OBJ acRed)
  13.         )
  14.      )
  15. )
  16.  

However the way you are inputting your selection polygon is not very satisfying.

A better way would be to either,  draw a polyline get the point list and then delete it
or use grdraw to gather your points.

Here is an example, function using the GRDRAW technique by Alan JT:

Code - Auto/Visual Lisp: [Select]
  1. (defun _getPoints (/ lst pt)
  2.     (if (car (setq lst (list (getpoint "\nSpecify first point: "))))
  3.       (progn
  4.         (while (setq pt (if (> (length lst) 1)
  5.                           (progn (initget "Undo") (getpoint (car lst) "\nSpecify next point [Undo]: "))
  6.                           (getpoint (car lst) "\nSpecify next point: ")
  7.                         )
  8.                )
  9.           (redraw)
  10.           (mapcar '(lambda (a b) (grdraw a b 1 1))
  11.                   (setq lst (if (eq pt "Undo") (cdr lst) (cons pt lst)))
  12.                   (cdr lst)
  13.           )
  14.         )
  15.         (cond ((> (length lst) 1) lst))
  16.       )
  17.     )
  18.   )
  19.  

Use it like so:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:p4 (/ lst pt points n ss sel_OBJ)
  2.      (vl-load-com)
  3.  
  4.      (setq lst (_getpoints))
  5.  
  6.      (if (setq ss (ssget "_WP" lst '((0 . "LWPOLYLINE") (8 . "7"))))
  7.         (repeat (setq i (sslength ss))
  8.            (setq sel_OBJ (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
  9.            (vla-put-Color sel_OBJ acRed)
  10.         )
  11.      )
  12. )
  13.  

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: ssget with WP
« Reply #8 on: February 01, 2014, 11:40:06 AM »
But my aim was knowing about selection sets in Activex manner  , are there any example about ( VLAX or VLA ) for selection sets ?
Please show me some  links

This tutorial may help: Selection Set Processing