Nikon Posted June 25 Posted June 25 (edited) Good day to all I need to execute the Offset command (for a specified distance of 10 mm), specify the point defining the offset side and change the layer of the offset element to a layer named "Off", line thickness 30, color 126. But the code doesn't work... How can the offset direction be specified in the code? (defun c:Off10ChangeLay (/ point offset-vec obj new-layer offset-obj entdata) (princ "Select an object to offset: ") (setq obj (car (entsel))) (if obj (progn (princ "Specify the point that defines the side of the offset: ") (setq point (getpoint " ")) ;; Set a fixed offset, 10 (setq offset-distance 10) ;; determining the direction of Offset ??? ??? (command "_.Offset" offset-vec obj "") (setq offset-obj (entlast)) (if offset-obj (progn ;; Create an "Off" layer if there is none. (if (not (tblsearch "layer" "Off")) (command "_layer" "_n" "Off" "")) (entmod (subst (cons 8 "Off") (assoc 8 (entget offset-obj)) (entget offset-obj))) ;; Getting the current properties of the object (setq entdata (entget offset-obj)) ;; Setting the line width to 30 (if (assoc 70 entdata) (setq entdata (subst (cons 70 30) (assoc 70 entdata) entdata)) (setq entdata (append entdata (list (cons 70 30))))) ;; Setting the color to 126 (if (assoc 62 entdata) (setq entdata (subst (cons 62 126) (assoc 62 entdata) entdata)) (setq entdata (append entdata (list (cons 62 126))))) (entmod entdata) (princ) ) Edited June 25 by Nikon Quote
GLAVCVS Posted June 25 Posted June 25 (edited) Hi Nikon The side to offset can be defined by the angle between the first and second points of the segment (+1/2π for the left side or -1/2π for the right side). Therefore, you can obtain the offset point by doing the following: (polar p1 (+/- (angle p1 p2)) (/ PI 2.0)) 1) Edited June 25 by GLAVCVS 1 Quote
GLAVCVS Posted June 25 Posted June 25 I see that your code doesn't identify the segment selected on the screen. Therefore, I think you should do that little bit of work first (using vlax-curve functions) 1 Quote
BIGAL Posted Thursday at 12:40 AM Posted Thursday at 12:40 AM You can also use the line direction left will be -ve right is positive. The way to use this is to pick near an end that implies the direction then do offset point. Here is an example of working out direction. Swaps start & end if required. Then as suggested use the angle of start - end + pi/2. (setq ent (entsel "\nPIck object near end ")) (setq pt (cadr ent)) (setq obj2 (vlax-ename->vla-object (car ent))) (setq start (vlax-curve-getstartPoint obj2)) (setq end (vlax-curve-getendPoint obj2)) (setq d1 (distance pt start)) (setq d2 (distance pt end)) (if (> d1 d2) (setq tmp start start end end tmp ) 1 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.