Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Polyline offset trim and erase

12 REPLIES 12
Reply
Message 1 of 13
AutoCADnoob88
3119 Views, 12 Replies

Polyline offset trim and erase

I've been looking for a lisp program to help out at work.  I've tried to mix-and-match code to come up with a working lisp but nothing is working. I am using a polyline rectangle to start with, offsetting it out 0.75 outward, and triming everything outside of the offset and erasing the offset.  Anyone have the solution?

 

Thanks

12 REPLIES 12
Message 2 of 13
Kent1Cooper
in reply to: AutoCADnoob88


@AutoCADnoob88 wrote:

.... I am using a polyline rectangle to start with, offsetting it out 0.75 outward, and triming everything outside of the offset and erasing the offset.  Anyone have the solution?

....


As for the Trimming part, there are threads here about that -- do a Search for some words like "Trim outside" and you should find things.

 

You can Offset the Polyline rectangle easily enough by just selecting it, without needing to pick outside it to show Offset which way to go -- a routine can do that part for you.  One approach:

 

(setq PL (car (entsel "\nSelect Polyline rectangle to Offset 0.75 units outward: ")))

(command

  "_.offset" 0.75 PL "_none"

  (polar

      ; a point guaranteed to be outside if it's a rectangle [or any convex shape whose

      ; first and last segments are not collinear], regardless of which direction it was

      ; drawn [could also be done based on various other relationships]

    (vlax-curve-getStartPoint PL); base reference

    (angle (vlax-curve-getPointAtParam PL 1) (vlax-curve-getStartPoint PL)); direction 2nd vertex to 1st

    1 ; [any positive distance]

  ); polar

  "" ; finish Offset

); command

 

[It even works on Circles, on Ellipses and Splines and Arcs in some circumstances, with not-visually-predictable directional results on Lines at least 1 unit long and Rays, and maybe some other things.]

Kent Cooper, AIA
Message 3 of 13
pbejse
in reply to: AutoCADnoob88


@AutoCADnoob88 wrote:

I've been looking for a lisp program to help out at work.  I've tried to mix-and-match code to come up with a working lisp but nothing is working. I am using a polyline rectangle to start with, offsetting it out 0.75 outward, and triming everything outside of the offset and erasing the offset.  Anyone have the solution?

 

Thanks


Extrim doesnt cut for you AutoCADnoob88? [Express tools]

 

Or is that trim everything between the original rectangle and the newly offset polyline?

 

 

Message 4 of 13

That is awesome!  Both work but how would i put them into the same routine?  Offset then trim to the offset.  That would only leave getting rid of the offset lines and my work would be so much easier. 

Message 5 of 13
Lee_Mac
in reply to: AutoCADnoob88

Here's an alternative method to perform the outside offset:

 

(defun c:offout ( / e s )
    (if (setq s (ssget "_+.:E:S" '((0 . "LWPOLYLINE") (90 . 4) (-4 . "&=") (70 . 1))))
        (vl-catch-all-apply 'vla-offset
            (list (vlax-ename->vla-object (setq e (ssname s 0)))
                (if
                    (LM:listclockwise-p
                        (mapcar 'cdr
                            (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) (entget e))
                        )
                    )
                    -0.75
                     0.75
                )
            )
        )
    )
    (princ)
)

;; List Clockwise-p  -  Lee Mac
;; Returns T if the point list is clockwise oriented

(defun LM:ListClockwise-p ( lst )
    (minusp
        (apply '+
            (mapcar
                (function
                    (lambda ( a b )
                        (- (* (car b) (cadr a)) (* (car a) (cadr b)))
                    )
                )
                lst (cons (last lst) lst)
            )
        )
    )
)
(vl-load-com) (princ)
Message 6 of 13
pbejse
in reply to: AutoCADnoob88


@AutoCADnoob88 wrote:

That is awesome!  Both work but how would i put them into the same routine?  Offset then trim to the offset.  That would only leave getting rid of the offset lines and my work would be so much easier. 


That still doesnt answer my question AutoCADnoob88, are you trying to "trim" the objects between the original polyline [rectangle] and the newly created polyline?

 


is that what you meant by <<Offset then trim to the offset.>> ? getting rid of the offset lines is easy only question is what is the end result?

 

pbe

Message 7 of 13
Kent1Cooper
in reply to: pbejse


@pbejse wrote:
....

That still doesnt answer my question AutoCADnoob88, are you trying to "trim" the objects between the original polyline [rectangle] and the newly created polyline?

....


The original question seems pretty clear to me: "...triming everything outside of the offset...."

Kent Cooper, AIA
Message 8 of 13
pbejse
in reply to: Kent1Cooper


@Kent1Cooper wrote:

@pbejse wrote:
....

That still doesnt answer my question AutoCADnoob88, are you trying to "trim" the objects between the original polyline [rectangle] and the newly created polyline?

....


The original question seems pretty clear to me: "...triming everything outside of the offset...."


I see, silly me, i thought it would be more than just that. Smiley Very Happy 

 

It would ne more fun to code if it is what i thought it would be.

 

Cheers.

Message 9 of 13

Offset a polyline .75 in distance outward.  then trim everything outside of the newly created polyline that touches it and then delete the offset.  The final picture is the original polyline box with .75in lines intersecting it along the edges. 

 

thanks for all the help

Message 10 of 13
pbejse
in reply to: AutoCADnoob88

Clear as frog hair Smiley Happy

 

 

Message 11 of 13
marko_ribar
in reply to: pbejse

OP, try combining Lee's code for offset with this beutiful code by Alan J. Thompson...

 

Look here for (c:EIO)

 

http://www.cadtutor.net/forum/showthread.php?46489-Erase-objects-outside-of-boundary-%28-polyline-%2...

 

M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 12 of 13

Im still struggling putting all of this information together.  Ive got the lisp for the offset .75 out and my version supports extrim but no one has mentioned how to delete the offset once everything has been trimmed outside of it.  These lisp's are confusing.  Why cant we just type in simple english and the program understands, get rid of all this secret code.  haha

 

thanks 

Message 13 of 13
Kent1Cooper
in reply to: AutoCADnoob88


@AutoCADnoob88 wrote:

.... no one has mentioned how to delete the offset once everything has been trimmed outside of it.  ....


One way:  Immediately after the Offset-outward operation [whether my version or Lee Mac's], put a line like this:

 

(setq opl (entlast)); [= Offset PolyLine]

 

[Call the variable anything you like.]  Then at the end, this:
 

(entdel opl)

Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost