mid and end points of lines and arcs

mid and end points of lines and arcs

dario_jukica
Contributor Contributor
2,085 Views
29 Replies
Message 1 of 30

mid and end points of lines and arcs

dario_jukica
Contributor
Contributor

Hi.

I have a drawing with multiple lines and arcs.

I need to place a point od every line end and every arc end and every arc mid.

Overkill at the end to delete multiple.

 

Please help.

 

Thank you.

 

Kind regards,

Dario

0 Likes
Accepted solutions (2)
2,086 Views
29 Replies
Replies (29)
Message 2 of 30

ВeekeeCZ
Consultant
Consultant
Accepted solution

Try this.

 

(vl-load-com)

(defun c:linarcpoints ( / s e i a b c p l)

  (if (setq s (ssget '((0 . "ARC,LINE"))))
    (repeat (setq i (sslength s))
      (setq e (ssname s (setq i (1- i)))
	    a (vlax-curve-getstartpoint e)
	    b (vlax-curve-getendpoint e)
	    c (if (= "ARC" (cdr (assoc 0 (entget e))))
		(vlax-curve-getpointatdist e (/ (vlax-curve-getdistatparam e (vlax-curve-getendparam e)) 2))))
      (foreach p (list a b c)
	(if (and p (not (vl-remove-if-not '(lambda (x) (equal p x 1e-5)) l)))
	  (setq l (cons p l))))))
  (foreach p l (entmake (list '(0 . "POINT") (cons 10 p))))
  (princ)
  )

 

Message 3 of 30

komondormrex
Mentor
Mentor

another take

 

 

 

(vl-load-com)
(defun c:mark_end_mid (/ line_arc_sset)
  (setq line_arc_sset (ssget '((0 . "line,arc"))))
  (foreach ename (vl-remove-if 'listp (mapcar 'cadr (ssnamex line_arc_sset)))
	(foreach point (list (vlax-get (vlax-ename->vla-object ename) 'startpoint)
			     (vlax-get (vlax-ename->vla-object ename) 'endpoint)
			     (if (vlax-property-available-p (vlax-ename->vla-object ename) 'center)
				     (vlax-curve-getpointatparam (vlax-ename->vla-object ename) (* 0.5 (+ (vlax-curve-getendparam (vlax-ename->vla-object ename))
													  (vlax-curve-getstartparam (vlax-ename->vla-object ename))
												       )
												)
				     )
			       	     nil
		       	     )
		       )
			  (if point (ssadd (vlax-vla-object->ename (vla-addpoint (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
				                         			 (vlax-3d-point point)
						    		   )
					   )
					   line_arc_sset
				    )
		          )
	)
  )
  (command "_-overkill" line_arc_sset "" "_d")
  (princ)
)

 

0 Likes
Message 4 of 30

_gile
Consultant
Consultant

Hi,

 

This should work for the mid point of most of the curve entities (Line, Arc, Circle, Ellipse, Polyline, Spline)

 

(defun vlax-curve-getMidPoint (curve / endParam)
  (if (setq endParam (vlax-curve-getEndParam curve))
    (vlax-curve-getPointAtDist
      curve
      (/ (vlax-curve-getDistAtParam curve endParam) 2.)
    )
  )
)

 

Testing command:

 

(defun c:test (/ ss i c)
  (if (setq ss (ssget '((0 . "ARC,CIRCLE,ELLIPSE,LINE,LWPOLYLINE,SPLINE"))))
    (repeat (setq i (sslength ss))
      (setq c (ssname ss (setq i (1- i))))
      (foreach p (list (vlax-curve-getMidPoint c)
		       (vlax-curve-getEndPoint c)
		 )
	(entmake
	  (list
	    (cons 0 "POINT")
	    (cons 10 p)
	  )
	)
      )
    )
  )
  (princ)
)

 

 

 

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 5 of 30

Kent1Cooper
Consultant
Consultant
(defun C:TEST (/ ss n ent)
  (if (setq ss (ssget '((0 . "LINE,ARC"))))
    (repeat (setq n (sslength ss))
      (setq ent (ssname ss (setq n (1- n))))
      (command
        "_.point" "_non" (vlax-curve-getstartpoint ent)
        "_.point" "_non" (vlax-curve-getendpoint ent)
      )
      (if (member '(0 . "ARC") (entget ent))
        (command "_.point" "non"
          (vlax-curve-getpointatdist ent (/ (vlax-curve-getdistatparam ent (vlax-curve-getendparam ent)) 2))
        )
      )
    )
  )
  (prin1)
)
Kent Cooper, AIA
0 Likes
Message 6 of 30

Kent1Cooper
Consultant
Consultant

[For both @_gile and @komondormrex :  They didn't want Points at the midpoints of Lines, only Arcs.  But they did want them at the start points of both, which it looks like @_gile's doesn't do.]

 

[Also, a small thing, but....  Your 2. can be just 2 -- the potential division "problem" is only when both numbers are integers, but what you're dividing there will always be a real number, so the 2 doesn't need to be.]

Kent Cooper, AIA
0 Likes
Message 7 of 30

komondormrex
Mentor
Mentor

you're **** right) 

0 Likes
Message 8 of 30

_gile
Consultant
Consultant

@Kent1Cooper  a écrit :

[For both @_gile and @komondormrex :  They didn't want Points at the midpoints of Lines, only Arcs.  But they did want them at the start points of both, which it looks like @_gile's doesn't do.]


I did not try to give the OP an out of the box solution wich exactly reply to its request. I always tend to provide more genric function helpers for the OP to solve the problem by itself.

The testing command I posted is just to show how the vlax-curve-getMidPoint custom function and the vlax-curve-getEndPoint native one can be used to solve the OP request and also how it works with most of the curve entities.

 


@Kent1Cooper  a écrit :

[Also, a small thing, but....  Your 2. can be just 2 -- the potential division "problem" is only when both numbers are integers, but what you're dividing there will always be a real number, so the 2 doesn't need to be.]


I think it is a good practice to always use real numbers for operations that must return a real number. It makes the intentions of the code immediately explicit to the reader and it avoids a conversion to the compiler (this is also a habit with F# language which does not tolerate any implicit conversion).



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 9 of 30

komondormrex
Mentor
Mentor

imho they are succesive lines and arcs, so overkill is needed to kill coincident points 

0 Likes
Message 10 of 30

dario_jukica
Contributor
Contributor

This works great.

Can you please add an overkill at the end...I'm getting some random duplicate points.

Thank you.

 

Cheers

0 Likes
Message 11 of 30

ВeekeeCZ
Consultant
Consultant

Ok, try the updated code. 

0 Likes
Message 12 of 30

dario_jukica
Contributor
Contributor

Works great, thank you very much.

0 Likes
Message 13 of 30

Sea-Haven
Mentor
Mentor

I may be wrong looking at code above but why not, is there a point already there, check so no need for the "Overkill" what about 2 lines joining do put end  & start = 4 points when should only be 3.

0 Likes
Message 14 of 30

dario_jukica
Contributor
Contributor

Is it too much to ask for an expansion of the code...please advise if I have to open a new topic.

 

The problem you have solved here is the first part of the task.

After that, I have to name them starting with a specific number. Standard style, height 1.25. Names must be placed in a closest possible position so that they don't overlap with each other or any of the lines. 

Once numbered I have to gather all the coordinates (2 decimal points) end export them to an excel table (name, X, Y, Z)

 

Thank you.

0 Likes
Message 15 of 30

ВeekeeCZ
Consultant
Consultant

Not at all. But you know, the code is so simple that it's pretty self-explanatory.

So do you understand at least something and say have issues with one or two lines?

 

0 Likes
Message 16 of 30

dario_jukica
Contributor
Contributor

I have no clue about coding, unfortunately, took a look at it but it makes no sense to me.

 

0 Likes
Message 17 of 30

ВeekeeCZ
Consultant
Consultant

Ooh... my bad, now I see it. You wanted an expansion, not an explanation. 

 

Well, probably better to start over. Post drawing with examples of the desired outcomes - Both, dwg and txt.

0 Likes
Message 18 of 30

dario_jukica
Contributor
Contributor

Attached please find an example of the finished files.

0 Likes
Message 19 of 30

ВeekeeCZ
Consultant
Consultant

That's a quite common task with plenty od solutions already written. All you need is to search.

0 Likes
Message 20 of 30

dario_jukica
Contributor
Contributor

You are correct, there are a few solutions out there but non of the ones I found do what I need and since I don't know how to code I don't know how to adapt them to my needs.

Tried using ChatGPT to help me out but we weren't able to figure it out.

Will keep searching then.

Thank you.

0 Likes