Trying to use a LWPolyline for ssget CP Mode, keep getting bad point list error

Trying to use a LWPolyline for ssget CP Mode, keep getting bad point list error

Gorra
Advocate Advocate
571 Views
7 Replies
Message 1 of 8

Trying to use a LWPolyline for ssget CP Mode, keep getting bad point list error

Gorra
Advocate
Advocate

I have an array of blocks overtop of a complicated (but not self-crossing) LWPolyline, I need to select all the blocks that are contained in or crossing the boundary. The polyline has already been selected and assigned to a global variable in an earlier step of the program. I've gotten as far as extracting the points from the polyline and putting them in a list, but no matter how I order the list, I still get a Bad Point List Argument error. For troubleshooting I have the polyline selected again in the function, seemed to help some. 

 

The function is here, largely taken from a similar forum post:

 

  (defun FilterGrid ( / KpSt DltSet ZmPt1 ZmPt2 Crdn_Lst Pnt_Lst PLEnt PLVLA CrdntNm Pnt TmpBndry)
    (setq ZmPt1 (list (car ExtrmWst) (cadr ExtrmNrth)))
    (setq ZmPt2 (list (car ExtrmEst) (cadr ExtrmSth)))
    (SelectBoundary)
    (setq PLVLA (vlax-ename->vla-object (car Bndry)))
    (setq Crdn_Lst (vlax-get PLVLA 'Coordinates))
    (setq CrdntNm 2)
    (setq Pnt_Lst (list (car Crdn_Lst) (cadr Crdn_Lst)))
    (setq Crdn_Lst (cdr Crdn_Lst))
    (setq Crdn_Lst (cdr Crdn_Lst))
    (repeat (/ (length Crdn_Lst) CrdntNm)
      (setq Pnt (list (car Crdn_Lst)(cadr Crdn_Lst)))
      (setq Crdn_Lst (cdr Crdn_Lst))
      (setq Crdn_Lst (cdr Crdn_Lst))
      (setq Pnt_Lst (cons Pnt Pnt_Lst ))
    )
    (setq Pnt_Lst (reverse Pnt_Lst))
    (command-s "zoom" "W" ZmPt1 ZmPt2)
    (setq KpSt (ssget "CP" Pnt_Lst))
    (sssetfirst KpSt)
    (command-s "chprop" "LA" "Defpoints" "")
    (if (setq DltSet (ssget _X '((0 . "INSERT") (8 . "VP-Hold"))))
      (command-s "erase")
      (princ)
    )
    (sssetfirst nil KpSt)
    (command-s "chprop" "LA" "VP-Hold")
)
 

Any help would be appreciated

 

Gorra

0 Likes
Accepted solutions (1)
572 Views
7 Replies
Replies (7)
Message 2 of 8

Gorra
Advocate
Advocate

I just went over the points with a fine tooth comb and found the first pair of numbers are reversed, and not bracketed properly. The order I can fix, but the bracket?

 

(5.43599e+06 531975.0 (531966.0 5.43593e+06) (532192.0 5.43581e+06) (532193.0 5.43584e+06) (532531.0 5.43584e+06) (532606.0 5.43584e+06) (532607.0 5.43605e+06) ...

0 Likes
Message 3 of 8

paullimapa
Mentor
Mentor
Accepted solution

assume you have this list:

(setq lst (list 5.43599e+06 531975.0 (list 531966.0 5.43593e+06)))

 AutoCAD returns with these 3 items:

(5.43599e+06 531975.0 (531966.0 5.43593e+06))

Now you want to combine the 1st and 2nd but place 2nd as 1st.

Save both those items like this:

(setq itm0 (car lst) ; save 1st item
      itm1 (cadr lst) ; save 2nd item
)

AutoCAD returns:

Command: !itm0
5.43599e+06
Command: !itm1
531975.0

Next remove the first item:

(setq lst (vl-remove (car lst) lst))

AutoCAD returns:

(531975.0 (531966.0 5.43593e+06))

Then use the following aec_replace-n function:

;;;--- aec_replace-n function 
; replaces new item at nth position in given list 
; https://www.theswamp.org/index.php?topic=41680.0
; Arguments:
; new = new value
; pos = index position
; lst = list
; Usage:
; (aec_replace-n "NewItem6" 6 '("Item0""Item1""Item2""Item3""Item4""Item5""Item6"))
; Returns:
; ("Item0" "Item1" "Item2" "Item3" "Item4" "Item5" "NewItem6")
(defun aec_replace-n (new pos lst / )
  (mapcar '(lambda (a) (if (= (setq pos (1- pos)) -1) new a)) lst)
)

To replace the item in front with what you want:

(setq lst (aec_replace-n (list itm1 itm0) 0 lst))

AutoCAD returns:

((531975.0 5.43599e+06) (531966.0 5.43593e+06))

 

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 4 of 8

Gorra
Advocate
Advocate

@paullimapa  Thanks , that idea was forming in my head but couldn't figure out the syntax for it. I've got the points pairs coming in correctly now.

0 Likes
Message 5 of 8

paullimapa
Mentor
Mentor

you are welcome...cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 6 of 8

Sea-Haven
Mentor
Mentor

Rather than using get coordinates, this makes a list for you. 

 

 

(setq plent (entsel "\nPick rectang"))
(if plent (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car plent))))))

 

For closed list just use after making co-ord.

 

(setq co-ord (cons (last co-ord) co-ord))

 

 

0 Likes
Message 7 of 8

john.uhden
Mentor
Mentor

@Gorra ,

This little widget may help you.

(defun c:Fixlist ()
  ;; Purpose: to convert first three stand-alone values into a list of its own.
  (setq a '(13 14 15 (1 2 3)(4 5 6)(7 8 9)))
  ;; So it comes out as...
  ;;     '((13 14 15)(1 2 3)(4 5 6)(7 8 9)))
  (setq c (reverse a) d c new nil)
  (foreach item c
    (if (listp item)
      (setq new (cons item new))
      (setq d (cdr d))
    )
  )
  (if (and d (< (length new) (length a)))
    (setq new (cons (reverse d) new))
    new
  )
)

John F. Uhden

0 Likes
Message 8 of 8

Sea-Haven
Mentor
Mentor

This is using get-coordinates. Can see above is much simpler.

; pline co-ords example
; By Alan H

(defun getcoords (ent)
  (vlax-safearray->list
    (vlax-variant-value
      (vlax-get-property
    (vlax-ename->vla-object ent)
    "Coordinates"
      )
    )
  )
)


 
; convert now to xyz
(defun co-ords2xy (xyz / )
(setq co-ordsxy '())
(if (= xyz 2)
(progn
(setq I 0)
(repeat (/ (length co-ords) 2)
(setq xy (list (nth i co-ords)(nth (+ I 1) co-ords) ))
(setq co-ordsxy (cons xy co-ordsxy))
(setq I (+ I 2))
)
)
)
(if (= xyz 3)
(progn
(setq I 0)
(repeat (/ (length co-ords) 3)
(setq xy (list (nth i co-ords)(nth (+ I 1) co-ords)(nth (+ I 2) co-ords) ))
(setq co-ordsxy (cons xy co-ordsxy))
(setq I (+ I 3))
)
)
)
)

(defun c:wow ( / )
(setq obj (vlax-ename->vla-object (car  (entsel "Pick obj"))))

(setq co-ords (vlax-get obj 'coordinates))
(cond 
  (( = (vla-get-objectname obj) "AcDb2dPolyline")(co-ords2xy 2))
  (( = (vla-get-objectname obj) "AcDb3dPolyline")(co-ords2xy 3))
)
(princ co-ordsxy)
0 Likes