Saqib_theleo Posted February 18, 2012 Posted February 18, 2012 Welcome to the forum Saqib_theleo, Looks like you heed my advice and posted your request where you got the orignal code. Now. what exactly do you need? What you're asking is not that difficult at all, only, there are a couple of codes (AlanjT/LM/Tharwat/.... ) posted on this thread, i suggest you try them all first and see what code is better suited for your needs (you know what they say about re-inventing the wheel) [bTW: who are these people they cal "THEY" ? is there a building out there with a room that says "THEY" on the door? ] Or maybe, you need an entirely different routine. Hi pBe, Thanks and yes I heeded your advice and posted my request in here. I tried those codes you suggested but they are not as good as this one (which is #09 post) I posted on my request. I don't need any different code this Lisp is good but the problem is, this is working with Line only not any PLine. I just want you to change this Lisp so that it could work with Line and PLine. (and I don't know about these people who call "THEY" or any building ) Thanks. Quote
pBe Posted February 19, 2012 Posted February 19, 2012 (edited) Hi pBe,I tried those codes you suggested but they are not as good as this one (which is #09 post) I posted on my request. I don't need any different code this Lisp is good but the problem is, this is working with Line only not any PLine. I just want you to change this Lisp so that it could work with Line and PLine. Thanks. Oh well, just so you know, the code posted on #9 requries a specific conditions from the original OP. and the rest of the codes posted on this thread has their own unique qualities depending on a given set of conditions. Anyhoo. i do believe your needs requires another approach. by combining the codes on this thread (defun c:ofn (/ ss i ent d) ;;; pBe Feb2012 ;;; ;;; kudos to Alanjt/LM/Wizman ;;; (vl-load-com) (if (and (setq dist (cond ((getdist (strcat "\nSpecify offset Distance" (if (numberp dist) (strcat " <" (rtos dist) ">: ") ": " )))) (dist))) (setq rep (cond ((getint (strcat "\nSpecify Number of offset" (if (numberp rep) (strcat " <" (itoa rep) ">: ") ": " )))) (rep))) (setq ss (ssget "_:L" '((0 . "ARC,CIRCLE,ELLIPSE,*LINE")))) ) (repeat (setq i (sslength ss)) (setq ent (ssname ss (setq i (1- i)))) (redraw ent 3) (setq sd (getpoint "\nPick Side to Offset:")) (redraw ent 4) (setq d dist) (repeat rep (command "._offset" d ent sd "") (setq d (+ d dist)) ) ) ) (princ) ) HTH Edited February 19, 2012 by pBe Quote
Saqib_theleo Posted February 19, 2012 Posted February 19, 2012 Oh well, just so you know, the code posted on #9 requries a specific conditions from the original OP. and the rest of the codes posted on this thread has their own unique qualities depending on a given set of conditions. Anyhoo. i do believe your needs requires another approach. by combining the codes on this thread (defun c:ofn (/ ss i ent d) ;;; pBe Feb2012 ;;; ;;; kudos to Alanjt/LM/Wizman ;;; (vl-load-com) (if (and (setq dist (cond ((getdist (strcat "\nSpecify offset Distance" (if (numberp dist) (strcat " <" (rtos dist) ">: ") ": " )))) (dist))) (setq rep (cond ((getint (strcat "\nSpecify Number of offset" (if (numberp rep) (strcat " <" (itoa rep) ">: ") ": " )))) (rep))) (setq ss (ssget "_:L" '((0 . "ARC,CIRCLE,ELLIPSE,*LINE")))) ) (repeat (setq i (sslength ss)) (setq ent (ssname ss (setq i (1- i)))) (redraw ent 3) (setq sd (getpoint "\nPick Side to Offset:")) (redraw ent 4) (setq d dist) (repeat rep (command "._offset" d ent sd "") (setq d (+ d dist)) ) ) ) (princ) ) HTH Hi pBe, Yes, now it is working as I want. I am thankful to you for your time and good help. *YTH* Thanks again. Take care. Quote
pBe Posted February 20, 2012 Posted February 20, 2012 Hi pBe,Yes, now it is working as I want. I am thankful to you for your time and good help. *YTH* Thanks again. Take care. Glad i could help Cheers Quote
AVS801 Posted January 2, 2020 Posted January 2, 2020 Hi, I have the following task: There is a closed polyline. I need to do OFFSET outside by a certain distance. At the moment my Lisp code is the following, but it doesn't work properly if the original polyline has counter clock wise orientation (offset goes inside not outside). Has anyone faced such a task? [LISP](defun c:offsetout (/) (while t (setq offset (getreal "\nInput offset distance :")) (while (not(setq ent_point (entsel "\nSelect an object or press ESC :")))) (setq ent (nth 0 ent_point)) (setq vla_obj (vlax-ename->vla-object ent)) (setq offsetObj1 (vla-Offset vla_obj (* -1 offset))) ;(setq offsetObj2 (vla-Offset vla_obj (* 1 offset))) (setq vla_obj1 (vlax-ename->vla-object (car(offsetObj1)))) ; (vlax-dump-object vla_obj1) ); end while ); end defun[/LISP][/CODE] Quote
BIGAL Posted January 4, 2020 Posted January 4, 2020 (edited) Offset, dist, pick pline, (getvar 'extmax) The extmax is always outside your pline or exactly on it so as a safety add say 10 to x value. This should fix inside outside. Use old fashioned (command . Edited January 4, 2020 by BIGAL Quote
dlanorh Posted January 4, 2020 Posted January 4, 2020 (edited) Try this. The Polyline must be a LWPolyline and the 'closed property set as true. It can be adjusted to compensate for open polylines where the start and end point are the same but not closed. To exit the loop just select a blank area of the screen when asked to select an object. (defun c:moff (/ o_dst sel obj n_obj) (setq o_dst (getreal "\nInput offset distance :")) (while (setq sel (entsel "\nSelect an Object : ")) (setq obj (vlax-ename->vla-object (car sel))) (cond ( (and (= (vlax-get-property obj 'objectname) "AcDbPolyline") (= :vlax-true (vlax-get-property obj 'closed)) );end_and (setq n_obj (car (vlax-invoke obj 'offset o_dst))) (cond ( (< (vlax-get n_obj 'area) (vlax-get obj 'area)) (vla-delete n_obj) (setq n_obj (vlax-invoke obj 'offset (* o_dst -1.0))) ) );end_cond ) ( (alert "NOT a Closed Polyline")) );end_cond );end_while );end_defun Edited January 4, 2020 by dlanorh clarity Quote
BIGAL Posted January 5, 2020 Posted January 5, 2020 Another, open pline still works, try it. A zig zag may give un predictable results, 3 sided seem fine. (defun c:moff (/ o_dst sel obj n_obj) (setq o_dst (getreal "\nInput offset distance :")) (while (setq sel (entsel "\nSelect an Object : ")) (setq pt (getvar 'extmax)) (setq pt (list (+ (car pt) 10.0)(+ (cadr pt) 10.0))) (command "offset" o_dst sel pt) ) ) (c:moff) Quote
mmichel Posted Monday at 11:22 PM Posted Monday at 11:22 PM (edited) this is not perfect but kinda works. lmk (defun c:o98 (/ e etyp dist rep original-dist iteration base-obj side dir base-point end-point dx dy slope direction result) (vl-load-com) ;; Main program logic (if (setq e (ssget "_+.:S:E" '((0 . "LWPOLYLINE,POLYLINE,LINE")))) ; Accept valid objects (progn ;; Get the offset distance (if (not dist) (setq dist 1.00)) ; Default value (setq dist (cond ((getreal (strcat "\nEnter Distance <" (rtos (abs dist) 2 4) ">: " ) )) ((abs dist)) ) ) (princ (strcat "\nOffset Distance: " (rtos dist 2 4) "\n")) (setq original-dist dist) ; Store the original distance for consistent increments ;; Get the number of iterations (setq rep (cond ((getint "\nEnter number of offsets (iterations) <10>: ")) (10) ; Default to 10 iterations ) ) (princ (strcat "\nNumber of Iterations: " (itoa rep) "\n")) ;; Process the selected entity (setq e (ssname e 0) etyp (cdr (assoc 0 (entget e)))) (princ (strcat "\nSelected Entity Type: " etyp "\n")) (setq base-obj (vlax-ename->vla-object e)) ; Convert base entity to VLA object ;; Get the side for the offset (setq side (getpoint "\nClick a point to specify the side: ")) (princ (strcat "\nClicked Point: " (rtos (car side) 2 4) ", " (rtos (cadr side) 2 4) "\n")) ;; Normalize the base and end points (setq base-point (vlax-curve-getpointatparam base-obj 0) end-point (vlax-curve-getpointatparam base-obj 1)) (if (or (< (car end-point) (car base-point)) (and (= (car end-point) (car base-point)) (< (cadr end-point) (cadr base-point)))) (setq base-point (vlax-curve-getpointatparam base-obj 1) end-point (vlax-curve-getpointatparam base-obj 0))) (princ (strcat "\nNormalized Base Point: " (rtos (car base-point) 2 4) ", " (rtos (cadr base-point) 2 4) "\n")) (princ (strcat "\nNormalized End Point: " (rtos (car end-point) 2 4) ", " (rtos (cadr end-point) 2 4) "\n")) ;; Calculate the line's slope (setq dx (- (car end-point) (car base-point)) dy (- (cadr end-point) (cadr base-point))) (setq slope (abs (/ dy (if (= dx 0) 1e-9 dx)))) ; Avoid divide by zero (princ (strcat "\nLine Slope: " (rtos slope 2 4) "\n")) ;; Determine offset direction based on orientation (if (> slope 1.0) (progn ;; Vertical orientation: compare x-values (setq dir (if (> (car side) (car base-point)) 1 -1)) ; Right if x > base-point's x, Left otherwise (setq direction (if (= dir 1) "Right" "Left")) (princ (strcat "\nVertical Orientation. Direction: " direction "\n")) ) (progn ;; Horizontal orientation: use cross-product for left/right logic (setq result (- (* dx (- (cadr side) (cadr base-point))) (* dy (- (car side) (car base-point))))) (setq dir (if (> result 0) -1 1)) ; -1 for Left, 1 for Right (setq direction (if (= dir 1) "Right" "Left")) (princ (strcat "\nHorizontal Orientation. Direction: " direction "\n")) ) ) ;; Perform iterative offsets (setq iteration 1) ; Initialize iteration counter (repeat rep (princ (strcat "\nIteration: " (itoa iteration) "\n")) (princ (strcat "\nOffset Distance for this Iteration: " (rtos (* dir original-dist iteration) 2 4) "\n")) (princ (strcat "Offsetting to the " direction "\n")) (cond ;; Handle polylines ((member etyp '("LWPOLYLINE" "POLYLINE")) (if (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-offset (list base-obj (* dir original-dist iteration))))) (progn (princ "\nOffset Applied Successfully.\n") (setq e (entlast)) ; Update for debugging ) (princ "\nOffset Failed.\n") ) ) ;; Handle lines ((eq etyp "LINE") (if (= (command "offset" (* dir original-dist iteration) e nil) nil) (princ "\nOffset Applied Successfully.\n") (princ "\nOffset Command Failed.\n") ) ) ) ;; Increment the iteration counter (setq iteration (1+ iteration)) ) (princ "\nOffsets Completed.\n") ) (princ "\nNo valid object selected.\n") ; Message if no selection ) (princ) ) Edited Tuesday at 03:01 PM by SLW210 Added Code Tags!! Quote
SLW210 Posted Tuesday at 03:02 PM Posted Tuesday at 03:02 PM Please use Code Tags! (<> in the editor toolbar) Quote
Recommended Posts
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.