Jump to content

using ssget with Selection Mode Strings failed


aridzv

Recommended Posts

Hi.

I'm trying to use ssget with Selection Mode String and it fail.

this is what I'm using:

(ssget "_CP" '((0 . "*POLYLINE")))

and this is the error massage from the command line:

: (ssget "_CP" '((0 . "*POLYLINE")))
nil

 

I've done a google search and in appears that I need to also pass a list of points.

now - how do I generate that list?....

 

I have this lisp that applies the "JOIN" command for all the poliylines in the drawing:

(defun C:Join_Polylines ( / sel1 n cmdech)

(setq  cmdech (getvar 'cmdecho))
(setvar 'CMDECHO 1)
(setq pa (getvar "peditaccept"))
(setvar "peditaccept" 1)
(princ)

(setq ss (ssget  '((0 . "*POLYLINE"))))
(command "pedit" "m" ss ""  "j" "0.01" "")

(setvar "peditaccept" pa)

(setvar 'cmdecho cmdech)
(princ)
)

 

but I need to use it for a selection made by crossing window.

 

what I'm trying to do over all is to select all the polylines inside a crossing polygon and join them.

that's the sequence I'm trying to produce in my lisp if I was using command line:

Command: PE

Select polyline to edit [Multiple]:M

Select entities:CP

Select entities: ENTER

Select entities:ENTER

Edit polyline [Close/Open/Decurve/Fit/Join/Linetype mode/Reverse direction/Spline/Width/Undo] <eXit>:J

Enter fuzz distance or [Jointype]: 0.01

Edit polyline [Close/Open/Decurve/Fit/Join/Linetype mode/Reverse direction/Spline/Width/Undo] <eXit>:ENTER

 

aridzv.

Edited by aridzv
Link to comment
Share on other sites

1 hour ago, aridzv said:

I've done a google search and in appears that I need to also pass a list of points.

now - how do I generate that list?....

 

if you feed this with an ename of a polyline it will make co-ord a list of all the vertexes.

(setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget ent))))

 

This will work if your polyline is only straight segments. if their are arc things could be omitted from the selection. because the cords only have the start and finish points of an arc.

https://www.cadtutor.net/forum/topic/73104-polyline-coordinates/?do=findComment&comment=581425

 

This should get you what you need. just pull the selectinside function from here. (updated for better points)

https://www.theswamp.org/index.php?PHPSESSID=48p02olnkruljfv4l7fupksnk5&topic=57795.msg611267#msg611267

 

(defun C:PJ (/ ent ss)
  (setvar 'cmdecho 0)
  (if (setq poly (car (entsel "\nSelect Outside Polyline To Join Inside Object's ")))
    (progn
      (SELECTINSIDE poly)
      (vl-cmdf "_.Join" SS2 "")
    )
  )
  (setvar 'cmdecho 1)
  (princ)
)

 

 

  • Thanks 1
Link to comment
Share on other sites

Hi @mhupp and thanks for the reply!

I combined the tow lisps like you wrote and it is working.

I've also manage to get the border polyline erased (see  (entdel poly) at the bottom the C:PJ defun).

what I'm still struggling with is to make drawing of the border polyline a part of the lisp and not having to draw it separately.

I've tried to use vl-cmdf but it is not working - you can see it stroke out as comments at the top of the code.

here is the revised code - I'll be glad for some more guidance:

(defun C:PJ (/ ent ss)
  (setvar 'cmdecho 0)
  ;;(vl-cmdf "_.pline" " ")
 ;;(setq poly ((vl-cmdf "_.pline" " ")))
  ;;(setq poly (entlast))
  (if (setq poly (car (entsel "\nSelect Outside Polyline To Join Inside Object's ")))
    (progn
      (SELECTINSIDE poly)
      (vl-cmdf "_.Join" SS2 "")
    )
  )
  (setvar 'cmdecho 1)
  (entdel poly) 
  (princ)
)

(defun SELECTINSIDE (ent / poly obj seg lst len) 
  (setq poly (vlax-invoke (vlax-ename->vla-object ent) 'explode)) ;this creates an exploded copy of the polyline
  (foreach obj poly ;steps though each segment of the exploded polyline to create the points list
    (cond
      ((eq (vla-get-Objectname obj) "AcDbArc")
        (setq seg (/ (vla-get-arclength obj) 5)) 
        (setq lst (cons (vlax-curve-getPointAtDist obj 0) lst))
        (setq len seg)
        (repeat 4
          (setq lst (cons (vlax-curve-getPointAtDist obj len) lst))
          (setq len (+ len seg))
        )
        (vla-delete obj)
      )
      ((eq (vla-get-Objectname obj) "AcDbLine")
        (setq lst (cons (vlax-get obj 'StartPoint) lst))
        (vla-delete obj)
      )
    )
  )
  (setq SS1 (ssget "_WP" lst))
  (setq SS2 (ssget "_CP" lst))
)

 

 

thanks,

aridzv.

Link to comment
Share on other sites

1 hour ago, aridzv said:

what I'm still struggling with is to make drawing of the border polyline a part of the lisp and not having to draw it separately.

 

Your close try this.

 

--edit

it doesn't prompt but you can just hit c to close the polyline or if you leave it open it will act like a closed polyline and connect to the first vertices when you feed it to ssget.

 

(defun C:PJ (/ poly coord ss)
  (prompt "Draw polyline: ") ;letting you/others to know what to do. 
  (vl-cmdf "_.pline") ;starts command
  (while (> (getvar 'cmdactive) 0) (command pause)) ;pauses lisp until your done drawing the perimeter
  (if (and (setq poly (entlast)) (eq (cdr (assoc 0 (entget poly))) "LWPOLYLINE")) ;checks to see if entlast is also a polyline.
  ;(if (setq poly (car (entsel "\nSelect Outside Polyline To Join Inside Object's ")))
    (progn
      (setq coord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget poly)))) ;if your just using drawing straight lines this will be faster
      (setq SS (ssget "_CP" coord))
      (vl-cmdf "_.Join" SS "")
    )
  )
  (entdel poly) 
  (princ)
)

 

Edited by mhupp
  • Like 1
Link to comment
Share on other sites

@mhupp

Thanks - works perfectly!

 

1. first,I cannot overstate the importance of the code clarifications at the end of each line - thanks for that!

2. Since I can't guarantee that only straight lines will be involved, I decided to stick with the original function (SELECTINSIDE) rather than the simpler one you used in second example.

3. the missing link (sort of speaking...) for me was this line:

(while (> (getvar 'cmdactive) 0) (command pause)) ;pauses lisp until your done drawing the perimeter

4. And this line is also of great importance:

(if (and (setq poly (entlast)) (eq (cdr (assoc 0 (entget poly))) "LWPOLYLINE")) ;checks to see if entlast is also a polyline.

5. here is the final lisp I'm going to use:

(defun C:PJ (/ poly coord ss)
  (prompt "Draw polyline: ") ;letting you/others to know what to do. 
  (vl-cmdf "_.pline") ;starts command
  (while (> (getvar 'cmdactive) 0) (command pause)) ;pauses lisp until your done drawing the perimeter
  (if (and (setq poly (entlast)) (eq (cdr (assoc 0 (entget poly))) "LWPOLYLINE")) ;checks to see if entlast is also a polyline.
  ;(if (setq poly (car (entsel "\nSelect Outside Polyline To Join Inside Object's ")))
    (progn
      (SELECTINSIDE poly)
      (vl-cmdf "_.Join" SS2 "")
    )
  )
  (entdel poly) 
  (princ)
)

(defun SELECTINSIDE (ent / poly obj seg lst len) 
  (setq poly (vlax-invoke (vlax-ename->vla-object ent) 'explode)) ;this creates an exploded copy of the polyline
  (foreach obj poly ;steps though each segment of the exploded polyline to create the points list
    (cond
      ((eq (vla-get-Objectname obj) "AcDbArc")
        (setq seg (/ (vla-get-arclength obj) 5)) 
        (setq lst (cons (vlax-curve-getPointAtDist obj 0) lst))
        (setq len seg)
        (repeat 4
          (setq lst (cons (vlax-curve-getPointAtDist obj len) lst))
          (setq len (+ len seg))
        )
        (vla-delete obj)
      )
      ((eq (vla-get-Objectname obj) "AcDbLine")
        (setq lst (cons (vlax-get obj 'StartPoint) lst))
        (vla-delete obj)
      )
    )
  )
  (setq SS1 (ssget "_WP" lst))
  (setq SS2 (ssget "_CP" lst))
)

 

MANY THANKS,

aridzv.

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...