+ Reply to Thread
Results 1 to 5 of 5

Thread: Extrim Multiple

  1. #1
    Full Member benhubel's Avatar
    Computer Details
    benhubel's Computer Details
    Operating System:
    Windows 7
    Discipline
    Manufacture
    benhubel's Discipline Details
    Occupation
    Waterjet Programmer
    Discipline
    Manufacture
    Using
    AutoCAD 2012
    Join Date
    Dec 2015
    Location
    Dallas, Texas
    Posts
    82

    Default Extrim Multiple

    Registered forum members do not see this ad.

    I love Extrim, but it only does one trim at a time. I am looking to trim everything that is selected at once.

    The pseudocode goes like this:
    1. Get selection
    2. Filter out everything but closed polylines
    3. Ask user if they want to just trim crossing lines, or to delete everything 4. selected on that side of the line.
    5. Get a point as the side to extrim on. If inside any selected polyline, get the inside point of each polyline and then trim inside each one (or inside the boundary of any crossing ones). Likewise, if outside of all selected polylines, trim the outside of each one (or outside the boundary of any crossing ones).

    My main problem is that I have no clue what I'm doing when it comes to dealing with Extrim. The syntax keeps throwing me around. I thought it would be super simple when I started, but because Extrim is a LISP rather than a command, it's got me really confused.

    I was planning to make use of alanjt's SelectWithinCurve routine to help with deleting non-crossing geometry.
    I just now discovered for the first time that I am prone to memory loss.

  2. #2
    Super Member marko_ribar's Avatar
    Computer Details
    marko_ribar's Computer Details
    Operating System:
    Windows 7 Ultimate X64
    Computer:
    Intel quad core CPU 4x2.66GHz, 8GB RAM
    Motherboard:
    INTEL compatibile
    CPU:
    quad core 4x2.66GHz
    RAM:
    8GB
    Graphics:
    NVIDIA GeForce 6600 GT
    Primary Storage:
    250 GB
    Secondary Storage:
    500 GB
    Monitor:
    Samsung 17''
    Discipline
    Architectural
    marko_ribar's Discipline Details
    Occupation
    Architecture, project designer, project visualisation
    Discipline
    Architectural
    Details
    space design - modeling and animations
    Using
    AutoCAD 2014
    Join Date
    Feb 2010
    Location
    Belgrade, Serbia, Europe
    Posts
    1,233

    Marko Ribar, d.i.a. (graduated engineer of architecture)
    M.R. on YouTube

  3. #3
    Full Member benhubel's Avatar
    Computer Details
    benhubel's Computer Details
    Operating System:
    Windows 7
    Discipline
    Manufacture
    benhubel's Discipline Details
    Occupation
    Waterjet Programmer
    Discipline
    Manufacture
    Using
    AutoCAD 2012
    Join Date
    Dec 2015
    Location
    Dallas, Texas
    Posts
    82

    Default

    Thank you! I thought that I had looked through everything, but apparently not. This saves me a bunch of time.
    I'll see if I can get my extra features plugged into this.
    I just now discovered for the first time that I am prone to memory loss.

  4. #4
    Full Member benhubel's Avatar
    Computer Details
    benhubel's Computer Details
    Operating System:
    Windows 7
    Discipline
    Manufacture
    benhubel's Discipline Details
    Occupation
    Waterjet Programmer
    Discipline
    Manufacture
    Using
    AutoCAD 2012
    Join Date
    Dec 2015
    Location
    Dallas, Texas
    Posts
    82

    Default

    After looking through that code, I have modified it a bit.

    I still have to find a way to:
    1. detect all crossing cutting edges
    2. write a region around each set of intersecting edges
    3. learn how to get newly created entities so that I can actually use the new regions to cut with
    4. cleverly implement the SelectWithinCurve code to delete the objects that the hands of Trim are too short to catch

    Because I have no idea what I'm doing, I would gladly accept any help that anybody wants to give. This reply is mostly just a status update, though, for those who are curious. I think I have the necessary knowledge to trudge through this mud.

    Code:
    ;Extrim Multiple
    ;Original code posted by marko_ribar to http://www.cadtutor.net/forum/showthread.php?68144-how-trim-many-line-inside-multi-circle-on-one-step/page2&p=#19
    ;Edited by benhubel to suit his frivolous desires
    ;Please forgive the code hacks, I don't actually know what I'm doing.
    
    (defun c:et () ;normal extrim shortcut for quick access
    (c:extrim)
    ) ;end et
    
    (defun c:eti () ;shortcut to extrim on the inside of all selected and closed polylines
    (setq etside 1)
    (c:etm)
    ) ;end eti
    
    (defun c:eto () ;shortcut to extrim on the outside of all selected and closed polylines
    (setq etside 2)
    (c:etm)
    ) ;end eto
    
    (defun c:etm ( / rnd GroupByNum ptonline ptinsideent highlight 
                         ss n en ed enA minpt maxpt dx dy pt dxx dyy ) ;extrim multiple
                         
      (vl-load-com)
    
      (load "extrim.lsp")
    
      (defun rnd (/ modulus multiplier increment rand)
        (if (not seed)
          (setq seed (getvar "DATE"))
        )
        (setq modulus    65536
              multiplier 25173
              increment  13849
              seed  (rem (+ (* multiplier seed) increment) modulus)
              rand     (/ seed modulus)
        )
      )
    
      (defun GroupByNum ( l n / f )
        (defun f ( a b )
          (if (and a (< 0 b))
            (cons (car a) (f (setq l (cdr a)) (1- b)))
          )
        )
        (if l (cons (f l n) (GroupByNum l n)))
      )
    
      (defun ptonline ( pt pt1 pt2 / vec12 vec1p d result )
        (setq vec12 (mapcar '- pt2 pt1))
        (setq vec12 (reverse (cdr (reverse vec12))))
        (setq vec1p (mapcar '- pt pt1))
        (setq vec1p (reverse (cdr (reverse vec1p))))
        (setq vec2p (mapcar '- pt2 pt))
        (setq vec2p (reverse (cdr (reverse vec2p))))
        (setq d (distance '(0.0 0.0) vec12) d1 (distance '(0.0 0.0) vec1p) d2 (distance '(0.0 0.0) vec2p))
        (if (equal d (+ d1 d2) 1e-8) (setq result T) (setq result nil))
        result
      )
    
      (defun ptinsideent ( pt ent / msp ptt xlin int k kk tst result )
        (vl-load-com)
        (setq msp (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))))
        (setq ptt (vlax-curve-getclosestpointto ent pt))
        (setq xlin (vla-addxline msp (vlax-3d-point pt) (vlax-3d-point ptt)))
        (setq int (GroupByNum (vlax-invoke (if (eq (type ent) 'ENAME) (vlax-ename->vla-object ent)) 'intersectwith xlin acExtendBoth) 3))
        (setq int (vl-sort int '(lambda (a b) (< (vlax-curve-getparamatpoint xlin a) (vlax-curve-getparamatpoint xlin b)))))
        (setq k 0)
        (while (< (setq k (1+ k)) (length int))
          (if (and (eq (rem k 2) 1) (ptonline pt (nth (- k 1) int) (nth k int))) (setq tst (cons T tst)) (setq tst (cons nil tst)))
        )
        (setq tst (reverse tst))
        (setq k 0)
        (mapcar '(lambda (x) (setq k (1+ k)) (if (eq x T) (setq kk k))) tst)
        (vla-delete xlin)
        (if kk
          (if (eq (rem kk 2) 1) (setq result T) (setq result nil))
          (setq result nil)
        )
        result
      )
    
      (setq highlight (getvar "HighLight"))
      (acet-error-init (list
                         (list   "cmdecho" 0
                               "highlight" highlight
                               "regenmode" 1
                                  "osmode" 0
                                 "ucsicon" 0
                              "offsetdist" 0
                                  "attreq" 0
                                "plinewid" 0
                               "plinetype" 1
                                "gridmode" 0
                                 "celtype" "CONTINUOUS"
                               "ucsfollow" 0
                                "limcheck" 0
                         )
                         T     ;flag. True means use undo for error clean up.
                         '(if redraw_it (redraw na 4))
                        );list
      );acet-error-init
    
      (prompt "\nSelect closed entities: ")
      (if (setq ss (ssget (append (list '(-4 . "<or") '(0 . "CIRCLE") '(-4 . "<and") '(0 . "*POLYLINE") '(-4 . "<not") '(-4 . "&=") '(70 . 8) '(-4 . "not>") '(-4 . "&=") '(70 . 1) '(-4 . "and>") '(-4 . "<and") '(0 . "SPLINE") '(-4 . "&=") '(70 . 1) '(-4 . "and>") '(-4 . "<and") '(0 . "ELLIPSE") '(41 . 0.0)) (list (cons 42 (* 2 pi))) (list '(-4 . "and>") '(-4 . "or>")))))
        (progn
          (setq n (sslength ss))
          (while (>= (setq n (1- n)) 0)
            (setq en (ssname ss n) ed (entget en) enA (vlax-ename->vla-object en))
              (vla-getboundingbox enA 'minpoint 'maxpoint)
            (setq
             minpt (vlax-safearray->list minpoint)
             maxpt (vlax-safearray->list maxpoint)
            )
            (setq dx (- (car maxpt) (car minpt)))
            (setq dy (- (cadr maxpt) (cadr minpt)))
            (setq pt '(0.0 0.0 0.0)) ;I think this was originally put here to initialize pt. I don't actually see why it's needed.
    		(if(= etside nil)(setq etside (getint "\nDo you want to trim inside or outside? (1)Inside or (2)Outside: ")));Ask if this is an inside job or if we need our forces outside the curves.
    		(if(= etside 2) ;If the variable etside has been set to (2)Outside
    			(setq pt '(9999999.0 9999999.0 9999999.0));get a point in the middle of nowhere. The unlucky ******* who puts his geometry around this point will have problems. Poor guy.
    			;else  -  setting the etside int to (1)Inside is a placebo, it could've been set to 93. We probably need some error handling of some sort here
    			(while (not (ptinsideent pt en));get a point inside the polyline. marko_ribar did far better with this part than I know how to do.
    				 (setq dxx (* dx (rnd)))
    				 (setq dyy (* dy (rnd)))
    				 (setq pt (list (+ (car minpt) dxx) (+ (cadr minpt) dyy) 0.0))
    			)
    		);end if
            (etrim en pt)
          )
        )
      )
      (setq etside nil) ;reset etside to nil just to make sure an error doesn't slip through on second run. I'm not sure if it actually helps or not.
      (acet-error-restore)
      (princ)
    )
    **Edit**
    Apparently I forgot to trim down my comments. At least now I know that cadtutor doesn't appreciate the more colorful side of the English language.
    Last edited by benhubel; 4th May 2016 at 09:16 pm. Reason: Amused note
    I just now discovered for the first time that I am prone to memory loss.

  5. #5
    Luminous Being
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    9,901

    Default

    Registered forum members do not see this ad.

    Removed post read code again uses (etrim obj pt1)
    A man who never made mistakes never made anything

Similar Threads

  1. EXTRIM not trimming everything.
    By SAFeSTeR in forum AutoCAD General
    Replies: 9
    Last Post: 5th Nov 2015, 05:28 pm
  2. Extrim command very slow
    By Sandervp in forum AutoCAD Bugs, Error Messages & Quirks
    Replies: 8
    Last Post: 15th Jul 2015, 02:13 pm
  3. EXTRIM Between Two Lines
    By sidhu412 in forum AutoLISP, Visual LISP & DCL
    Replies: 22
    Last Post: 23rd Aug 2014, 07:19 pm
  4. Extrim not working in lisp
    By BIGAL in forum AutoLISP, Visual LISP & DCL
    Replies: 3
    Last Post: 28th Jan 2013, 12:53 am
  5. Extrim command
    By chizifreshi in forum AutoCAD General
    Replies: 5
    Last Post: 30th Jan 2012, 02:57 pm

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts