Jump to content

Double Offset Codes Done, Works Well - But Need to Delete Original One


Recommended Posts

Posted

Hi there,

 

I had a code for double offset;  I found one code from the forums . I needed an offset for both sides on the line and the code works well. But for the next projects I need to delete the original line and just keep the new 2 side lines. I tried to write something on the code but not works well. Can you check and help me, please ?

 

(defun c:dOff ( / *error* of undo doc ss )
  (vl-load-com)

  (defun *error* ( msg )
    (and undo (vla-EndUndomark doc))
    (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
        (princ (strcat "\n** Error: " msg " **")))
    (princ)
   )

  (if (and (ssget '((0 . "ARC,CIRCLE,ELLIPSE,*LINE")))
           (setq of (getdist "\nSpecify Offset Distance: ")))
    (progn
      (setq undo
        (not
          (vla-StartUndomark
            (setq doc
              (vla-get-ActiveDocument
                (vlax-get-acad-object)
              )
            )
          )
        )
      )
      
      (vlax-for obj (setq ss (vla-get-ActiveSelectionSet doc))
        (mapcar
          (function
            (lambda ( o )
              (vl-catch-all-apply
                (function vla-offset) (list obj o)
              )
            )
          )
          (list of (- of))
        )
      )
      (vla-delete ss)

      (setq undo (vla-EndUndoMark doc))
    )
  )
  (princ)
)

 

  • 2 weeks later...
Posted
(defun c:dOff ( / *error* of undo doc ss )
  (vl-load-com)

  (defun *error* ( msg )
    (and undo (vla-EndUndomark doc))
    (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
        (princ (strcat "\n** Error: " msg " **")))
    (princ)
  )

  (if (and (setq gru (ssget '((0 . "ARC,CIRCLE,ELLIPSE,*LINE"))))
           (setq of (getdist "\nSpecify Offset Distance: ")))
    (progn
      (setq undo
        (not
          (vla-StartUndomark
            (setq doc
              (vla-get-ActiveDocument
                (vlax-get-acad-object)
              )
            )
          )
        )
      )
      
      (vlax-for obj (setq ss (vla-get-ActiveSelectionSet doc))
        (mapcar
          '(lambda ( elem )
            (vl-catch-all-apply 'vla-offset (list obj elem))
           )
          (list of (- of))
        )
      )
      (vla-delete ss)
      (vl-cmdf "_ERASE" gru "")
      (setq undo (vla-EndUndoMark doc))
    )
  )
  (princ)
)

 

I set the ssget with the variable gru: (setq gru (ssget '((0 . "ARC,CIRCLE,ELLIPSE,*LINE"))))

The gru selection is deleted: (vl-cmdf "_ERASE" gru "")

Aesthetically it's a variation that might make purists cringe and I don't blame them, not least because I try to avoid the command and vl-cmdf function, but it's the one that's much quicker to write.

 

  • Like 1
Posted

If you don't want to use "vl-cmdf" try the following.

 

    (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex gru)))
      (entdel ent)
    )

or

   (repeat (setq i (sslength gru))
     (entdel (ssname ss (setq i (1- i))))
   )

 

  • Like 2
Posted

Eh, I know, but sometimes laziness... 😚

  • Funny 1
Posted (edited)
20 minutes ago, confutatis said:

Eh, I know, but sometimes laziness... 😚

i hear you brother! id probably do the same thing.

Edited by mhupp
  • Agree 1
Posted

Old fashioned (command "erase" still works. We are talking microseconds for this task.

Posted

Thank you guys. It fits perfectly to my situation. Thanks a lot.

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