Jump to content

Help with multiple offset code customisation


leventi

Recommended Posts

Hello guys,

 

What I need is explained in this picture:

 

qggW0.png

 

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)
)

Link to comment
Share on other sites

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)
)

Link to comment
Share on other sites

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 by leventi
fixed the missing paren at the end
Link to comment
Share on other sites

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 by pBe
Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

Agreed . :thumbsup:

 

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...