Jump to content

Lisp For Select Less than specified Length Lines


pvsvprasad

Recommended Posts

@ Grrr:

The undocumented ssget option ":L-I" is new to me. Do you by any chance know if ":L-" can be added to other ssget options (":L-X", ":L-CP" etc.)?

BricsCAD also supports (ssget ":L-I" ...).

Edited by Roy_043
Contrary to what I said before BC does support (ssget "_:L-I" ...) as well as (ssget "_I:L"...).
Link to comment
Share on other sites

  • Replies 36
  • Created
  • Last Reply

Top Posters In This Topic

  • Grrr

    9

  • Tharwat

    8

  • Roy_043

    6

  • marko_ribar

    5

@Roy...

 

No it can't be done, but Kent1Cooper from autodesk forum discovered this example :

 

(if (not (equal (sssetfirst nil (ssget ["_X" or "_A" or "_CP" etc.] [points/pointlist] [filter])) '(nil nil)))
 (setq ss (ssget "_:L")) ;;; - this works like "-I" Implied method and isolates only unlocked entities from previous (sssetfirst) gripped and selected entities
)

 

Then you can use "ss" variable in any way you want : for ex. (vlax-for x (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))) ... ), or

(repeat (setq i (sslength ss))
 (setq ent (ssname ss (setq i (1- i))))
 ...
)

 

HTH, (It helped me lots of times...)

M.R.

Link to comment
Share on other sites

Roy, I'm not aware of any of these.. perhaps trial and error would be the answer.

By the way for this particular case I have googled that #1 problem you mentioned, and found this thread

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/combining-ssget-selection-methods-implied-not-locked/td-p/3654290

This test also works for me, but I don't have BrisCAD to test on:

(defun C:test ( / SS )
(if (setq SS (ssget "_I" ))
	(progn
		(setq SS (ssget ":L-P" ))
		(sssetfirst nil SS)
		(vla-Regen (vla-get-ActiveDocument (vlax-get-acad-object)) acActiveViewport)
	)
)	
)

Link to comment
Share on other sites

@Marko:

Thanks for sharing. But there is an issue if all entities are on locked layers. In that case the user will be prompted to make a selection. Your suggestion can be somewhat simplified:

(if (cadr (sssetfirst nil (ssget "_X")))
 (setq ss (ssget "_:L"))
)

@Grrr:

Thank you for the additional information. I doubt if ":L-P" works as you expect it to. In BricsCAD using just ":L" works. That may also be the case in AutoCAD.

Link to comment
Share on other sites

@Roy

Nothing else comes to my mind, but this :

(alert "If prompted : Select objects: - HIT ENTER")
(if (cadr (sssetfirst nil (ssget "_X")))
 (setq ss (ssget "_:L"))
)

Link to comment
Share on other sites

@Roy, it looks crazy, but on my netbook it worked...

 

(defun ssunlocked ( / cmde ss )

 (vl-load-com)

 (setq cmde (getvar 'cmdecho))
 (setvar 'cmdecho 0)
 (vla-sendcommand (vla-get-activedocument (vlax-get-acad-object)) "_.COMMANDLINE\n")
 (if (cadr (sssetfirst nil (ssget "_X" '((0 . "CIRCLE")))))  ;;; <- use your preselection
   (vla-sendcommand (vla-get-activedocument (vlax-get-acad-object)) "(sssetfirst nil (ssget \"_P\"))\n(setq ss (ssget \"_:L\"))\n\n")
   (setq ss nil)
 )
 (setvar 'cmdecho cmde)
 ss
)

Edited by marko_ribar
Link to comment
Share on other sites

Roy, here are 2 suggestions of mine:

(defun C:test ( / SS e i )
(if (setq SS (ssget "_I"))
	(progn
		(sssetfirst nil nil)
		(repeat (setq i (sslength SS))
			(if (= 4 (logand 4 (cdr (assoc 70 (tblsearch "LAYER" (cdr (assoc 8 (entget (setq e (ssname SS (setq i (1- i))))))))))))
				(ssdel e SS)
			)
		)
	); progn
	(setq SS (ssget "_:L"))
); if
(if SS (sssetfirst nil SS))
(princ)
); defun

(defun c:test ( / acDoc acSS SS )
(setq acDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
(if (setq SS (ssget))
	(progn
		(vlax-map-collection (setq acSS (vla-get-ActiveSelectionSet acDoc))
			(function
				(lambda (x)
					(if (= (vla-get-Lock (vla-item (vla-get-Layers acDoc) (vlax-get x 'Layer))) :vlax-true)
						(ssdel (vlax-vla-object->ename x) SS) ; <- I wanted to go completely with Visual here (using vla-RemoveItems)
					)
				); lambda
			)
		); vlax-map-collection
		(vla-delete acSS)
		(sssetfirst nil SS)
		(vla-Regen acDoc acActiveViewport)
	); progn
); if acSS
(princ)
);| defun |; (vl-load-com) (princ)

But I think this iteration approach may be obvious for you, so maybe use code like this as a subfunction?

Link to comment
Share on other sites

Grrr, thanks for an input, but IMHO I think you're missing the point of the problem... The task should be formulated as this : find the simplest way to make standard selection filters work in combination with option to filter entities from unlocked layers... The point is that you may use it in coding situations in any lisp where certain preselection filter was used and you wish to accomplish filtering that filter by making selection set of entities belonging to unlocked layers... So examples like iteration through selection set are not the solution (it takes lots of coding and beside that it's not practical as you may have very large number of entities you need to process through iteration...)

Link to comment
Share on other sites

Hi marko,

Yes I don't think this is the best solution which I suggested (just wanted to throw it as an option),

however apart of the amount of coding I was wondering how (ssget ":L") mode actually works - is it some type of reactor that excludes entities not matching the criteria? otherwise it has to be iteration.

What if someone creates a reactor like this ? - only for prompting the SS

Link to comment
Share on other sites

Give this a shot;

(defun c:Test ( / len sad sel )
 ;; Tharwat - 24.09.16 ;;
 (if (and (setq len (getdist "\nSpecify Minimum length :"))
          (princ "\nSelect Lines & Polylines :")
          (setq sad (ssadd) sel (ssget "_:L" '((0 . "LINE,*POLYLINE"))))
          )
   ((lambda (x / e )
      (while (setq e (ssname sel (setq x (1+ x))))
        (if (< (vlax-curve-getdistatparam e (vlax-curve-getendparam e)) len)
          (ssadd e sad))
        )
      ) -1
        )
   )
 (sssetfirst nil sad)
 (princ)
 ) (vl-load-com)

 

Nice code, however, i't would work even better if there was an positive or nagative option (select longer than given lengt or shorter than given length).

 

I'm not so good in Lisp, but trying some minus or plus sign in the equation doesn't seem to do it (not at the positions i place it anyway :P).

Link to comment
Share on other sites

Nice code, however, i't would work even better if there was an positive or nagative option (select longer than given lengt or shorter than given length).

 

I'm not so good in Lisp, but trying some minus or plus sign in the equation doesn't seem to do it (not at the positions i place it anyway :P).

 

Haha it is not that sign but this sign :D

Give this a kick.

(defun c:Test ( / len sad sel kwd sgn)
 ;; Tharwat - 24.09.16 ;;
 (if (and (setq len (getdist "\nSpecify length :"))
          (princ "\nSelect Lines & Polylines :")
          (setq sad (ssadd) sel (ssget "_:L" '((0 . "LINE,*POLYLINE"))))
          (not (initget 7 "Longer Shoter"))
          (setq kwd (getkword "\nSpecify [Longer/Shorter] :"))
          (setq sgn (if (= kwd "Shoter") < >))
          )
   ((lambda (x / e )
      (while (setq e (ssname sel (setq x (1+ x))))
        (if (sgn  (vlax-curve-getdistatparam e (vlax-curve-getendparam e)) len)
          (ssadd e sad))
        )
      ) -1
        )
   )
 (sssetfirst nil sad)
 (princ)
 ) (vl-load-com)

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...