MARing Posted January 4 Posted January 4 Hi everybody, I just registered to check if there is a command or any script that you know of that can offset a squere polyline, delete the original polyline, and reconnect the neighboring lines to the new offset. (I made an example of how it should work.) Recently, I gave myself a new DIY project to make a new console stair in the house by using a CNC laser. I made them in SketchUp using a tab-and-slot system, but now, since I did it without reserving any tolerance gaps, I need to resize all the slots. There are more than 400 pieces with multiple tab & slots. Recently, I spent 3 hours with ChatGPT trying to make the script, but I don't think it understood me. The slots don't necessarily need to be parallel or perpendicular to the X axis. They can be oriented in any direction along the XY plane, including diagonally or at any other angle. Any help would be excelent. Quote
BIGAL Posted January 4 Posted January 4 On iPad at moment, if the shapes are plines may need to explode. So can get at each segment, I am not sure how we would identify a slot. The offset and trimming can be done. Post a sample dwg only need a few shapes not 400. Quote
MARing Posted January 5 Author Posted January 5 Thanks for response BIGAL, I uploaded 2 drawings and some photos to easier understand what I want. Idea wasnt that I run the script and that it automatically corrects all the slots, but rather that I select one slot by slot, even join them to pline if necessary, and running the comand which ask me to input the offset. Now I have to join the slot lines in pline, make an offset, trim the connecting lines and trim the offset lines depending if I am making inner or outer offset. Everything said nothing isnt a big deal, if there wasnt so much slots which needs to be offseted by 0,1 or 0,2mm. Untitled1.dwg Untitled3.dwg Quote
BIGAL Posted January 6 Posted January 6 I made something just pick the outer edge it must be a pline, you can then get all 4 points that make up the outstand and offset them all by an amount, thought I had it solved but then it stopped working on an edge where the start point is an edge point. In this situation have to look backwards on a points list. Hopefully will solve for you. have to go now. Image is very nice detail. Quote
BIGAL Posted January 7 Posted January 7 (edited) Please try this let me know how it goes. ; https://www.cadtutor.net/forum/topic/95729-offset-delete-original-reconect/ (defun c:wow ( / ang1 ang2 ang3 pt1 pt2 pt3 pt4 st1 st2 st3 st4) ; Checking if pline is CW or CCW and set to CCW ; Orignal idea by Kent Cooper, 1 August 2018 Offsetinorout.lsp ; By Alan H July 2020 (defun AH:chkcwccw (ent / objnew area1 area2 obj minpoint maxpoint) (setq obj (vlax-ename->vla-object (car ent))) (vla-GetBoundingBox obj 'minpoint 'maxpoint) (setq pointmin (vlax-safearray->list minpoint)) (setq pointmax (vlax-safearray->list maxpoint)) (setq dist (/ (distance pointmin pointmax) 20.0)) (vla-offset obj dist) (setq objnew (vlax-ename->vla-object (entlast))) (setq area1 (vlax-get objnew 'Area)) (vla-delete objnew) (vla-offset obj (- dist)) (setq objnew (vlax-ename->vla-object (entlast))) (setq area2 (vlax-get objnew 'Area)) (vla-delete objnew) (if (< area1 area2) (command "Pedit" ent "R" "") ) ) (defun getplineseg (ent / ename pt param) (setq ename (car ent)) (setq pt (cadr ent)) (setq pt (vlax-curve-getClosestPointTo ename pt)) (setq param (vlax-curve-getParamAtPoint ename pt)) (setq num (fix param)) (cond ((= num (- (length co-ord) 1)) (progn (setq v1 (- num 1) v2 num v3 0 v4 1 ) ) ) ((= num (- (length co-ord) 2)) (progn (setq v1 (- num 1) v2 num v3 (+ num 1) v4 0 ) ) ) ((progn (setq v1 (- num 1) v2 num v3 (+ num 1) v4 (+ num 2) ) ) ) ) (setq pt1 (nth v1 co-ord) pt2 (nth v2 co-ord) pt3 (nth v3 co-ord) pt4 (nth v4 co-ord) ) (setq ang1 (angle pt1 pt2) ang2 (angle pt2 pt3) ang3 (angle pt3 pt4) ) (princ) ) ;;---------------------=={ Subst Nth }==----------------------;; ;; ;; ;; Substitutes an item at the nth position in a list. ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;; ;;------------------------------------------------------------;; ;; Arguments: ;; ;; a - item to substitute ;; ;; n - position in list to make the substitution ;; ;; l - list in which to make the substitution ;; ;;------------------------------------------------------------;; ;; Returns: Resultant list following the substitution ;; ;;------------------------------------------------------------;; (defun LM:SubstNth ( a n l ) (if l (if (zerop n) (cons a (cdr l)) (cons (car l) (LM:SubstNth a (1- n) (cdr l))) ) ) ) (setq oldsnap (getvar 'osmode)) (setvar 'osmode 0) (setq off (getreal "\nEnter offset eg 0.1 ")) (setq co-ord nil) (while (setq plent (entsel "\nSelect bottom pline segment: ")) (AH:chkcwccw plent) (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car plent))))) (getplineseg plent) (setq obj (vlax-ename->vla-object (car plent))) (setq pt1a (polar pt1 (+ ang2 pi) off)) (setq co-ord (LM:SubstNth pt1a v1 co-ord)) (setq pt2a (polar pt2 (+ ang2 pi) off)) (setq pt2a (polar pt2a ang1 off)) (setq co-ord (LM:SubstNth pt2a v2 co-ord)) (setq pt3a (polar pt3 ang2 off)) (setq pt3a (polar pt3a ang1 off)) (setq co-ord (LM:SubstNth pt3a v3 co-ord)) (setq pt4a (polar pt4 ang2 off)) (setq co-ord (LM:SubstNth pt4a v4 co-ord)) (setq pts '()) (foreach pt co-ord (setq pts (cons (car pt) pts)) (setq pts (cons (cadr pt) pts)) ) (setq pts (reverse pts)) (vlax-put obj 'coordinates pts) (setvar 'osmode oldsnap) ) (princ) ) (c:wow) Edited January 7 by BIGAL 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.