leventi Posted February 24, 2012 Share Posted February 24, 2012 Hello guys, What I need is explained in this picture: Say I have a polyline/circle/line/arc in my drawing. I want to offset it twice in the direction I select and the amount of distance I enter. So it is just like normal offset command but I need it done twice in the same direction. Another thing I need is to change the colors. Color of the selected object has to be made "Cyan", the first offset has to have a white color and the second offset has to be "Cyan" again. That's all. Here is the code I found on the internets (i think on this forum). I changed it to make just 2 offsets, it was a multiple offset code. It works great, I just need the color change code added in the mix: (defun c:test (/ s i d p v) ;;; Tharwat 14. Dec. 2011 ;;; (if (and (setq s (car (entsel "\n Select entity :"))) ;(member (cdr (assoc 0 (entget s))) '("LINE" "CIRCLE" "ARC" "ELLIPSE")) ;I had to removed this part (wasnt working with polylines) (setq i 2) (setq d (getdist "\n Distance of offset :")) (setq p (getpoint "\n Specify point on side to offset :")) (setq v d) ) (repeat i (command "_.offset" d s p "") (setq d (+ d v))) (princ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted February 24, 2012 Share Posted February 24, 2012 Check this out .... (defun c:TesT (/ s d p) (vl-load-com) ;;; Tharwat 24. Feb. 2012 ;;; (if (and (setq s (car (entsel "\n Select entity :"))) (member (cdr (assoc 0 (entget s))) '("LWPOLYLINE" "POLYLINE" "LINE" "CIRCLE" "ARC" "ELLIPSE") ) (setq d (getdist "\n Distance of offset :")) (setq p (getpoint "\n Specify point on side to offset :")) ) (progn (command "_.offset" d s p "") (command "_.chprop" (entlast) "" "color" "WHITE" "") (command "_.offset" (+ d d) s p "") (command "_.chprop" (entlast) "" "color" "CYAN" "") ) (princ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
leventi Posted February 25, 2012 Author Share Posted February 25, 2012 (edited) I need to change the color of selected entity to CYAN as well. I tried to do it with: (command "_.chprop" (s) "" "color" "CYAN" "") but doesn't work. As far as I understand, you store the "name" of the selected entity in "s". Entlast also returns the "name" of the last added entity so it should work but incompatible data types maybe? Edit: Oh nevermind, i see, i don't need the parenthesis. Works now. Thanks a lot. Edit 2: Fix'ed the missing paren at the end. (defun c:TesT (/ s d p) (vl-load-com) ;;; Tharwat 24. Feb. 2012 ;;; (if (and (setq s (car (entsel "\n Select entity :"))) (member (cdr (assoc 0 (entget s))) '("LWPOLYLINE" "POLYLINE" "LINE" "CIRCLE" "ARC" "ELLIPSE") ) (setq d (getdist "\n Distance of offset :")) (setq p (getpoint "\n Specify point on side to offset :")) ) (progn (command "_.offset" d s p "") (command "_.chprop" s "" "color" "CYAN" "") (command "_.chprop" (entlast) "" "color" "WHITE" "") (command "_.offset" (+ d d) s p "") (command "_.chprop" (entlast) "" "color" "CYAN" "") ) (princ) ) (princ) ) Edited February 25, 2012 by leventi fixed the missing paren at the end Quote Link to comment Share on other sites More sharing options...
Tharwat Posted February 25, 2012 Share Posted February 25, 2012 Edit: Oh nevermind, i see, i don't need the parenthesis. Works now. Thanks a lot. You're welcome . the routine that you modified is missing one paren at the end . Quote Link to comment Share on other sites More sharing options...
pBe Posted February 25, 2012 Share Posted February 25, 2012 (edited) Another (defun c:test ( / clr ss e d) (setq dist (cond ((getdist (strcat "\nSpecify Offset Distance" (if (numberp dist) (strcat " <" (rtos dist 2 2) ">: ") ": " )))) (dist))) (while (and dist (setq ss (ssget "_:S:E:L")) (vlax-method-applicable-p (vlax-ename->vla-object (setq e (ssname ss 0))) 'Offset) (setq clr "7" d dist pt (getpoint "\nSide to Offset"))) (repeat 2 (command "_.offset" d e pt "" "_chprop" (entlast) "" "_color" clr "") (setq clr "4" d (+ d dist)) ) [color=blue][b] (command "_chprop" e "" "_color" clr "") [/b][/color] ) (princ) ) HTH Edited February 25, 2012 by pBe Quote Link to comment Share on other sites More sharing options...
Tharwat Posted February 25, 2012 Share Posted February 25, 2012 I need to change the color of selected entity to CYAN as well. I tried to do it with: Another (defun c:test ( / clr el ss e d) (if (setq clr "7" dist (cond ((getdist (strcat "\nEnter Distance [Enter to accept: <" (rtos (setq dist (if (null dist) 1.00 (getvar 'Offsetdist))) 2 2) ">: " ) ) ) (dist) )) (while (and (setq ss (ssget "_:S:E:L")) (vlax-method-applicable-p (vlax-ename->vla-object (setq e (ssname ss 0))) 'Offset) (setq clr "7" d dist pt (getpoint "\nSide to Offset"))) (repeat 2 (command "_.offset" d e pt "" "_chprop" (entlast) "" "_color" clr "") (setq clr "4" d (+ d dist)) ) ) ) (princ) ) HTH Hi pBe . one line of code is needed Quote Link to comment Share on other sites More sharing options...
pBe Posted February 25, 2012 Share Posted February 25, 2012 i updated the post.. thats always a problem when writing a code in haste Quote Link to comment Share on other sites More sharing options...
Tharwat Posted February 25, 2012 Share Posted February 25, 2012 thats alwyas a problem when writing a code in haste Agreed . Nice way of coding by the way . Quote Link to comment Share on other sites More sharing options...
pBe Posted February 25, 2012 Share Posted February 25, 2012 Agreed . Nice way of coding by the way . Thank you tharwat I've fallen into a habit of copy & pasting snippets from other codes without checking the syntax. hence the error in coding Anyhoo... Cheers Quote Link to comment Share on other sites More sharing options...
leventi Posted February 25, 2012 Author Share Posted February 25, 2012 Another (defun c:test ( / clr ss e d) (if (setq dist (cond ((getdist (strcat "\nSpecify Offset Distance" (if (numberp dist) (strcat " <" (rtos dist 2 2) ">: ") ": " )))) (dist))) (while (and (setq ss (ssget "_:S:E:L")) (vlax-method-applicable-p (vlax-ename->vla-object (setq e (ssname ss 0))) 'Offset) (setq clr "7" d dist pt (getpoint "\nSide to Offset"))) (repeat 2 (command "_.offset" d e pt "" "_chprop" (entlast) "" "_color" clr "") (setq clr "4" d (+ d dist)) ) ) ) (princ) ) HTH Hey, thanks to you too. I like that it remembers last offset distance and continues offset command untill you hit enter but it still doesn't change color of the selected entity to CYAN. Quote Link to comment Share on other sites More sharing options...
pBe Posted February 25, 2012 Share Posted February 25, 2012 Hey, thanks to you too. I like that it remembers last offset distance and continues offset command untill you hit enter but it still doesn't change color of the selected entity to CYAN. Oh... that.. See Updated Code Quote Link to comment Share on other sites More sharing options...
leventi Posted February 27, 2012 Author Share Posted February 27, 2012 Oh... that.. See Updated Code I had to add (vl-load-com) Works now thanks. Quote Link to comment Share on other sites More sharing options...
pBe Posted February 27, 2012 Share Posted February 27, 2012 r I had to add (vl-load-com) Works now thanks. Anytime leventi. Cheers Quote Link to comment Share on other sites More sharing options...
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.