Drawing a line between the two endpoints of offset arcs

Drawing a line between the two endpoints of offset arcs

jogibson6PA7C
Contributor Contributor
1,405 Views
12 Replies
Message 1 of 13

Drawing a line between the two endpoints of offset arcs

jogibson6PA7C
Contributor
Contributor

I lot of what I use autocad for involves a simple three step process.  Drawing an arc, offset another arc from the first one, and then creating a closed shape by connecting both arcs with two line segments.  

 

 

Step 1:jogibson6PA7C_2-1726580395838.png

 

Step 2:  jogibson6PA7C_4-1726580452257.png

 

 

 

Step 3: jogibson6PA7C_1-1726580371512.png

 

What I'm trying to work out is some way to automate step 3 at a minimum, since that's the most time consuming and doesn't require me to input a specific measurement.

0 Likes
Accepted solutions (3)
1,406 Views
12 Replies
Replies (12)
Message 2 of 13

LDShaw
Collaborator
Collaborator
Accepted solution

I took this from something I've already made.
See if this meets your needs

 

(defun c:foo(/ arc1 arc2 arc1_data arc2_data start1 end1 start2 end2)
  ;; Select the first arc
  (setq arc1 (car (entsel "\nSelect the first arc: ")))
  (setq arc1_data (entget arc1))

  ;; Select the second arc
  (setq arc2 (car (entsel "\nSelect the second arc: ")))
  (setq arc2_data (entget arc2))

  ;; Get the center, radius, start and end angles of both arcs
  (setq center1 (cdr (assoc 10 arc1_data))
        radius1 (cdr (assoc 40 arc1_data))
        start_angle1 (cdr (assoc 50 arc1_data))
        end_angle1 (cdr (assoc 51 arc1_data))

        center2 (cdr (assoc 10 arc2_data))
        radius2 (cdr (assoc 40 arc2_data))
        start_angle2 (cdr (assoc 50 arc2_data))
        end_angle2 (cdr (assoc 51 arc2_data))
  )

  ;; Calculate start and end points of the first arc
  (setq start1 (polar center1 start_angle1 radius1))
  (setq end1   (polar center1 end_angle1 radius1))

  ;; Calculate start and end points of the second arc
  (setq start2 (polar center2 start_angle2 radius2))
  (setq end2   (polar center2 end_angle2 radius2))

  ;; Draw a line connecting the start points of both arcs
  (command "_.line" start1 start2 "")

  ;; Draw a line connecting the end points of both arcs
  (command "_.line" end1 end2 "")

  (princ "\nThe arcs have been closed with lines.")
  (princ)
)

 


I did not know when the arcs were made so I allow you to select them.

Message 3 of 13

jogibson6PA7C
Contributor
Contributor

Works like a charm!   Thank you very much. 

Message 4 of 13

Kent1Cooper
Consultant
Consultant
Accepted solution

It doesn't need to be after the fact with the selection of two already-existing Arcs.  Since you included the drawing of the initial Arc as your desired step 1, this includes that.  And there's no need for a lot of extraction of data and calculations to get the endpoints for the Lines.

It lets you draw the initial Arc by whatever of the many means are available.  It then pauses only for confirmation or setting of the Offset distance [you can use the Through option as well as a distance], and for you to pick on which side to Offset it.

 

(defun C:AOC (/ a1 a2) ; = Arc Offset and Close ends
  (command-s "_.arc"); [however you choose to draw it]
  (setq a1 (entlast))
  (command "_.offset" pause (vlax-curve-getStartPoint a1) pause "")
  (setq a2 (entlast))
  (command
    "_.line" "_non" (getpropertyvalue a1 "StartPoint") "_non" (getpropertyvalue a2 "StartPoint") ""
    "_.line" "_non" (getpropertyvalue a1 "EndPoint") "_non" (getpropertyvalue a2 "EndPoint") ""
  ); command
  (prin1)
)

 

[Unfortunately, it doesn't preview the Offset result as you would see in a basic Offset command -- that doesn't seem to be possible within a (command) or (command-s) function.]

Kent Cooper, AIA
Message 5 of 13

komondormrex
Mentor
Mentor

a matter of interest. getting at once a closed shape in the form of a pline.

 

(defun c:arc_offset_arc_pline (/ origin_arc origin_arc_data 4_included_angle bulge target_arc_offset target_arc_start_point
				 target_arc_end_point pline 
			      )
  	(if (null target_arc_offset_saved) (setq target_arc_offset_saved 10)) 
	(setq origin_arc (vlax-ename->vla-object (car (entsel "\nPick original arc: ")))
		  origin_arc_data (mapcar '(lambda (property) (vlax-get origin_arc property))
					  '(startpoint startangle endpoint endangle center totalangle radius)
				  )
		  1-4_included_angle (* 0.25 (nth 5 origin_arc_data))
		  bulge (/ (sin 1-4_included_angle) (cos 1-4_included_angle))
		  target_arc_offset (if (null (setq target_arc_offset (getreal (strcat "\nEnter target arc offset (positive/negative->outside/inside) <"
										       (rtos target_arc_offset_saved)
										       "> : "
									       )
								      )
								)
					)
				     	target_arc_offset_saved
				      	(setq target_arc_offset_saved target_arc_offset)
				    )
		  target_arc_start_point (polar (nth 4 origin_arc_data) (nth 1 origin_arc_data) (+ (nth 6 origin_arc_data) target_arc_offset))
		  target_arc_end_point (polar (nth 4 origin_arc_data) (nth 3 origin_arc_data) (+ (nth 6 origin_arc_data) target_arc_offset))
	)
	(setq pline (vla-addlightweightpolyline (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
	  					(vlax-safearray-fill (vlax-make-safearray vlax-vbdouble (cons 0 7))
									 (apply 'append (mapcar '(lambda (point) (mapcar '+ '(0 0) point))
												 (list (nth 0 origin_arc_data)
												 	   (nth 2 origin_arc_data)
													   target_arc_end_point
													   target_arc_start_point
												 )
											)
									 )
	  					)
			)
	)
	(mapcar '(lambda (index bulge) (vla-setbulge pline index bulge)) '(0 1 2 3) (list bulge 0 (- bulge) 0))
	(vla-put-closed pline :vlax-true)
	(vla-erase origin_arc)
	(princ)
)

 

updated

 

Message 6 of 13

LDShaw
Collaborator
Collaborator

If he wanted to do a pline 
Pedit multiple  join  jointype add set fuzz distance


Done. If spaced right this could do them all at once. 

 

0 Likes
Message 7 of 13

komondormrex
Mentor
Mentor

maybe he wanted, maybe not; he did not tell. but a term 'shape' speaks for itself, imo.

Message 8 of 13

LDShaw
Collaborator
Collaborator

You are right about the lack of information and I really like the way your lsp works.
I just figured since we were kicking things around. (I originally was going to use pedit on my lisp but decided to keep to just what he asked and not assume.) I figured I'd add my 2¢ and throw in pedit.

0 Likes
Message 9 of 13

jogibson6PA7C
Contributor
Contributor
Could this be adapted to start from a pline instead of an arc? I have a similar use case starting from a pline that this particular solution would be perfect for.
0 Likes
Message 10 of 13

jogibson6PA7C
Contributor
Contributor

To add a bit more information, your original solution did exactly what I was looking for.   Spacing the two arcs (step 2) is a lot less repetitive because I'll use different spacings, so automating that is unlikely to provide much of a time saving.  There are some instances where it *might* be helpful to have step 2 be automated, but more often than not I'll already have an arc to start from, so it's rare that automating step 1, or including its creation in the LSP, will be beneficial.  That said, it's easy enough to just trace an existing arc. 

As for what form the finished object should take, for this use case it doesn't change much, the finished project is just dimensioned and printed from a plotter.  I do have a similar situation that starts from plines, so it would be helpful to also have a lsp that can start with a pline, offset from that pline, then close the shape. 

0 Likes
Message 11 of 13

LDShaw
Collaborator
Collaborator

I wanted to see if Pedit would work. I almost got it to working right. Someone smarter than me needs to figure out how the selection set should work. Right now you have to reselect the plines in the pedit command to close. there should be no need for that.
the Trash file kind of shows you what it will do.

 

 

(defun c:foo (/ ss offsetDist pt plineEntity)
  ;; Step 1: Get the polyline to offset
  (setq ss (ssget "_+.:E:S" '((0 . "LWPOLYLINE,POLYLINE")))) ; Select polyline
  (if ss
    (progn
      ;; Ask for offset distance
      (setq offsetDist (getreal "\nEnter the offset distance: "))
      
      ;; Ask the user to pick a point to determine the offset side
      (setq pt (getpoint "\nSpecify a point on the side to offset: "))
      
      ;; Offset the polyline
      (command "_.OFFSET" offsetDist ss pt "")
      
      ;; Pause to allow user to select items
      (prompt "\nSelect the polylines to join and press Enter: ")
      (setq plineEntity (ssget))
      
      ;; Perform PEDIT on the selected polylines
      (if plineEntity
        (command "_.PEDIT" "_M" plineEntity "" "_J" "_J" "_A" offsetDist "c" "")
        (prompt "\nNo polylines selected for PEDIT.")
      )
    )
    (prompt "\nNo polyline selected.")
  )
  (princ)
)

 

 

 

 


this should do most plines Not just arcs.

0 Likes
Message 12 of 13

Kent1Cooper
Consultant
Consultant
Accepted solution

@jogibson6PA7C wrote:

....  I do have a similar situation that starts from plines, so it would be helpful to also have a lsp that can start with a pline, offset from that pline, then close the shape. 


Try out >this<, which [if it otherwise does what you want] can easily be modified to not include the Hatching part.  It works with all kinds of finite-length objects with linearity [Line, Arc, Circle, Polyline, Ellipse, Spline].

Kent Cooper, AIA
Message 13 of 13

komondormrex
Mentor
Mentor

check the code in message 5 with some repetitive offset automation added. regarding operating on a polyline, would it be 2 vertices pline with non-zero bulge? 

0 Likes