Offset multiple objects at once

Offset multiple objects at once

JoeKidd33
Advocate Advocate
29,749 Views
40 Replies
Message 1 of 41

Offset multiple objects at once

JoeKidd33
Advocate
Advocate

We have a process in our drawings where we need need to offset closed polygons to the interior of the polygon at a set distance. Can anyone think of a routine or way to automate this? We will sometimes have hundreds of these polygons that need to be offset. I was thinking if there was a way to have an interior coordinate calculated from the object and store that as a variable, it could be part of a lsp routine to take the selected object and use the interior coordinate as the point for side to offset.

0 Likes
29,750 Views
40 Replies
Replies (40)
Message 21 of 41

Anonymous
Not applicable

So I just found this and it is very handy for what we do. But instead of using source layer can it use current layer?

 

Thanks, 

Seth 

0 Likes
Message 22 of 41

john.uhden
Mentor
Mentor

Where is "this?"

John F. Uhden

0 Likes
Message 23 of 41

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... But instead of using source layer can it use current layer? ....


 

Unfortunately, the (vla-offset) approach doesn't honor the Layer option in the Offset command, that can put the results on the current Layer.  But the Layer change could be built into the code.  Are you talking about the version that keeps, or the version that erases, the original objects?

Kent Cooper, AIA
0 Likes
Message 24 of 41

Anonymous
Not applicable

I am talking about the version that keeps the original objects.

it is from this ( https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/offset-multiple-objects-at-once/m-p/... )

 

 How could you write it to select all the new offset lines and change clayer? Also at what point would that have to be inserted into the code?

0 Likes
Message 25 of 41

ronjonp
Mentor
Mentor

Try this quick mod:

(defun c:offf (/ _off a b c d i o p s x)
  ;; RJP » 2018-11-28
  (defun _off (o d / r)
    (cond ((= 'list (type (setq r (vl-catch-all-apply 'vlax-invoke (list o 'offset d))))) (car r)))
  )
  (or (setq p (getenv "RJP_Offset_Side")) (setq p "Inside"))
  (or (setq i (getenv "RJP_Offset_Dist")) (setq i "1"))
  (or (setq b (getenv "RJP_Offset_Delete")) (setq b "No"))
  (or (setq c (getenv "RJP_Offset_Clayer")) (setq c "No"))
  (cond
    ((and (progn (initget "Outside Inside")
		 (setq p (cond ((getkword (strcat "\nOffset [Outside/Inside] <" p ">: ")))
			       (p)
			 )
		 )
	  )
	  (setq	i (cond	((getdist (strcat "\nEnter Offset Distance: <" i ">: ")))
			((atof i))
		  )
	  )
	  (progn (initget "Yes No")
		 (setq b (cond ((getkword (strcat "\nDelete original? [Yes/No] <" b ">: ")))
			       (b)
			 )
		 )
	  )
	  (progn (initget "Yes No")
		 (setq
		   c (cond ((getkword (strcat "\nOffset object to current layer? [Yes/No] <" c ">: ")))
			   (c)
		     )
		 )
	  )
	  (setq s (ssget ":L" '((0 . "*POLYLINE,ARC,CIRCLE,ELLIPSE,SPLINE"))))
     )
     (setenv "RJP_Offset_Dist" (vl-princ-to-string i))
     (setenv "RJP_Offset_Side" p)
     (setenv "RJP_Offset_Delete" b)
     (setenv "RJP_Offset_Clayer" c)
     (foreach e	(vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
       (setq o (vlax-ename->vla-object e))
       (cond ((= 2
		 (length (setq a
				(vl-remove
				  'nil
				  (mapcar
				    '(lambda (x) (cond ((setq d (_off o (x i))) (list d (vlax-curve-getarea d)))))
				    (list + -)
				  )
				)
			 )
		 )
	      )
	      (setq a (mapcar 'car (vl-sort a '(lambda (r j) (< (cadr r) (cadr j))))))
	      (and (= p "Outside") (setq a (reverse a)))
	      (vla-delete (cadr a))
	      (and (= "Yes" b) (entdel e))
	      (and (= "Yes" c) (vla-put-layer (car a) (getvar 'clayer)))
	     )
	     (t (vla-put-color o 1) (print "Something went wrong.."))
       )
     )
    )
  )
  (princ)
)
(vl-load-com)
Message 26 of 41

Anonymous
Not applicable

That works awesome thanks for all your help and time! 

 

0 Likes
Message 27 of 41

ronjonp
Mentor
Mentor

Glad to help! 🙂

0 Likes
Message 28 of 41

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

So I just found this and it is very handy for what we do. But instead of using source layer can it use current layer?

....


 

Since that [Message 21] was in Reply to me, and later you confirmed you want to keep the original object(s), I assume it's about the code in Message 9.  Attached is a [lightly tested] revision to put the results on the Current Layer [the -CL at the end of the file name].  It could be done as an option  whether to put the results on the current or source Layer [as in regular OFFSET], but this was a quicker modification.

Kent Cooper, AIA
Message 29 of 41

Anonymous
Not applicable

Alright so i just got done testing them and they are both phenomenal. Rperez, your lisp offf in message (25) has helpful options it gives you if that is what you are working with: offset inside or outside,  enter dist,  do you want to delete the original, and do you want to offset to current layer. Definitely a handy thing to have. Also one thing to consider using this one it that if you have objects too small for the offset inside it will become a little bit of a mess due to it still offsetting it to the outside. Kent1Cooper, your lisp runs a lot faster. With the 2 different commands offin or offout you don't have as many options which makes for using the command quicker. If you don't need the options and aren't working with 10,000 or more objects use the offin or offout. The offin or offout does happen to process the information 67% slower but the lack of all the pop up options makes up for that. 

For what I am doing I will end up using offin or offout . 

 

To everyone who will read this and use these, ask these guys questions if you have any. They are so helpful and have spent time to help me out on numerous projects and questions that I have had.

Thanks again for all the assistance you have given me, I am sure there will be more in the future! 

 

 

0 Likes
Message 30 of 41

Anonymous
Not applicable

is there a way to have the offset on a certain layer as well? I used your offset in and out and work great! just wondering if you are able to add the layer to offset on..

 

Your help if greatly appreciated.

0 Likes
Message 31 of 41

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

is there a way to have the offset on a certain layer as well? ....


Attached is OffsetInOrOut-USL.lsp, with the USL standing for "User-Specified Layer."  Read the comments at the top of the file.  It uses the same command names  as the earlier versions, so if you want to have those also available, you should change some command names.  But since this includes options  for the Current Layer or the Source-object's Layer, it covers the functionalities of the others.  Its only drawback, relatively speaking, is that you need to answer the prompt about the Layer, which you don't in the earlier routines that only use the Source or Current Layer.

 

One possible enhancement that could be added: if you type in a Layer name that doesn't exist, to have it ask whether to create it.

Kent Cooper, AIA
Message 32 of 41

Matheus-Lima
Advisor
Advisor

Wow this thread just helped me A LOT right now, thank you, everybody! Specially @Kent1Cooper for the LISP file!

[PT-BR] Se essa postagem foi útil para você, clique em Curtir! Se a resposta resolveu o seu problema, clique em Aceitar Solução.
[EN-US] If it was helpful to you, click on Like! If the answer solved your problem, click on Accept Solution.

EESignature


Matheus Lima
Civil Engineer | BIM for Infrastructure Enthusiast | BIM Manager | Instagram @bim_infra | LinkedIn
Message 33 of 41

masafumi.horiuchi.sd
Contributor
Contributor

JoeKidd33,

 

I have found your AutoLisp code "OffsetInOrOut.lsp" and it is very useful to do a routine of offsetting a large amount of objects. It would be greatly appreciated if you could teach me how to revise it a little. I am using Autocadlt 2024.

 

Quote: [It doesn't have regular Offset's options about the Layer of the result, nor to delete the original, but those could be added.]

 
I would be grateful if you could teach me how to change the AutoLisp code to be able to select "delete the original" or  "not to delete the original".
 
0 Likes
Message 34 of 41

Kent1Cooper
Consultant
Consultant

@masafumi.horiuchi.sd wrote:

... to change the AutoLisp code to be able to select "delete the original" or  "not to delete the original".


The simplest thing would be to see Messages 16 & 17 here, and make a separate command that incorporates that deletion.  But if two commands would be too much, it could be incorporated into a single command as an option.

Kent Cooper, AIA
Message 35 of 41

masafumi.horiuchi.sd
Contributor
Contributor

 Thank you so much for your reply.

 I read the 17th message and knew how to change the lisp code to be able to delete the objests after offsetting.

 Thank you very much for your information.

0 Likes
Message 36 of 41

sadishpaul
Participant
Participant

Hi, the newly created offset objects are in same color that of the original object 

 

but i want the newly created objects to be in the color set in the color control

 

regards,

paul

0 Likes
Message 37 of 41

Kent1Cooper
Consultant
Consultant

@sadishpaul wrote:

Hi, the newly created offset objects are in same color that of the original object 

but i want the newly created objects to be in the color set in the color control


Explain what you mean by "the color control."  Do you want the User to be prompted with a color chart to select a color for them?  Or do you want them to be BYLAYER in color [the "color control" being that of the Layer], removing any object override?  Or do you want them to be whatever the current object color setting is [CECOLOR System Variable]?  Or something else?

 

And in which of the various routines?

Kent Cooper, AIA
0 Likes
Message 38 of 41

john.uhden
Mentor
Mentor

@ronjonp :

Hey, Ron, what do you do with a perfect reverse curve (both segments are tangent, and have the same chord lengths and radii)?  Because it appears that if the offsets from the original are both the same (except one is to the left and one is to the right) that their areas are identical.

Yeah, this is me again arguing that you can't use the terms "inside" and "outside" but instead must use the terms "left" and "right."  Which is why pointing to the desired side solves the confusion.

My apologies... yes you can use "inside" or "outside" if the polyline is closed, using your comparative area method.

John F. Uhden

0 Likes
Message 39 of 41

ronjonp
Mentor
Mentor

@john.uhden You'll have to draw a picture of your scenario. It's not registering in the brain today 😀.

 

 

 

0 Likes
Message 40 of 41

aadish_rahman
Contributor
Contributor

thank you very much

0 Likes