Jump to content

Recommended Posts

Posted

I was trying to use LISP to select a segment or edge of a polyline, using "entsel". But when my mouse hover to an edge, it select the whole polyline.

 

Something like when we trigger the Fillet or Chamfer command, we able to highlight and select just only the edge of a polyline.

Posted

@Gino Lau This is not really possible as a direct feature in LISP, but may have a less direct solution using temporary graphics.

 

However, it really depends on what you are trying to do. I know the the single segment selection baked into the Fillet command is not possible to replicate with AutoLISP or Visual Lisp. If you give us an idea of what you are trying to accomplish we may be able to offer an alternate solution.

Posted

Not sure with Lisp, with ARX, you can highlight sub entities, here’s a sample in Python

 

import traceback
from pyrx import Rx, Ge, Gi, Db, Ap, Ed


@Ap.Command("doit")
def justDoit():
    try:
        # selet a polyline
        ps, id, pkpnt = Ed.Editor.entSel("\nSelect", Db.Polyline.desc())
        if ps != Ed.PromptStatus.eOk:
            raise RuntimeError("Selection Error! {}: ".format(ps))

        # open the polyline and get the closest from pkpnt
        pline = Db.Polyline(id)
        cp = pline.getClosestPointTo(pkpnt)

        # hack out a gs marker for the segment and create a path
        gsmkr = int(pline.getParamAtPoint(cp) + 1)
        spath = Db.FullSubentPath(id, Db.SubentType.kEdgeSubentType, gsmkr)

        # highlight is ok with kForRead
        pline.highlight(spath, False)

    except Exception as err:
        traceback.print_exception(err)

 

highlight.png.f63dcef70b718ca715e412ae81d2532c.png

Posted

Select the segment, I don't have anything as such but:

- Select a point  on the polyline (getpoint)

- Create temporary polyline (I don't like these but...)

- Trim temporary polyline at that point

- Work out if the remaining polyline trimmed point it end A or B

- Use mAssoc to get list of points, cadr or (reverse (cadr depends on direction to get the original polyline point

- Use mAssoc on the original polyline, again with reverse or not find the nth + 1 point where n is the vertex above

- Should give the end A and B of the polyline segment, 

 

and from there you can do your stuff.

 

a bit long winded but should work

Posted (edited)

Select a segment lisp, sorry don't know where I got it, so no author name.

 

(defun getplineseg ( / elst ename pt param preparam postparam)
(setq elst (entsel "\nSelect pline segment: "))
(setq ename (car elst))
(setq pt (cadr elst))
(setq pt (vlax-curve-getClosestPointTo ename pt))
(print (setq param (vlax-curve-getParamAtPoint ename pt)) )
(setq preparam (fix param))
(setq postparam (1+ preparam))
(setq pt1 (vlax-curve-getPointAtParam ename preparam)
pt2 (vlax-curve-getPointAtParam ename postparam))
)

Part two can check which end is nearest to pick point. 

 

 

Edited by BIGAL
Posted
On 11/03/2025 at 14:52, Gino Lau said:

I was trying to use LISP to select a segment or edge of a polyline, using "entsel". But when my mouse hover to an edge, it select the whole polyline.

If you want to select just a single or multiple segments of polyline, you can use CTRL + mouse left click to select segments of polylines (I don't know what do you want to accomplish with lisp). See the attached picture.

 

image.thumb.png.f1b16bab9c600aa2d6c442775ac6710e.png

Posted

If you just want to get the pair of points that define the segment, you can use this:

(defun s (ev / x d p i e pS)
  (while (and
           (if x x (setq x (if (= (rem (cdr (assoc 70 (setq x (entget (car ev))))) 2) 0) x (append x (list (assoc 10 x)))) pS (cadr ev)))
	   (setq f (cdr (assoc 10 (setq x (cdr (member (setq p (assoc 10 x)) x))))))
	   (/= (max (distance (cdr p) pS) (distance f pS) (setq d (distance (setq i (cdr p)) f))) d)
	 )
  )
  (if ev (list i f))
)

 

To use it:

(s (entsel "\nSelect segment..."))

 

Posted
3 minutes ago, GLAVCVS said:

If you just want to get the pair of points that define the segment, you can use this:

(defun s (ev / x d p i e pS)
  (while (and
           (if x x (setq x (if (= (rem (cdr (assoc 70 (setq x (entget (car ev))))) 2) 0) x (append x (list (assoc 10 x)))) pS (cadr ev)))
	   (setq f (cdr (assoc 10 (setq x (cdr (member (setq p (assoc 10 x)) x))))))
	   (/= (max (distance (cdr p) pS) (distance f pS) (setq d (distance (setq i (cdr p)) f))) d)
	 )
  )
  (if ev (list i f))
)

 

To use it:

(s (entsel "\nSelect segment..."))

 

 

Of course:
- it's assumed that an 'LWPOLYLINE' is selected. Otherwise, it won't work.

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