Author Topic: Finding Start and Last point  (Read 4368 times)

0 Members and 1 Guest are viewing this topic.

Craig

  • Guest
Finding Start and Last point
« on: June 10, 2005, 10:05:19 AM »
Anyone have a good idea on getting a LWPOLYLINEs first and last point? Example
Code: [Select]
Coordinates = (463.169 705.026 1534.87 705.026 1534.87 1135.03)
This PLINE has 3 vertices and I want the last point. This would apply to LWPOLYLINEs that have multiple vertices as well.

I know I can get the first point using
Code: [Select]
(list
(nth 0
    (vlax-safearray->list
      (vlax-variant-value
(vlax-get-property en_obj 'Coordinates)
      )
    )
)
(nth 1
    (vlax-safearray->list
      (vlax-variant-value
(vlax-get-property en_obj 'Coordinates)
      )
    )
)
     )

It's really the last one I'm after since the last nth might change on each PLINE selected.

whdjr

  • Guest
Finding Start and Last point
« Reply #1 on: June 10, 2005, 10:19:01 AM »
Quote from: AutoCAD Help Files
Returns the endpoint (in WCS) of the curve  
(vlax-curve-getEndPoint curve-obj)

Arguments

curve-obj

The VLA-object to be measured.

Return Values

A 3D point list representing an endpoint, if successful, otherwise nil.

Examples

Get the endpoint of the ellipse used to demonstrate vlax-curve-getArea:

_$ (vlax-curve-getEndPoint ellipseObj)

(2.0 2.0 0.0)

whdjr

  • Guest
Finding Start and Last point
« Reply #2 on: June 10, 2005, 10:20:21 AM »
Quote from: AutoCAD Help Files
Returns the start point (in WCS) of the curve  
(vlax-curve-getStartPoint curve-obj)

Arguments

curve-obj

The VLA-object to be measured.

Return Values

A 3D point list representing the start point, if successful, otherwise nil.

Examples

Get the start point of the ellipse used to demonstrate vlax-curve-getArea:

_$ (vlax-curve-getStartPoint ellipseObj)

(2.0 2.0 0.0)

For an ellipse, the start points and endpoints are the same.
Obtain the start point of the spline used to demonstrate vlax-curve-getDistAtParam:

_$ (vlax-curve-getStartPoint splineObj)

(1.73962 2.12561 0.0)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Finding Start and Last point
« Reply #3 on: June 10, 2005, 10:23:32 AM »
You could Use the curve methods,

but to answer the list question, Perhaps this will help
Code: [Select]

(setq tmp (reverse (vlax-safearray->list  .....
(setq 2dVertexPoint (list (cadr tmp)(car tmp))
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.

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Finding Start and Last point
« Reply #4 on: June 10, 2005, 11:31:34 AM »
Visit my homepage -> Free Stuff and search for 'VxGetEndPoints'

Cheers
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18

whdjr

  • Guest
Finding Start and Last point
« Reply #5 on: June 10, 2005, 12:03:42 PM »
But to answer the original question:
Quote from: Craig
Anyone have a good idea on getting a LWPOLYLINEs first and last point?


and because he already had the polyline object:

Code: [Select]
(vlax-curve-getstartpoint en_obj)
(vlax-curve-getendpoint en_obj)

You don't have to deal with the lists. :)

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Finding Start and Last point
« Reply #6 on: June 10, 2005, 01:16:36 PM »
And here's another way of doing this, skipping the use of the (vlax-curve) functions. This is handy to know since the curve functions are not easily available in VBA, but this methodolgy will work.
Code: [Select]

;for testing, select pline
(setq pline (vlax-ename->vla-object (car (entsel "\nSelect pline: "))))
;get the startpoint, the coordinate property doesn't like the (vlax-get) way of obtaining the data
(setq stPt (vlax-safearray->list (vlax-variant-value (vla-get-coordinate pline 0))))
;find # of vertices, O based...note that the coordinates property works fine with (vlax-get)
(setq vert# (1- (/ (length (vlax-get pline 'coordinates)) 2)))
;get the endpoint
(setq endPt (vlax-safearray->list (vlax-variant-value (vla-get-coordinate pline vert#))))

Craig

  • Guest
Finding Start and Last point
« Reply #7 on: June 10, 2005, 01:36:47 PM »
Quote from: whdjr

Code: [Select]
(vlax-curve-getstartpoint en_obj)
(vlax-curve-getendpoint en_obj)

You don't have to deal with the lists. :)


Thanks Will, that couldn't be any easier. Learning this stuff bit by bit and those two lines beat my six lines.  :D

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Finding Start and Last point
« Reply #8 on: June 10, 2005, 02:36:00 PM »
Quote from: Craig

Thanks Will, that couldn't be any easier. Learning this stuff bit by bit and those two lines beat my six lines.  :D
And to help with the learning a little......the (vlax-curve-) functions work with many types of objects:
Line, Arc, LWPline, Pline, Spline, 3DPline, Ellipse, Circle.

Furthermore, you don't need to convert to/from a vla-object to use them. You can send EITHER a valid <ename> OR vla-object  :)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Finding Start and Last point
« Reply #9 on: June 10, 2005, 03:10:53 PM »
The vlax-curve function is a very powerful tool.

But for those wanting plain lisp..

Code: [Select]
;;  Returns the ends of LWPline
;;  No error checking
;;  Expects an entity name
(defun pline_ends (ent / elst)
  (setq elst (entget ent))
  (list (cdr (assoc 10 elst))
        (cdr (assoc 10 (reverse elst))))
)
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.

daron

  • Guest
Finding Start and Last point
« Reply #10 on: June 10, 2005, 03:26:54 PM »
Also, don't forget this fine tutorial entitled Relaxed curves, given by our own SMadsen.

whdjr

  • Guest
Finding Start and Last point
« Reply #11 on: June 10, 2005, 03:41:41 PM »
Quote from: daron
Also, don't forget this fine tutorial entitled Relaxed curves, given by our own SMadsen.
AHA!  You found it!

I was looking for that earlier Daron.  I'm glad you found that and posted it.  It's a good read and awesome learning tool.

daron

  • Guest
Finding Start and Last point
« Reply #12 on: June 10, 2005, 04:22:01 PM »
It's pretty easy. It's on the second page of the "Teach Me" forum. That is a prime example of the purpose of the Teach Me forum.