Jump to content

SS CPolygon


Grrr

Recommended Posts

Hi guys,

I just wrote this "imitation" of ACAD's selection, using CPolygon method:

; Grrr
; Grips a selection, if the user specifies the polygon shape, and there are objects in the enclosed area or crossing it

(defun C:test ( / ptlst pt ptx ptf SSCP cnt lwp h )

(setq go T)
(while go
	(initget 128 "Done") ; allows all inputs
	(cond
		((and (not pt) (not (or (= pt "Done")(= pt "D"))) )
			(setq pt (getpoint "\nPick first point "))
			(setq ptlst (list))
			(setq ptlst (cons pt ptlst))
			(setq ptx pt)
			(setq ptf pt)
			
		)
		((and (setq pt (getpoint "\nPick Next point or [Done], yellow line can be modified" ptx)) (= (type pt) 'LIST) )
			(setq ptlst (cons pt ptlst))
			(if (and (= (type pt) 'LIST) (= (type ptx) 'LIST))
				(progn
					(if (and (= 'ename (type lwp)) (entget lwp)) (entdel lwp))
					(if (and (= 'ename (type h)) (entget h)) (entdel h))
					(redraw)
					(grdraw (car ptlst) (last ptlst) 2 2)
					(if (> (length ptlst) 2)
						(progn
							(setq cnt 0)
							(repeat (- (length ptlst) 1)
								(grdraw (nth cnt ptlst) (nth (setq cnt (+ cnt 1)) ptlst) 1 2)
							)
							(LWPoly ptlst 1)
							(setq lwp (entlast))
							(vl-cmdf "_.HATCH" "T" 50 "CO" 1 "S" lwp "" "")
							(setq h (entlast))
							(entupd h)
							(vl-cmdf "_.DRAWORDER" h "" "B")
						)
					)
					
				)
			)
			(setq ptx pt)
		)
		((and (or (= pt "Done")(= pt "D") (null pt)) (>= (length ptlst) 2))
			(setq go nil)
			(redraw)
			(if (setq SSCP (ssget "_CP" ptlst ))
				(progn
					(if (and (= 'ename (type lwp)) (entget lwp)) (entdel lwp))
					(if (and (= 'ename (type h)) (entget h)) (entdel h))
					(sssetfirst nil SSCP)
				)
				(progn
					(if (and (= 'ename (type lwp)) (entget lwp)) (entdel lwp))
					(if (and (= 'ename (type h)) (entget h)) (entdel h))
					(setq go T)
				)
			)
		)
	)
); while	

(princ)
)


(defun LWPoly (lst cls)
(entmakex 
	(append 
		(list 
			(cons 0 "LWPOLYLINE")
			(cons 100 "AcDbEntity")
			(cons 100 "AcDbPolyline")
			(cons 90 (length lst))
			(cons 70 cls)
		)
		(mapcar (function (lambda (p) (cons 10 p))) lst)
	)
	)
)

I have no questions or anything, its just a practice work and I've decided to share it.

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