Jump to content

Recommended Posts

Posted

Hi,

 

im trying to get the closest endpoint of a 3D Line from a single Selection. I tried to retrieve the location using ssnamex, wich is working in 2d, but not in 3d from a 3d view.
the Z location somehow always gets messed up in the selection so its not reliable. Any Ideas?

Here is the code im using
 

(defun c:foo (/ ss selPt obj startPt endPt pt1)
  
  (while (not ss)
      (setq ss (ssget "_+.:E:S" '((0 . "LINE"))))
  )

  (setq selPt (cadr (nth 3 (car (ssnamex ss 0))))) ; get point of selection
  
  (setq obj (vlax-ename->vla-object (ssname ss 0)))
  (setq startPt (vlax-curve-getStartPoint obj))
  (setq endPt   (vlax-curve-getEndPoint obj))
  
   ;; Determine closer endpoint
  (if (< (distance selPt startPt) (distance selPt endPt))
    (setq pt1 startPt)
    (setq pt1 endPt)
  )
  
  (vla-put-color (vla-addcircle (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (vlax-3d-point pt1) 10) acRed) ;circle for testing
)

 

Posted

Hello
It is better if you attach an example drawing

Posted

I would suggest using the point returned by entsel corresponding to the center of the pickbox aperture, expressed in UCS, e.g.:

 

(defun c:foo ( / cpt enx ocs pt1 pt2 sel )
    (if (and (setq sel (entsel))
             (= "LINE" (cdr (assoc 0 (setq enx (entget (car sel))))))
        )
        (progn
            (setq ocs (trans '(0 0 1) 1 0 t)
                  cpt (trans (cadr sel) 1 0)
                  pt1 (cdr (assoc 10 enx))
                  pt2 (cdr (assoc 11 enx))
            )
            (if (< (distance pt2 cpt) (distance pt1 cpt))
                (setq pt1 pt2)
            )
            (entmake
                (list
                   '(000 . "CIRCLE")
                   '(040 . 1)
                   '(062 . 1) 
                    (cons 010 (trans pt1 0 ocs))
                    (cons 210 ocs)
                )
            )
        )
    )
    (princ)
)

 

Posted

test.dwg
Here is a example. From this point of view i cant seem to get the upper endpoint of the green line.

Posted (edited)
  15 hours ago, Lee Mac said:

I would suggest using the point returned by entsel corresponding to the center of the pickbox aperture, expressed in UCS, e.g.:


I also tried entsel, but the problem remained esentially the same.
Entsel seems to ignore the Z value and always sets it to 0.0

Also what is the ocs for in your code?

Edited by EnM4st3r
Posted
(defun c:foo (/ ss selPt obj startPt endPt pt1)
  
  (while (not ss)
      (setq ss (ssget "_+.:E:S" '((0 . "LINE"))))
  )

  (setq selPt (trans (cadr (nth 3 (car (ssnamex ss 0)))) 0 2)) ; get point of selection
  
  (setq obj (vlax-ename->vla-object (ssname ss 0)))
  (setq startPt (reverse (cdr (reverse (trans (vlax-curve-getStartPoint obj) 0 2)))))
  (setq endPt   (reverse (cdr (reverse (trans (vlax-curve-getEndPoint obj) 0 2)))))
  
   ;; Determine closer endpoint
  (if (< (distance selPt startPt) (distance selPt endPt))
    (setq pt1 startPt)
    (setq pt1 endPt)
  )
  
  (vla-put-color (vla-addcircle (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (vlax-3d-point (trans pt1 2 0)) 10) acRed) ;circle for testing
)

Hi  EnM4st3r,

 

Try the edited code above if it works for you.

  • Like 2
Posted
  14 hours ago, LanloyLisp said:

Hi  EnM4st3r,

 

Try the edited code above if it works for you.

Nice. It only placed them visually tough, not on the exact endpoints.
I changed it a little, seems to work now.

 

(defun c:foo (/ ss selPt obj pt1 pt2)
  
  (while (not ss)
      (setq ss (ssget "_+.:E:S" '((0 . "LINE"))))
  )

  (setq selPt (trans (cadr (nth 3 (car (ssnamex ss 0)))) 0 2)) ; get point of selection
  (setq obj (vlax-ename->vla-object (ssname ss 0)))
  (setq pt1 (vlax-curve-getStartPoint obj))
  (setq pt2 (vlax-curve-getEndPoint obj))
  
   ;; Determine closer endpoint
  (if (< (distance selPt (reverse (cdr (reverse (trans pt2 0 2)))))
        (distance selPt (reverse (cdr (reverse (trans pt1 0 2)))))
      )
    (setq pt1 pt2)
  )
  
  (vla-put-color (vla-addcircle (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (vlax-3d-point pt1) 10) acRed) ;circle for testing
)


 

  • Like 1
Posted
  15 hours ago, EnM4st3r said:

Also what is the ocs for in your code?

 

Circles are planar entities and defined relative to the OCS.

  • Like 1

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