Jump to content

points at vertixes and inbetween???


r4n

Recommended Posts

howdy,

I found this code:

(defun c:ppav ()

(vl-load-com)

(setq *model-space* (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))))

(setq obj (vlax-ename->vla-object (car (entsel))))

(setq c (vlax-get obj "Coordinates") i 0)

(repeat (/ (length c) 2)

(setq x (nth i c) y (nth (1+ i) c))

(vla-addpoint *model-space* (vlax-3d-point (list x y 0.0)))

(setq i (+ i 2))

(setq temp (osnap (list x y) "mid")) ; I added this

(command "point" temp) ; and this

)

(princ)

)

 

and added the two lines to try and get points set on the midpoints of the pline segments....but it does not work as intended. Some midpoints are set on the wrong segment and 1 extra point is being set.

 

Can Anyone Help?

thanks

Ray

Link to comment
Share on other sites

Instead, consider using the vlax-curve* functions on the *Line's Object/Ename.

 

For example, I think you'll find the vlax-curve-getDistAtParam, and vlax-curve-getParamAtDist functions to be of use.

Link to comment
Share on other sites

Firstly, a warm welcome to CADTutor Ray :)

 

I would suggest the vlax-curve-getpointatparam function since the vertices of an LWPolyline have integer parameters, and hence the midpoints can be found at the half values of the parameters.

 

Here is some quickly written code:

 

(defun c:test ( / e i p s ) (vl-load-com)
 (if (setq s (ssget '((0 . "LWPOLYLINE"))))
   (repeat (setq i (sslength s))
     (repeat (1+ (fix (* 2 (vlax-curve-getendparam (setq p -0.5 e (ssname s (setq i (1- i))))))))
       (entmakex (list (cons 0 "POINT") (cons 10 (vlax-curve-getpointatparam e (setq p (+ p 0.5))))))
     )
   )
 )
 (princ)
)

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