Author Topic: Find 2 nearest intersection point from text insertion  (Read 2988 times)

0 Members and 1 Guest are viewing this topic.

m4rdy

  • Newt
  • Posts: 62
Find 2 nearest intersection point from text insertion
« on: April 25, 2011, 04:17:44 AM »
How do we find two nearest intersection point from text insertion point?
Thank you.


m4rdy
Autocad 2007, Windows XP

Lee Mac

  • Seagull
  • Posts: 12916
  • London, England
Re: Find 2 nearest intersection point from text insertion
« Reply #1 on: April 25, 2011, 05:54:06 AM »
  • Make a SelectionSet of all candidate lines
  • Find all points of intersection between all objects within such a SelectionSet (example here)
  • Sort the list of intersection points by distance to a certain point.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Find 2 nearest intersection point from text insertion
« Reply #2 on: April 25, 2011, 08:48:07 AM »

Not covered by the spec' ..
will the text always be parallel with the concrete beam centerLine ( I assume you are endeavouring to extract the beam length)

I can see some problems with just accepting the closest points to the text.
Perhaps determine the closest centerline then find the intersection of intersecting candidates ... etc
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

m4rdy

  • Newt
  • Posts: 62
Re: Find 2 nearest intersection point from text insertion
« Reply #3 on: April 25, 2011, 09:10:15 AM »
Hi Kerry

...
will the text always be parallel with the concrete beam centerLine ( I assume you are endeavouring to extract the beam length)
....

Yes, the text always be parallel with the concrete beam centerline.
And Yes, i need to make polylines from those 2 points and the end result is finding the beam length.

...
I can see some problems with just accepting the closest points to the text.
Perhaps determine the closest centerline then find the intersection of intersecting candidates ... etc

Yes again, that's my problem.

So far, this is my pseudo code:
1. Get all insertion point of texts in "BEAM" layer
2. Get all intersection points of line in "GRID" layer
3. Find the nearest GRID line from each of insertion text
4. Find 2 nearest intersection point from result no.3
5. Make polyline from result no.4

I hope that makes more clearly (or not... :-()

Thank you Lee Mac and Kerry.

m4rdy
Autocad 2007, Windows XP

Lee Mac

  • Seagull
  • Posts: 12916
  • London, England
Re: Find 2 nearest intersection point from text insertion
« Reply #4 on: April 25, 2011, 09:34:42 AM »
Draft of my pseudo code - as Kerry states though, this method is not bullet-proof.

Code: [Select]
(defun c:test ( / pt ss in ) (vl-load-com)
  (if
    (and
      (setq pt (getpoint "\nPoint to Test: "))
      (setq ss (ssget "_X" '((0 . "LINE") (8 . "GRID"))))
      (setq in (LM:GetIntersectionsinSS ss))
      (< 1 (length in))
    )
    (progn
      (setq pt (trans pt 1 0)
            in (vl-sort in '(lambda ( a b ) (< (distance a pt) (distance b pt))))
      )
      (foreach x (list (car in) (cadr in))
        (entmakex (list (cons 0 "POINT") (cons 10 x)))
      )
    )
  )
  (princ)
)

m4rdy

  • Newt
  • Posts: 62
Re: Find 2 nearest intersection point from text insertion
« Reply #5 on: April 25, 2011, 09:59:14 AM »
Wow, so fast reply.
Thank you Lee.
Much appreciated.

m4rdy
Autocad 2007, Windows XP

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Find 2 nearest intersection point from text insertion
« Reply #6 on: April 25, 2011, 11:22:05 AM »
So what are you doing with the text you collect?
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

m4rdy

  • Newt
  • Posts: 62
Re: Find 2 nearest intersection point from text insertion
« Reply #7 on: April 25, 2011, 11:32:51 AM »
So what are you doing with the text you collect?


Hi Alan,
For finding insertion point of each text as base point to find two nearest intersection points.

m4rdy
Autocad 2007, Windows XP

m4rdy

  • Newt
  • Posts: 62
Re: Find 2 nearest intersection point from text insertion
« Reply #8 on: April 25, 2011, 11:40:13 AM »
Code: [Select]
;; Entmake lwpolyline
(defun LWPoly (lst cls)
  (entmakex
    (append (list (cons 0 "LWPOLYLINE")
 (cons 100 "AcDbEntity")
 (cons 100 "AcDbPolyline")
 (cons 90 (length lst))
 (cons 70 cls);_0 = open 1 = closed
 (cons 40 10.)
 (cons 41 10.)  
   )
   (mapcar (function (lambda (p) (cons 10 (trans p 0 1)))) lst)
    )
  )
)

;; Get insertion point of text
;; Return : ((ename1 (ins_point1)) (ename2 (ins_point2))...)

(defun get-ins-txt (sset / i j ent sset entl ins_point)
  (setq i -1)
  (while (setq ent (ssname sset (setq i (1+ i))))
    (setq entl (entget ent)
 ins_point (cons (cons ent (list (cdr (assoc 10 entl))))  ins_point)
    )
  )
)

;; Original from Lee mac
;; modified by m4rdy

(defun c:beam (/ pt ss1 ss2 in ins_txt)
  (vl-load-com)
  (princ "SELECT BEAM TEXT")
  (setq ss1 (ssget "_X" '((0 . "LINE") (8 . "GRID"))))
  (setq ss2 (ssget '((0 . "TEXT") (8 . "BEAM"))))
  (setq in (LM:GetIntersectionsinSS ss1))
  (setq ins_txt (get-ins-txt ss2))
  (if (and ss1 ss2 (< 1 (length in)))
    (progn
      (foreach x ins_txt
(setq pt (trans (cadar ins_txt) 1 0)
     in (vl-sort in
 '(lambda (a b) (< (distance a pt) (distance b pt)))
)
)
(LWPoly (list (car in) (cadr in)) 0)
      ) ;_foreach
    ) ;_progn
  ) ;_if
  (princ)
)

I have some troubles with 'foreach'.
If anybody can help..
Thank you

m4rdy
« Last Edit: April 25, 2011, 11:44:15 AM by m4rdy »
Autocad 2007, Windows XP

Lee Mac

  • Seagull
  • Posts: 12916
  • London, England
Re: Find 2 nearest intersection point from text insertion
« Reply #9 on: April 25, 2011, 11:49:19 AM »
Hi M4rdy,

Perhaps try something like this:

Code: [Select]
;; Entmake lwpolyline
(defun LWPoly (lst cls)
  (entmakex
    (append (list (cons 0 "LWPOLYLINE")
  (cons 100 "AcDbEntity")
  (cons 100 "AcDbPolyline")
  (cons 90 (length lst))
  (cons 70 cls);_0 = open 1 = closed
  (cons 40 10.)
  (cons 41 10.)  
    )
    (mapcar (function (lambda (p) (cons 10 (trans p 0 1)))) lst)
    )
  )
)

(defun LM:GetTextInsertion ( eList )
  (cdr
    (assoc
      (if
        (and
          (zerop (cdr (assoc 72 elist)))
          (zerop (cdr (assoc 73 elist)))
        )
        10 11
      )
      elist
    )
  )
)

;; Original from Lee Mac
;; modified by m4rdy

(defun c:beam ( / ss1 ss2 in en pt i ) (vl-load-com)

  (princ "\nSelect Beam Text: ")
  (if
    (and
      (setq ss1 (ssget "_X" '((0 . "LINE") (8 . "GRID"))))
      (setq ss2 (ssget '((0 . "TEXT") (8 . "BEAM"))))
      (setq in (LM:GetIntersectionsinSS ss1))
      (< 1 (length in))
    )
    (repeat (setq i (sslength ss2))
      (setq en (ssname ss2 (setq i (1- i)))
            pt (trans (LM:GetTextInsertion (entget en)) en 0)
            in (vl-sort in '(lambda ( a b ) (< (distance a pt) (distance b pt))))
      )
      (LWPoly (list (car in) (cadr in)) 0)
    )
  )
  (princ)
)

m4rdy

  • Newt
  • Posts: 62
Re: Find 2 nearest intersection point from text insertion
« Reply #10 on: April 25, 2011, 12:01:22 PM »
Hi M4rdy,

Perhaps try something like this:

Code: [Select]
;; Entmake lwpolyline
(defun LWPoly (lst cls)
  (entmakex
    (append (list (cons 0 "LWPOLYLINE")
  (cons 100 "AcDbEntity")
  (cons 100 "AcDbPolyline")
  (cons 90 (length lst))
  (cons 70 cls);_0 = open 1 = closed
  (cons 40 10.)
  (cons 41 10.)  
    )
    (mapcar (function (lambda (p) (cons 10 (trans p 0 1)))) lst)
    )
  )
)

(defun LM:GetTextInsertion ( eList )
  (cdr
    (assoc
      (if
        (and
          (zerop (cdr (assoc 72 elist)))
          (zerop (cdr (assoc 73 elist)))
        )
        10 11
      )
      elist
    )
  )
)

;; Original from Lee Mac
;; modified by m4rdy

(defun c:beam ( / ss1 ss2 in en pt i ) (vl-load-com)

  (princ "\nSelect Beam Text: ")
  (if
    (and
      (setq ss1 (ssget "_X" '((0 . "LINE") (8 . "GRID"))))
      (setq ss2 (ssget '((0 . "TEXT") (8 . "BEAM"))))
      (setq in (LM:GetIntersectionsinSS ss1))
      (< 1 (length in))
    )
    (repeat (setq i (sslength ss2))
      (setq en (ssname ss2 (setq i (1- i)))
            pt (trans (LM:GetTextInsertion (entget en)) en 0)
            in (vl-sort in '(lambda ( a b ) (< (distance a pt) (distance b pt))))
      )
      (LWPoly (list (car in) (cadr in)) 0)
    )
  )
  (princ)
)

Thank you very much, Lee Mac.
Now, It's done very well.

m4rdy
Autocad 2007, Windows XP

Lee Mac

  • Seagull
  • Posts: 12916
  • London, England
Re: Find 2 nearest intersection point from text insertion
« Reply #11 on: April 25, 2011, 12:06:16 PM »
You're welcome M4rdy, happy to help you along the way  :-)