Author Topic: (Challenge) find the coordinates of a line...  (Read 8179 times)

0 Members and 1 Guest are viewing this topic.

BazzaCAD

  • Guest
(Challenge) find the coordinates of a line...
« on: July 13, 2007, 05:59:14 PM »
The challenge is to find the coordinates of the line in THIS dwg.  :-)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: (Challenge) find the coordinates of a line...
« Reply #1 on: July 13, 2007, 06:11:34 PM »
Seems unusual that it's located by it's center ... ?
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.

BazzaCAD

  • Guest
Re: (Challenge) find the coordinates of a line...
« Reply #2 on: July 13, 2007, 06:14:54 PM »
I guess I should of said the start & end point coordinates.

Josh Nieman

  • Guest
Re: (Challenge) find the coordinates of a line...
« Reply #3 on: July 13, 2007, 06:15:36 PM »
oh fudge..

I saw the title and thought "oh man, even _I_ can write this one!!"

way to kill my spirits :(


Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: (Challenge) find the coordinates of a line...
« Reply #4 on: July 13, 2007, 06:17:30 PM »
I know what you meant :-)
any programmatic solution would need prior knowledge of the item.
... and know that a positive offset is actually negative
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.

BazzaCAD

  • Guest
Re: (Challenge) find the coordinates of a line...
« Reply #5 on: July 13, 2007, 06:22:52 PM »
any programmatic solution would need prior knowledge of the item.
... and know that a positive offset is actually negative

Sorry, I'm not sure I know what you mean. What else do you need?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: (Challenge) find the coordinates of a line...
« Reply #6 on: July 13, 2007, 06:24:40 PM »
Nothing.

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

BazzaCAD

  • Guest
Re: (Challenge) find the coordinates of a line...
« Reply #7 on: July 13, 2007, 06:35:44 PM »
oh fudge..

I saw the title and thought "oh man, even _I_ can write this one!!"

way to kill my spirits :(


Sorry Josh,
Maybe we'll both learning something from this challenge. :)

Josh Nieman

  • Guest
Re: (Challenge) find the coordinates of a line...
« Reply #8 on: July 13, 2007, 06:38:45 PM »
well using 'list' I find that it's inserted at point, X= 124.3487  Y=  25.9280  Z=   0.0000

Luckily the block creator was wise enough to list the "Gap Dist" in the custom properties of that block, (6.000) and the Overall Length, as well, (79.5142) and thus, using geometry, I figure it'd be easy to figure the coords, since the angle of the line is also included in the custom properties... I'm not 100% sure, but I am guessing... that via lisp, you can extract even the 'custom property' values.... but that's a 100% assumption.

unfortunately, though I may be able (if I was lucky) to assert the path to follow to derive the right answer... I lack the programming skills to translate that into the right language.

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: (Challenge) find the coordinates of a line...
« Reply #9 on: July 13, 2007, 06:45:04 PM »
Quick & dirty and only works in WCS and if the block is uniformly scaled.....
Pass the function a VLA-OBJECT of the dynamic line.
Code: [Select]
(defun dynlineendpoints (line / tmp rslt)
  (setq tmp (car (vlax-invoke line 'explode)))
  (setq rslt (cons (vlax-curve-getstartpoint tmp)
   (list (vlax-curve-getendpoint tmp))
   )
)
  (vla-delete tmp)
  rslt
  )
Quote from: CommandLine
Command: (dynlineendpoints (vl-sel))

Select object: ((95.5246 8.3578 0.0) (153.173 43.4983 0.0))

Josh Nieman

  • Guest
Re: (Challenge) find the coordinates of a line...
« Reply #10 on: July 13, 2007, 06:46:16 PM »
dude, explode a copy... that's cheating!!

(and much more efficient then how I was going to do it... but that's playing dirty)

BazzaCAD

  • Guest
Re: (Challenge) find the coordinates of a line...
« Reply #11 on: July 13, 2007, 06:52:39 PM »
Ya that's a great idea.
I wonder how my code will handle getting the coordinates of a bunch of DynBlk's...

LE

  • Guest
Re: (Challenge) find the coordinates of a line...
« Reply #12 on: July 13, 2007, 11:05:08 PM »
Hope that helps.

Code: [Select]
(defun dxf (f lst) (cdr (assoc f lst)))

(defun trans-blk-pts  (ptblk ins_pt ang fx fy / sinang cosang xptblk
       yptblk)
  (setq sinang (sin ang)
cosang (cos ang)
xptblk (car ptblk)
yptblk (cadr ptblk))
  (list
    (+ (- (* xptblk cosang fx) (* yptblk sinang fy))
       (car ins_pt))
    (+ (+ (* xptblk sinang fx) (* yptblk cosang fy))
       (cadr ins_pt))
    0))

(defun draw_point  (pt col / d)
  (setq d (* (getvar "viewsize") 0.015))
  (grdraw
    (trans (polar pt (* 0.25 pi) d) 0 1)
    (trans (polar pt (* 1.25 pi) d) 0 1)
    col
    (- col))
  (grdraw
    (trans (polar pt (* 0.75 pi) d) 0 1)
    (trans (polar pt (* 1.75 pi) d) 0 1)
    col
    (- col)))

(defun nestobj (/ ndata edata matrix pin block
data etype p10 p11 z10 z11
zfactor pts return)
  (if (and (setq ndata (nentsel)) (> (length ndata) 2))
    (progn
      (setq edata  (assoc 10 (entget (car ndata)))
    matrix (caddr ndata)
    pin    (last matrix)
    block  (car (last ndata))
    data   (entget block)
    etype  (cdr (assoc 0 (setq elst (entget (car ndata))))))
      (cond
((= etype "LINE")
(setq p10     (cdr (assoc 10 elst))
       p11     (cdr (assoc 11 elst))
       zfactor (cdr (assoc 43 data))
       ins_pt  (cdr (assoc 10 data)))
(if zfactor
   (progn
     (setq z10 (* (caddr p10) zfactor))
     (setq z11 (* (caddr p11) zfactor))))
(foreach block (last ndata)
   (setq data (entget block)
p10  (trans-blk-pts
p10
(dxf 10 data)
(dxf 50 data)
(dxf 41 data)
(dxf 42 data))
p11  (trans-blk-pts
p11
(dxf 10 data)
(dxf 50 data)
(dxf 41 data)
(dxf 42 data))))
(if z10
   (setq p10 (list (car p10) (cadr p10) z10)))
(if z11
   (setq p11 (list (car p11) (cadr p11) z11)))
(grdraw p10 p11 7 -7)
(setq return (list "LINE" (list p10 p11)))))))
  return)

(defun C:GETENDS  (/ data)
  (if (and (setq data (nestobj)) (= (car data) "LINE"))
    (progn
    (draw_point (car (cadr data)) 1)
    (draw_point (cadr (cadr data)) 1))) (princ))

(princ)

If you have already a function to calculate those two points, I would like to see it. Thanks.
« Last Edit: July 13, 2007, 11:13:57 PM by LE »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: (Challenge) find the coordinates of a line...
« Reply #13 on: July 13, 2007, 11:26:44 PM »
Barry,

(are you in a 'stepping sideways' mood )

What is the bounding-box returned from an interrogation of your object.

... perhaps a redundant thought because of ucs's though .... 

... and also wouldn't identify a start as such ( I assume this is dependant on the rotation direction of the Dynamic Block)

[asides]
Should there be a different offset each end. ?
The result is interesting when the .offset is larger than the .length. :)
How do you handle an instance where you require the actual end to extend past the 'workPoint' ?

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.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: (Challenge) find the coordinates of a line...
« Reply #14 on: July 14, 2007, 01:07:24 AM »
My variant... 

Code: [Select]
(defun test (/ mi ma)
 (vla-GetBoundingBox (vlax-ename->vla-object (car (entsel))) 'mi 'ma)
 (list (vlax-safearray->list mi) (vlax-safearray->list ma))
)