Author Topic: Crop LISP  (Read 8464 times)

0 Members and 1 Guest are viewing this topic.

blahdc

  • Guest
Crop LISP
« on: January 24, 2011, 03:18:52 PM »
Looking for a LISP that will crop out and delete ALL entities outside of a selected area. The tricky part would be to not delete the lines crossing over the border but to actually crop them.

Tried searching with no luck but I'm hoping someone might know of a LISP that can accomplish this task. Many thanks!

Guitar_Jones

  • Guest
Re: Crop LISP
« Reply #1 on: January 24, 2011, 03:21:29 PM »
Look up cookie cutter by Joe Burke.

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Crop LISP
« Reply #2 on: January 24, 2011, 03:24:56 PM »
Express Tools' EXTRIM.
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

kruuger

  • Swamp Rat
  • Posts: 635
Re: Crop LISP
« Reply #3 on: January 24, 2011, 03:49:58 PM »
k.

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Crop LISP
« Reply #4 on: January 24, 2011, 03:58:17 PM »
Express Tools' EXTRIM.
What I meant was Express Tools' EXTRIM and the 'EXW erase command.

Quote
Command: e ERASE
Select objects: 'exw
Specify first corner: Specify other corner:
Select objects:
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

blahdc

  • Guest
Re: Crop LISP
« Reply #5 on: January 25, 2011, 11:02:46 AM »

Express Tools' EXTRIM.

Hmm I got the trim to work but I'm not understanding on how to select everything outside of my box. Can you explain that a little more? Many thanks!

I tried cookie cutter but it is giving me errors, saying it can't cut objects.

jvillarreal

  • Bull Frog
  • Posts: 332
Re: Crop LISP
« Reply #6 on: January 25, 2011, 04:27:02 PM »
CAD Tip #5697 at cadforum offered a "wps utility" that would select inside a rectangular polygon or circle transparently which i modified to also work with curved polylines. I don't think they list an author besides xanadu.cz..Modifications were made when i was beginning to learn lisp so, as you can imagine, the added code is not that great and visual lisp free..

This modified code includes options to select inside SELI or outside SELO and both can be called transparently during a command.
Example: After initializing the erase command, type 'SELO at the selection prompt and select your closed polyline.

Note: If using either routine alone, objects will become the "previous" selection

Code: [Select]
;;Modified tip #5697 @ cadforum

(defun mass1042 (alist / x nlist);slight variation of massoc by Jaysen Long
  (foreach x alist
     (if
         (member (car x) '(10 42))
         (setq nlist (cons (cdr x) nlist))
      )
   )
  (reverse nlist)
);defun

(defun tp ( pt / )(command (trans pt 0 1)))
(defun tracecirc ( elist / cen rad p1)
   (setq cen (cdr (assoc 10 elist)) rad (cdr (assoc 40 elist)))
   (repeat 90 ; 360/4  0.06981317=4*pi/180
   (setq p1 (polar cen (* i 0.06981317) rad)  i (1+ i))
   (tp p1)))

(defun tracepline (elist / currpt nxt nxtpt p1 cen rad x2 x y2 y c s ang n cc a midp i)
 (setq elist (mass1042 elist) i -1)
 (repeat (length elist)
  (setq currpt (nth (setq i (1+ i)) elist) nxt (nth (1+ i) elist))
  (if (and (= (type currpt) 'LIST) (= (type nxt) 'REAL) (not (zerop nxt)))
   (progn (setq nxtpt (if (setq nxtpt (nth (+ i 2) elist)) nxtpt (nth 0 elist))
              y2 (cadr nxtpt)
              y (cadr currpt)
     x2 (car nxtpt)
     x  (car currpt)
     c (distance currpt nxtpt)
     s (abs (* (/ c 2) nxt))
     rad (/ (+ (expt s 2)(expt (/ c 2) 2))(* s 2))
              cc  (/ c 2.0)
     a (sqrt (- (expt rad 2.0) (expt cc 2.0)))
          midp (polar currpt (angle currpt nxtpt) cc)
              cen (polar midp (+ (angle currpt nxtpt)
                   (/ pi (cond ((> nxt 1) -2.0)
         ((< nxt -1) 2.0)
         ((>= nxt 0) 2.0)
         ((< nxt 0) -2.0)))) a)
     ang (abs (cvunit (* 4 (atan nxt)) "radian" "degree"))
              n (angle cen currpt))

 (repeat (fix ang)
  (setq p1 (polar cen n rad) n (+ n (if (< nxt 0) -0.0174532925 0.0174532925)))(tp p1))

   )
   (if (= (type currpt) 'LIST)(tp currpt))
  );if
 );repeat
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;SELECT OBJECTS COMPLETELY WITHIN A CIRCLE OR ANY POLYLINE
;(type 'seli inside an object selection prompt such as the selection prompt after erase)

(defun C:seli ( / i elist at cmde )
 (setq cmde (getvar "cmdecho"))
 (setvar "cmdecho" 0)
 (setq elist (entget (car (entsel "\nPick a circle or polyline: "))))
 (setvar "OSMODE" (boole 7 (getvar "OSMODE") 16384))
 (if (zerop (getvar "CMDACTIVE")) (command "select"))
 (command "_wp")
 (if (= (cdr(assoc 0 elist)) "CIRCLE")(tracecirc elist)(tracepline elist))
 (command "" "")
 (setvar "OSMODE" (boole 2 (getvar "OSMODE") 16384))
 (setvar "cmdecho" cmde)
 (princ)
)



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;SELECT OBJECTS COMPLETELY OUTSIDE A CIRCLE OR ANY POLYLINE
;(type 'selo inside an object selection prompt such as the selection prompt after erase)

(defun C:selo ( / pick i elist at cmde )
 (setq cmde (getvar "cmdecho"))
 (setvar "cmdecho" 0)
 (setq elist (entget (setq pick (car (entsel "\nPick a circle or polyline: ")))))
 (setvar "OSMODE" (boole 7 (getvar "OSMODE") 16384))
 (if (zerop (getvar "CMDACTIVE")) (command "_select"))
 (command "_all" "_r" pick)
 (command "_cp")
 (if (= (cdr(assoc 0 elist)) "CIRCLE")(tracecirc elist)(tracepline elist))
 (command "" "")
 (setvar "OSMODE" (boole 2 (getvar "OSMODE") 16384))
 (setvar "cmdecho" cmde)
 (princ)
)
« Last Edit: January 27, 2011, 12:01:49 PM by jvillarreal »

kruuger

  • Swamp Rat
  • Posts: 635
Re: Crop LISP
« Reply #7 on: January 25, 2011, 04:36:52 PM »

Express Tools' EXTRIM.

Hmm I got the trim to work but I'm not understanding on how to select everything outside of my box. Can you explain that a little more? Many thanks!

I tried cookie cutter but it is giving me errors, saying it can't cut objects.
did you try my attacgment cut.zip ?
kruuger

Joe Burke

  • Guest
Re: Crop LISP
« Reply #8 on: January 26, 2011, 06:55:56 AM »

Express Tools' EXTRIM.

Hmm I got the trim to work but I'm not understanding on how to select everything outside of my box. Can you explain that a little more? Many thanks!

I tried cookie cutter but it is giving me errors, saying it can't cut objects.

Please post an example file which demonstrates the problem with my CookieCutter routine. Maybe I can explain why it's not working as expected.

Thanks
« Last Edit: January 26, 2011, 07:00:40 AM by Joe Burke »

blahdc

  • Guest
Re: Crop LISP
« Reply #9 on: February 01, 2011, 01:35:15 PM »
Sorry for the long delay. I have been busy with work lately. Here is an example of what I'm trying to accomplish. The DWG attached contains 4 boxes. I want to use the red box as my cutting boundary.

Using the "cut.lsp" provided by kruuger works but doesn't cut the hatch. Other files i have also contain raster images which I would like to be able to cut (not just crop).  I loaded cookie cutter 2 but it fails:

Quote
Command: cookiecutter2
Select circle or closed polyline, ellipse or spline for trimming edge:
Pick point on side to trim:
*Invalid selection*
Expects a single object.
Erase all objects outside? [Yes/No] <N>: y
Command:
*Invalid selection*
Expects a single object.

Not sure what I'm doing wrong here...any ideas?