Jump to content
Kalsefar

Code for offset

Recommended Posts

Kalsefar

Hello Everyone,

 

please, I need a code ( lisp ) that can help me to make offset for multiple objects at the same time.

  • Like 1

Share this post


Link to post
Share on other sites
ronjonp

Your answer is most likely somewhere in this thread.

  • Thanks 1

Share this post


Link to post
Share on other sites
ronjonp
30 minutes ago, Kalsefar said:

None of it help me @ronjonp

Here's a quickie:

(defun c:foo (/ d s)
  ;; RJP » 2020-10-23
  (if (and (setq d (getdist "\nOffset distance: ")) (setq s (ssget ":L" '((0 . "~INSERT")))))
    (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
      (vl-catch-all-apply 'vlax-invoke (list (vlax-ename->vla-object e) 'offset d))
    )
  )
  (princ)
)
(vl-load-com)

 

Edited by ronjonp
  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
Kalsefar

Your code very helpful, and sorry for disturbing you but can you show me a way how I can make a Dialog box for your code so I can insert the distance in the dialog?!
if it possible and you have time

thanks a lot @ronjonp

Share this post


Link to post
Share on other sites
ronjonp
1 hour ago, Kalsefar said:

Your code very helpful, and sorry for disturbing you but can you show me a way how I can make a Dialog box for your code so I can insert the distance in the dialog?!
if it possible and you have time

thanks a lot @ronjonp

Sorry no time to make it pretty. Why can't you just enter the value in the command line ( or pick two points )? 🤔

  • Thanks 1

Share this post


Link to post
Share on other sites
Kalsefar

Sorry due to I asking much :( , But can you please edit the code to I able to add number of offsets, I tried to edit but I failed

Share this post


Link to post
Share on other sites
ronjonp
On 10/23/2020 at 4:05 PM, Kalsefar said:

Sorry due to I asking much :( , But can you please edit the code to I able to add number of offsets, I tried to edit but I failed

No worries :) ... try this. Heading out for the weekend!

(defun c:foo (/ b d f n s)
  ;; RJP » 2020-10-23
  (if (and (setq d (getdist "\nOffset distance: "))
	   ;; Edit (setq n 1) per Roy .. Thanks!
	   (or (setq n (getint "\nNumber of offsets:<1>")) (setq n 1))
	   (setq s (ssget ":L" '((0 . "~INSERT"))))
	   (setq s (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))
      )
    (progn
      (foreach e (mapcar 'vlax-ename->vla-object s)
	(setq f t)
	(setq b n)
	(while (and (> (setq b (1- b)) -1) f)
	  (if
	    (setq f (= 'list (type (setq e (vl-catch-all-apply 'vlax-invoke (list e 'offset d))))))
	     (setq e (car e))
	     (setq f nil)
	  )
	)
      )
      ;; Delete orginal offset objects
      (mapcar 'entdel s)
    )
  )
  (princ)
)
(vl-load-com)

 

Edited by ronjonp
*Fixed a couple of errors

Share this post


Link to post
Share on other sites
BIGAL

A couple of suggestions the first multiple offset input, just type each offset seperated by a comma.

 

; thanks to Lee-mac for this defun 
; www.lee-mac.com
; 44 is comma
(defun _csv->lst ( str / pos )
	(if (setq pos (vl-string-position 44 str))
		(cons (substr str 1 pos) (_csv->lst (substr str (+ pos 2))))
		(list str)
    )
)


(defun C:MULOFF ( / obj s off)
(vl-load-com)
(setq obj (entsel "\nSelectObject"))
(setq s (getpoint "\nPick Offset side"))
(setq offs (getstring "\Enter offsets seperated by a comma eg 1,2,3  "))
(setq lst (csv->lst offs))
(foreach off lst 
(command "_.offset" off obj s "")
)
(princ)
)
(c:muloff)

Re a dcl for input go to downloads here and have  a look at multi getvals.lsp, multi radio buttons.lspMulti GETVALS.lsp

; thanks to Lee-mac for this defun 
; www.lee-mac.com
; 44 is comma
(defun _csv->lst ( str / pos )
	(if (setq pos (vl-string-position 44 str))
		(cons (substr str 1 pos) (_csv->lst (substr str (+ pos 2))))
		(list str)
    )
)


(defun C:MULOFF ( / obj s off)
(vl-load-com)
(setq obj (entsel "\nSelectObject"))
(setq s (getpoint "\nPick Offset side"))
(if (not AH:getvalsm)(load "Multi Getvals.lsp"))
(setq offs (nth 0 (AH:getvalsm (list "Enter values" "Offsets seperate by , " 30 29 "1,2,3" ))))
(setq lst (csv->lst offs))
(foreach off lst 
(command "_.offset" off obj s "")
)
(princ)
)
(c:muloff)

image.png.0f6b094d48f39979b696c45ebb9beef3.png

 

image.png.88d313e85868aac20a269a683326922d.png

Edited by BIGAL

Share this post


Link to post
Share on other sites
ronjonp
3 hours ago, BIGAL said:

A couple of suggestions the first multiple offset input, just type each offset seperated by a comma.

 


(defun C:MULOFF ( / obj s off)
(vl-load-com)
(setq obj (entsel "\nSelectObject"))
(setq s (getpoint "\nPick Offset side"))
(setq offs (getstring "\Enter offsets seperated by a comma eg 1,2,3  "))
(setq lst (csv->lst offs))
(foreach off lst 
(command "_.offset" off obj s "")
)
(princ)
)
(c:muloff)

Re a dcl for input go to downloads here and have  a look at multi getvals.lsp, multi radio buttons.lspMulti GETVALS.lsp


(defun C:MULOFF ( / obj s off)
(vl-load-com)
(setq obj (entsel "\nSelectObject"))
(setq s (getpoint "\nPick Offset side"))
(if (not AH:getvalsm)(load "Multi Getvals.lsp"))
(setq offs (nth 0 (AH:getvalsm (list "Enter values" "Offsets seperate by , " 30 29 "1,2,3" ))))
(setq lst (csv->lst offs))
(foreach off lst 
(command "_.offset" off obj s "")
)
(princ)
)
(c:muloff)

image.png.0f6b094d48f39979b696c45ebb9beef3.png

 

image.png.88d313e85868aac20a269a683326922d.png

 

@BIGAL With all the pictures intact you're introducing a missing (csv->lst) function and less functionality of a simple command line input which both accepts a picked distance or number? You really should validate user input before passing them along .. have you thought about that? ..  Sorry you have many posts that seem to SPAM many good replies ( this one included ) ;/

 

FWIW less links to your AH:* functions and pictures and provide a complete solution. Most people cannot or will not assemble your puzzles.

Edited by ronjonp
  • Like 1

Share this post


Link to post
Share on other sites
Roy_043

@ronjonp Small issue:

(or (setq n (getint "\nNumber of offsets:<1>")) 1)

I think this should be:

(or (setq n (getint "\nNumber of offsets:<1>")) (setq n 1))

 

  • Thanks 1

Share this post


Link to post
Share on other sites
Kalsefar
Re a dcl for input go to downloads here and have  a look at multi getvals.lsp, multi radio buttons.lspMulti GETVALS.lsp

Please What is the shortcut for run the multi getvals.lsp ?!

Share this post


Link to post
Share on other sites
Kalsefar

Sir @ronjonp can you please change the code to delete the original item after creating the offset directly

Share this post


Link to post
Share on other sites
BIGAL

I have updated the code posted, and added the csv->lst yes that was a mistake  by me.

 

Inside the multi getval and radio buttons lisps are various examples on how to use if you look.

 

In the code posted there is 2 lines (if (not AH:getvalsm)(load "Multi Getvals.lsp")) this loads the Multi getvals.lsp code if not already loaded, it just needs to be in a support path or you can add the correct location "c:\\mydirectory\\oflisps\\Muti getvals.lsp" on your computer, note the \\ for directory names.

 

2nd line (setq offs (nth 0 (AH:getvalsm (list "Enter values" "Offsets seperated by , " 30 29 "1,2,3" )))) this is the code for the entry it is only 1 line in size, the box is set to a limit of 30 characters can be made more if required a list is returned of the string entered.

 

Here is another example  a list is returned of the values entered. 

(setq ans (AH:getvalsm (list "Enter Values" "Length      " 5 4 "100" "Width" 5 4 "50" "Depth" 5 4 "25" "Gap" 5 4 "25")))

(setq len (atof (nth 0 ans)) wid (atof (nth 1 ans)) depth (atof (nth 2 ans)) gap (atof (nth 3 ans))) ; the atof converts the string to a number

You can save the values entered for reuse  if running the request for sizes multiple times by saving to variables.

(if (= len nil)(setq len 100))
(if (= wid nil)(setq wid 50))
(if (= depth nil)(setq depth 25))
(if (= gap nil)(setq gap 25))

(setq ans (AH:getvalsm (list "Enter Values" "Length      " 5 4 (rtos len 2 0) "Width" 5 4 (rtos wid 2 0) "Depth" 5 4 (rtos depth 2 0) "Gap" 5 4 (rtos gap 2 0))))

(setq len (atof (nth 0 ans)) wid (atof (nth 1 ans)) depth (atof (nth 2 ans)) gap (atof (nth 3 ans)))

If you want you can copy the defun AH:getvalsm code into your code so its already available.

 

Click on this to download Multi getvals.lsp

 

Multi GETVALS.lsp

 

Edited by BIGAL

Share this post


Link to post
Share on other sites
ronjonp
On 10/24/2020 at 4:23 AM, Kalsefar said:

Sir @ronjonp can you please change the code to delete the original item after creating the offset directly

Updated the code HERE.

Share this post


Link to post
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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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