Author Topic: (cadr (nentsel))  (Read 4597 times)

0 Members and 2 Guests are viewing this topic.

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: (cadr (nentsel))
« Reply #15 on: December 15, 2016, 03:20:41 PM »
Your picture shows the work.
My final goal is to work with the selection point to calculate the distance between it and the ends of the block.
IMO alot more efficient would be if you include that axis line into the block's definition, so we could skip all the nasty explode stuff.
And this one should give you everything you need, both distances and the coordinates of the closest point:
Code: [Select]
(defun C:test ( / p pick e enx BothDistances ClosestPoint)
  (while
    (not
      (and
        (setq p (getpoint "\nSelect the line: "))
        (setq pick (nentselp p))
        (setq e (car pick))
        (= "LINE" (cdr (assoc 0 (setq enx (entget e)))))
        (if (apply '< (setq BothDistances (mapcar '(lambda (x) (distance p (cdr (assoc x enx)))) (list 10 11))))
          (setq ClosestPoint (cdr (assoc 10 enx)))
          (setq ClosestPoint (cdr (assoc 11 enx)))
        )     
      )
    )
    p
  )
  (alert
    (strcat
      "\nFirst distance: " (rtos (car BothDistances) 2) " units."
      "\nSecond Distance: " (rtos (cadr BothDistances) 2) " units."
      "\nClosest Point is located at: " (vl-princ-to-string ClosestPoint) " coordinates."
    )
  )
  (princ)
)
Although it was an interesting practice! :-D
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

velasquez

  • Newt
  • Posts: 195
Re: (cadr (nentsel))
« Reply #16 on: December 15, 2016, 05:23:05 PM »
Your picture shows the work.
My final goal is to work with the selection point to calculate the distance between it and the ends of the block.
IMO alot more efficient would be if you include that axis line into the block's definition, so we could skip all the nasty explode stuff.
And this one should give you everything you need, both distances and the coordinates of the closest point:
Although it was an interesting practice! :-D

The image shows how my work is.
The selection point obtained with (cadr (nentsel) is used in the left block without problem.
Note that in the right block the calculation fails, always returning the same coordinate.

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: (cadr (nentsel))
« Reply #17 on: December 15, 2016, 05:47:03 PM »
I don't think you'll have this problem with the last code I posted, the only requirement is to include that line into the block's definition.
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: (cadr (nentsel))
« Reply #18 on: December 15, 2016, 10:08:35 PM »
Here is my snippet, but I haven't read whole topic deeply, so this is only applicable for picking curves such as LINE among others...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / s l p )
  2.  
  3.  
  4.   (while (setq s (nentsel))
  5.     (setq l (car s))
  6.     (setq p (cadr s))
  7.     (setq p (vlax-curve-getclosestpointtoprojection l (trans p 1 0) (getvar 'viewdir)))
  8.       (prompt "\nPicked point is closer to end point of curve...")
  9.       (prompt "\nPicked point is closer to start point of curve...")
  10.     )
  11.   )
  12.   (princ)
  13. )
  14.  

Regards...
« Last Edit: December 16, 2016, 06:55:50 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: (cadr (nentsel))
« Reply #19 on: December 16, 2016, 10:17:05 AM »
@Marko:
I think the viewdir is expressed in the current UCS.
So you should use:
Code: [Select]
(trans (getvar 'viewdir) 1 0 T)

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: (cadr (nentsel))
« Reply #20 on: December 16, 2016, 11:27:14 AM »
@Marko:
I think the viewdir is expressed in the current UCS.
So you should use:
Code: [Select]
(trans (getvar 'viewdir) 1 0 T)

Yes, Roy, you're right... Thanks for heads up... I've corrected my library in all occurs of this mistake... I simply haven't checked it in random UCS...
Many thanks... M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

velasquez

  • Newt
  • Posts: 195
Re: (cadr (nentsel))
« Reply #21 on: December 16, 2016, 11:30:20 AM »
I appreciate the help I'm getting.