Jump to content

Help with multiple offset code customisation


Recommended Posts

Posted

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

Posted

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

Posted (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 by leventi
fixed the missing paren at the end
Posted

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 .

Posted (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 by pBe
Posted
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 :)

Posted

i updated the post.. thats always a problem when writing a code in haste :lol:

Posted
thats alwyas a problem when writing a code in haste :lol:

 

Agreed . :thumbsup:

 

Nice way of coding by the way .

Posted
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

Posted
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.

Posted
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

Posted
Oh... that.. :)

 

See Updated Code

I had to add

(vl-load-com)

Works now thanks.

Posted

r

I had to add

(vl-load-com)

Works now thanks.

 

Anytime leventi.

 

Cheers

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