Jump to content

Offset and delete source


anothercadguy

Recommended Posts

Greeting to all,

I am trying to built a lisp to offset a line. here's what I have:

(defun c:off ()    
(Command "_offset" "e" "yes" pause)
(princ) 
)

the only thing with this is that I cannot find the variable where auto stores the original setting and once I exit my custom command, auto cad keeps the "erase" source as yes.

Obviously I am not too familiar with lisp yet, so any help will be greatly appreciated.

thanks in advance.

Link to comment
Share on other sites

  • Replies 21
  • Created
  • Last Reply

Top Posters In This Topic

  • 3dwannab

    8

  • anothercadguy

    4

  • alanjt

    3

  • rkmcswain

    2

Please use code tags when posting lisp code. Also, you can disable smilies using the checkbox under "Miscellaneous Options" in each post.

 

Now to the original problem. I don't think there is a variable that controls the erase option. However, you could use this line to turn off the erase feature

 

(command "._offset" "_E" "_No" "" "_E")

Link to comment
Share on other sites

have a look at this, it's real quick and real dirty.

 

(defun c:OFF (/ offset_dist obj_2_offset offset_side)
(setvar 'cmdecho 0)
(while (= offset_dist nil)
(setq offset_dist (getdist "\nOffset distance: "))
);while

(while
(while (= obj_2_offset nil)
(setq obj_2_offset (entsel (strcat "\nPick object to offset <" (rtos offset_dist) ">: ")))
);while

(while (= offset_side nil)
(setq offset_side (getpoint "\nSide to offset on: "))
);while

(command "offset" offset_dist obj_2_offset offset_side "")

(command "erase" obj_2_offset "")
(setq obj_2_offset nil)
(setq offset_side nil)
);while

(princ))

Link to comment
Share on other sites

Thanks for the code and smiley info rkmcswain. I've tried your method but it wouldn't fly. the alanjt script works but it loops towards the end, Once you enter the distance and offset your line, the commands stays put and won't accept any other distance.

 

thanks for your reply s

Link to comment
Share on other sites

oops, i guess i added too many while

 

try this:

 

(defun c:OFF (/ offset_dist obj_2_offset offset_side)
(setvar 'cmdecho 0)
(while (= offset_dist nil)
(setq offset_dist (getdist "\nOffset distance: "))
);while

(while (= obj_2_offset nil)
(setq obj_2_offset (entsel (strcat "\nPick object to offset <" (rtos offset_dist) ">: ")))
);while

(while (= offset_side nil)
(setq offset_side (getpoint "\nSide to offset on: "))
);while

(command "offset" offset_dist obj_2_offset offset_side "")

(command "erase" obj_2_offset "")
(setq obj_2_offset nil)
(setq offset_side nil)

(princ))

Link to comment
Share on other sites

not a problem. if i get a chance this weekend, i'll actually sit down and scratch something a lot better out. i did that real quick last night w/o testing.

Link to comment
Share on other sites

  • 9 years later...
oops, i guess i added too many while

 

try this:

 

(defun c:OFF (/ offset_dist obj_2_offset offset_side)
(setvar 'cmdecho 0)
(while (= offset_dist nil)
(setq offset_dist (getdist "\nOffset distance: "))
);while

(while (= obj_2_offset nil)
(setq obj_2_offset (entsel (strcat "\nPick object to offset <" (rtos offset_dist) ">: ")))
);while

(while (= offset_side nil)
(setq offset_side (getpoint "\nSide to offset on: "))
);while

(command "offset" offset_dist obj_2_offset offset_side "")

(command "erase" obj_2_offset "")
(setq obj_2_offset nil)
(setq offset_side nil)

(princ))

 

Hi Alan,

 

I tried this with decimal places offset but reverts back to the previous offset used.

 

I tried offsetting 72.5 and it didn't work. Thanks.

Link to comment
Share on other sites

Hi Alan,

 

I tried this with decimal places offset but reverts back to the previous offset used.

 

I tried offsetting 72.5 and it didn't work. Thanks.

 

Architectural units maybe. Try entering the line

(setq offset_dist (getdist "\nOffset distance: "))

to see if it returns 72.5

Now enter the line

(setq obj_2_offset (entsel (strcat "\nPick object to offset <" (rtos offset_dist) ">: ")))

does it prompt "Pick object to offset : " ?

Link to comment
Share on other sites

The offset_dist variable is localized so it won't remember your last entry: (/ offset_dist obj_2_offset offset_side)

 

Here's a simple example that saves a default offset distance:

(defun c:off (/ e off p)
 ;; Get saved offset from registry or default to 1
 (setq	off (atof (cond	((getenv "MyOffsetProgram"))
		("1")
	  )
    )
 )
 (if (and ;; Prompt for distance, if nil use default
   (setq off (cond ((getdist (strcat "\nOffset distance <" (vl-princ-to-string off) ">: ")))
		   (off)
	     )
   )
   ;; Pick something to offset .. needs more error checking ( ie a block will bonk it )
   (setq e (entsel (strcat "\nPick object to offset: ")))
   ;; Pick a side to offset or use point in entsel
   (setq p (cond ((getpoint "\nSide to offset on: "))
		 ((cadr e))
	   )
   )
     )
   (progn ;; Offset object
   (command "_.offset" off (car e) p "")
   ;; Delete original (entdel won't **** the bed if the object is locked)
   (entdel (car e))
          ;; Write our default offset to registry
   (setenv "MyOffsetProgram" (vl-princ-to-string off))
   )
 )
 ;; SSHHHHH!!
 (princ)
)
(vl-load-com)

Edited by ronjonp
Link to comment
Share on other sites

I found the problem to my intial problem. I had done:

(defun c:ODEL nil (c:OFFSET_DELETE))
(defun c:OFFSET_DELETE ( / )

to create two command prompts forgetting about the variables.

 

Architectural units maybe. Try entering the line
(setq offset_dist (getdist "\nOffset distance: "))

to see if it returns 72.5

Now enter the line

(setq obj_2_offset (entsel (strcat "\nPick object to offset <" (rtos offset_dist) ">: ")))

does it prompt "Pick object to offset : " ?

Yes it retruns as expected.

 

The offset_dist variable is localized so it won't remember your last entry: (/ offset_dist obj_2_offset offset_side)

This brings up the question. By deleting that variable but the script won't run with the new value which is the issue I had.

 

Is there any way for it to remember the entered offset next run?

 

I tried delcaring that as a global like:

(defun c:OFFSET_DELETE ( offset_dist / offset_dist obj_2_offset offset_side )

 

But get ; error: too few arguments.

 

Thanks, guys.

Link to comment
Share on other sites

Here's a simple example that saves a default offset distance:

 

That's cool, thanks. I can sort out the filtering of the pick objects to filter blocks etc.

 

I tried to get it to work so that I could pick more entities by.

(progn ;; Offset object	   
(command "_.offset" off )
(while (/= 0 (getvar 'cmdactive))
	(command (car e) p pause)
	(entdel (car e))
	;; Pick something to offset .. needs more error checking ( ie a block will bonk it )
	(setq e (entsel (strcat "\nPick object to offset: ")))
	;; Pick a side to offset or use point in entsel
	(setq p (cond ((getpoint "\nSide to offset on: "))
		 ((cadr e))
	   )
	)
	(setenv "MyOffsetProgram" (vl-princ-to-string off))
)
)

 

But was unsuccessful.

Link to comment
Share on other sites

Got it working in a loop but just need to remove the user getting asked the offset distance each time.

 

Here's the code until I work that out :)

 

(defun c:ODEL nil (c:OFFSET_DELETE))
(defun c:OFFSET_DELETE (/ e off p)

;; Get saved offset from registry or default to 1
(setq off (atof (cond ((getenv "MyOffsetProgram"))
("1")
)
)
)

(while
(if (and ;; Prompt for distance, if nil use default
(setq off (cond ((getdist (strcat "\nOffset distance <" (vl-princ-to-string off) ">: ")))
	(off)
	)
)
	;; Pick something to offset .. needs more error checking ( ie a block will bonk it )
	(setq e (entsel (strcat "\nPick object to offset: ")))
	;; Pick a side to offset or use point in entsel
	(setq p (cond ((getpoint "\nSide to offset on: "))
		((cadr e))
		)
	)
	)
(progn ;; Offset object
	(while (command "_.offset" off (car e) p ""))
	;; Delete original (entdel won't **** the bed if the object is locked)
	(entdel (car e))
		;; Write our default offset to registry
		(setenv "MyOffsetProgram" (vl-princ-to-string off))
		)
)
)
 ;; SSHHHHH!!
 (princ)
 )
(vl-load-com)

Link to comment
Share on other sites

Wrap the Entsel in a While is not "INSERT" else do again assoc 0 is object type, or if you do a dump and look at method supported Offset is one of the methods supported. Bit like "has-attributes" checks if block has attributes. Using method means dont need to add lots of objects checking. Will try to find something.

 

Command: DUMPIT

Select object: ; IAcadLine: AutoCAD Line Interface
; Methods supported:
; ..........
;   Offset (1)

 

(setq ans "N")
(while (/= ans "Y")
(setq obj (vlax-ename->vla-object (car (entsel "\nPick object"))))
(if (= (vlax-method-applicable-p obj "Offset") T)(setq ans  "Y")(alert "Not a object that can be offset\nplease pick again"))
)

 

Almost forgot about this, some code I have use it all the time, at any time you like it skips the need to type offset just type Oxxx and it will auto ask to offset an object a distance as define by the numbers following the O, the only quirk is for decimals need - instead of a . period, eg O123 is offset 123 it also does circles and fillet.

 

Its part of a bigger code set so will cut out and test before posting.

Edited by BIGAL
Link to comment
Share on other sites

Almost forgot about this, some code I have use it all the time, at any time you like it skips the need to type offset just type Oxxx and it will auto ask to offset an object a distance as define by the numbers following the O, the only quirk is for decimals need - instead of a . period, eg O123 is offset 123 it also does circles and fillet.

 

Its part of a bigger code set so will cut out and test before posting.

That's cool.

 

I've modified that so it doesn't fail if nothing is selected.

 

(defun c:TEST1 ( / obj )
(while
	(not
		(and
			(setq obj
				(car (entsel "\nSelect Offset-able object:"))
				)
			(= (vlax-method-applicable-p (vlax-ename->vla-object obj) "Offset") T)
			(princ (vlax-method-applicable-p (vlax-ename->vla-object obj) "Offset"))
			)
		)
	(prompt "\nNothing offset-able selected")
	)
(princ)
)
(vl-load-com) (princ)

Link to comment
Share on other sites

I've only got a chance to look at this today.

Thanks guys for your help.

 

Here's the working code. Done it quicker than I expected.

 

; ################################################################

; ABOUT
; Offsets by specified distance.
; Distance remembered through different ACAD sessions.
; Original and majority of code done by user ronjonp here: http://www.cadtutor.net/forum/showthread.php?24646-Offset-and-delete-source&p=699122&viewfull=1#post699122

; MY EDITS, BY 3DWANNAB ON 24.03.18
; I've added a loop to pick more objects for offset after the first one is completed.
; and error checking to only select offset-able objects.
; It also doesn't fail if nothings selected.

; USAGE
; 'ODEL' or 'OFFSET_DELETE'.

; ################################################################

(defun c:ODEL nil (c:OFFSET_DELETE))
(defun c:OFFSET_DELETE (/ e off p)

;; Get saved offset from registry or default to 1
(setq off (atof (cond ((getenv "MyOffsetProgram"))
  ("1")
  )
)
)

(while (if (and ;; Prompt for distance, if nil use default
  (setq off (cond ((getdist (strcat "\nOffset distance <" (vl-princ-to-string off) ">: ")))
     (off)
     )
  )
 ;; Pick something to offset .. needs more error checking ( ie a block will bonk it )
 ; (setq e (entsel (strcat "\nPick object to offset: ")))

 (progn
    (while
       (not
          (and
             (setq e
                (entsel "\nSelect Offset-able object: ")
                )
             (= (vlax-method-applicable-p (vlax-ename->vla-object (car e)) "Offset") T)
    ; (princ (vlax-method-applicable-p (vlax-ename->vla-object (car e)) "Offset"))
    (setq e e)
    )
          )
       (prompt "\nNothing offset-able selected!")
       )
 ;; Pick a side to offset or use point in entsel
 (setq p (cond ((getpoint "\nSide to offset on: "))
    ((cadr e))
    )
 )
 )

 )
(progn ;; Offset object
 (while (command "_.offset" off (car e) p ""))
 ;; Delete original (entdel won't **** the bed if the object is locked)
 (entdel (car e))
  ;; Write our default offset to registry
  (setenv "MyOffsetProgram" (vl-princ-to-string off))
  )
)
)
 ;; SSHHHHH!!
 (princ)
 )
(vl-load-com)

Link to comment
Share on other sites

3dwannab,

 

I guess I don't understand the purpose for this lisp routine correct me if I'm wrong but the offset command that's in AutoCAD already remembers the offset distance until you change it and it also gives you the opportunity to erase the object selected. Am I missing something?

 

Thanks,

Brian

Link to comment
Share on other sites

It deletes the original object. I know there's an option to delete in offset but that's two extra steps. OFFSET>Erase>Yes>Amount as opposed to ODEL>Amount

 

Plus it was a challenge for me to practice my LISP writing.

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