Author Topic: transfer point coordinates from Block to Space  (Read 1287 times)

0 Members and 1 Guest are viewing this topic.

Coder

  • Swamp Rat
  • Posts: 827
transfer point coordinates from Block to Space
« on: January 29, 2014, 12:31:21 AM »
Hello guys .

I thought to get coordinates of a point in my Block is simple but I found out the coordinates of the point object is faraway from the correct location of the block , strange to me ! :-o

Is there a way to transfer the coordinates of that point object to current active space in my autocad ?

Many thanks in advance .  :-)

reltro

  • Guest
Re: transfer point coordinates from Block to Space
« Reply #1 on: January 29, 2014, 11:37:07 AM »
Hey Coder...

I had the same Problem short time ago...
I solved it so I wanna share

Code: [Select]
(defun BCS2WCS (BlockRef pointlist / ent inspkt ang)
    (setq ent (entget BlockRef))
    (setq inspkt (cdr (assoc 10 ent)))
    (setq ang (cdr (assoc 50 ent)))
    (mapcar
        '(lambda (Pt /)
            (trans
                (mapcar
                    '+
                    (polar
                        '(0 0 0)
                        (+ ang (angle '(0 0 0) Pt))
                        (distance '(0 0 0) Pt)
                    )
                    inspkt
                )
                BlockRef
                0
            )
        )
        pointlist
    )
)


(defun WCS2BCS (BlockRef pointlist / ent inspkt ang)
    (setq ent (entget BlockRef))
    (setq inspkt (cdr (assoc 10 ent)))
    (setq ang (cdr (assoc 50 ent)))

    (mapcar
        '(lambda (Pt /)
            (apply
                '(lambda (x y z / )
                    (list
                        (+ (* x (cos ang)) (* y (sin ang)))
                        (- (* x (sin ang)) (* y (cos ang)))
                        z
                    )
                )
                (mapcar
                    '-
                    (trans
                        Pt
                        0
                        BlockRef
                        'T
                    )
                    InsPkt
                )
            )
        )
        pointlist
    )
)


I named the function with BCS... BlockCoordinateSystem ;)
maybe, if u need it, u have to add a multiplication with the scale...

Hope it helps
greets
reltro

Coder

  • Swamp Rat
  • Posts: 827
Re: transfer point coordinates from Block to Space
« Reply #2 on: January 30, 2014, 12:08:59 AM »
Hi reltro .

Thank you so much for sharing your nice work , it works great .  :-)

You are awesome .