Author Topic: How to select objects at a particular point  (Read 6156 times)

0 Members and 1 Guest are viewing this topic.

Amsterdammed

  • Guest
How to select objects at a particular point
« Reply #15 on: June 01, 2005, 07:50:32 AM »
Quote
The line end points are snapped to polylines, but there is no vertex and no break.


I’m afraid this code is not what will solve the Problem. Because it is the wrong approach, from the polylines. But we want to know if every line is attached to a polyline on at least one Endpoint.

So maybe collecting all the lines in a ss and than foreach checking the Endpoints. But with what? We can’ t do it with equal because there is no point to compare, it is somewhere on the polyline.

So ether we let zoom in again on the points and try with ssget point and filter set to Polyline (to me the easiest but not the most reliable way).

Or you make a ssget with a little window and filter set to Polyline on each checked Endpoint.
Than you can check with the found Polyline or polylines if the drawing is tense if there is a intersection point between the vertex’s and the line we are checking. Doing so with the inters function or
Code: [Select]

 (setq ar
    (vlax-invoke-method
      (vlax-ename->vla-object ent1)
     'IntersectWith
      (vlax-ename->vla-object ent2)
      acExtendNone
    )
  )


This code I found somewhere else but I only used it once and so did not test  a lot.

But the question remains: why doing all this, you said the lines where drawn with snap to the polylines.

SMadsen

  • Guest
How to select objects at a particular point
« Reply #16 on: June 01, 2005, 08:13:46 AM »
Oh, you need to check if lines touch  polyline segments in arbitrary places? Shouldn't be hard to do. Collect polylines as well as line endpoints and play a bit with VLAX-CURVE-GETCLOSESTPOINTTO.

Kinda like (equal 0.0 (distance line_pt (vlax-curve-getClosestPointTo pline_obj line_pt nil)) fuzz) .. but only in pseudo-form as the curve thingie can return nil.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
How to select objects at a particular point
« Reply #17 on: June 01, 2005, 01:21:32 PM »
I think that this will accomplish the task. If any lines are found that do not touch any pline, they are placed into a named selection set and highlighted. Command is ALLTOUCH.....the named selection set will be "NoTouch" and can be accessed by either VBA or Vlisp.
Code: [Select]

(defun c:alltouch (/    close2ept      close2spt
  ept    idx     int?     lines    no_int
  pline    plines   spt
 )
  (vl-load-com)
  (defun active_ss (flist name / code val ss doc)
    (setq doc (vla-get-activedocument (vlax-get-acad-object)))
    (vl-catch-all-apply
      'vla-add
      (list (vla-get-selectionsets doc) name)
    )
    (setq ss (vla-item (vla-get-selectionsets doc) name))
    (vla-clear ss)
    (if flist
      (progn
(mapcar '(lambda (a)
  (setq code (cons (car a) code))
  (setq val (cons (cdr a) val))
)
flist
)
(setq code (vlax-safearray-fill
    (vlax-make-safearray
      vlax-vbinteger
      (cons 0 (- (length code) 1))
    )
    code
  )
     val  (vlax-safearray-fill
    (vlax-make-safearray
      vlax-vbvariant
      (cons 0 (- (length val) 1))
    )
    val
  )
)
(vlax-invoke-method
 ss 'select acSelectionSetAll nil nil code val)
      )
      (vla-select ss acSelectionSetAll)
    )
    (vla-highlight ss :vlax-true)
    (if (> (vla-get-count ss) 0)
      ss
      nil
    )
  )
  (if
    (and (setq lines (active_ss '((0 . "LINE") (67 . 0)) "LineSS"))
(setq plines (active_ss '((0 . "LWPOLYLINE") (67 . 0)) "PLineSS"))
    )
     (progn
       (setq no_int nil)
       (vlax-for line lines
(setq idx  0
      int? nil
      sPt  (vlax-get line 'startpoint)
      ePt  (vlax-get line 'endpoint)
)
(while (and (not int?)
    (< idx (vla-get-count plines))
)
  (setq pline   (vla-item plines idx)
close2sPt (vlax-curve-getclosestpointto pline sPt)
close2ePt (vlax-curve-getclosestpointto pline ePt)
  )
  (if (or (equal (distance sPt close2sPt) 0.0 1e-6)
  (equal (distance ePt close2ePt) 0.0 1e-6)
      )
    (setq int? t)
    (setq idx (1+ idx))
  )
)
(if (not int?)
  (setq no_int (cons line no_int))
)
       )
       (vla-highlight lines :vlax-false)
       (vla-highlight plines :vlax-false)
     )
  )
  (if no_int
    (progn
      (princ
(strcat "\n There are a total of "
(itoa (length no_int))
" lines that do not touch a Polyline."
"\nThese lines are saved in the ActiveX SS \"NoTouch\""
)
      )
      (vl-catch-all-apply
'vla-add
(list (vla-get-selectionsets *doc*) "NoTouch")
      )
      (setq ss (vla-item (vla-get-selectionsets *doc*) "NoTouch"))
      (vla-clear ss)
      (vlax-invoke ss 'additems no_int)
      (vla-highlight ss :vlax-true)
    )
    (princ "\nCongratulations! No untouching lines found!")
  )
  (princ)
)