+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 13
  1. #1
    Forum Newbie
    Using
    AutoCAD 2011
    Join Date
    Feb 2012
    Posts
    4

    Default Help with multiple offset code customisation

    Registered forum members do not see this ad.

    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:

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

  2. #2
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    5,655

    Default

    Check this out ....

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

  3. #3
    Forum Newbie
    Using
    AutoCAD 2011
    Join Date
    Feb 2012
    Posts
    4

    Default

    I need to change the color of selected entity to CYAN as well. I tried to do it with:

    Code:
    (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.

    Code:
    (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)
    )
    Last edited by leventi; 25th Feb 2012 at 09:49 am. Reason: fixed the missing paren at the end

  4. #4
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    5,655

    Default

    Quote Originally Posted by leventi View Post
    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 .

  5. #5
    Forum Deity pBe's Avatar
    Computer Details
    pBe's Computer Details
    Operating System:
    Windows 8.1
    Discipline
    Landscape
    Using
    AutoCAD 2015
    Join Date
    Apr 2010
    Posts
    2,912

    Default

    Another

    Code:
    (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))
               
                      )
            (command "_chprop" e "" "_color" clr "")
           )
    (princ)      
    )
    HTH
    Last edited by pBe; 25th Feb 2012 at 02:11 pm.

  6. #6
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    5,655

    Default

    Quote Originally Posted by leventi View Post
    I need to change the color of selected entity to CYAN as well. I tried to do it with:
    Quote Originally Posted by pBe View Post
    Another
    Code:
    (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

  7. #7
    Forum Deity pBe's Avatar
    Computer Details
    pBe's Computer Details
    Operating System:
    Windows 8.1
    Discipline
    Landscape
    Using
    AutoCAD 2015
    Join Date
    Apr 2010
    Posts
    2,912

    Default

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

  8. #8
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    5,655

    Default

    Quote Originally Posted by pBe View Post
    thats alwyas a problem when writing a code in haste
    Agreed .

    Nice way of coding by the way .

  9. #9
    Forum Deity pBe's Avatar
    Computer Details
    pBe's Computer Details
    Operating System:
    Windows 8.1
    Discipline
    Landscape
    Using
    AutoCAD 2015
    Join Date
    Apr 2010
    Posts
    2,912

    Default

    Quote Originally Posted by Tharwat View Post
    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

  10. #10
    Forum Newbie
    Using
    AutoCAD 2011
    Join Date
    Feb 2012
    Posts
    4

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by pBe View Post
    Another

    Code:
    (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.

Similar Threads

  1. Multiple Offset
    By daiharv in forum AutoCAD Drawing Management & Output
    Replies: 19
    Last Post: 10th Dec 2015, 10:54 am
  2. multiple offset
    By anishtain4 in forum AutoLISP, Visual LISP & DCL
    Replies: 43
    Last Post: 20th Feb 2012, 09:40 am
  3. offset multiple objects
    By dimekus in forum AutoCAD Drawing Management & Output
    Replies: 6
    Last Post: 2nd Jun 2011, 07:15 pm
  4. Help With Offset Code
    By WCCSAM in forum AutoLISP, Visual LISP & DCL
    Replies: 1
    Last Post: 20th Nov 2008, 03:23 pm
  5. Multiple offset?
    By James in forum AutoCAD Beginners' Area
    Replies: 2
    Last Post: 27th Nov 2006, 01:50 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts