Author Topic: Trans help  (Read 217 times)

0 Members and 1 Guest are viewing this topic.

CincyJeff

  • Newt
  • Posts: 60
Trans help
« on: January 11, 2017, 10:21:24 am »
I'm trying to place detail bubbles in paperspace aligned with objects in modelspace. I know the insertion point locations in modelspace and I have the viewport object in paperspace. I've tried activating the viewport and using (trans pt 2 3) but it does not return the correct value. The modelspace pt (-706.059 920.111 0.0) has a corresponding paperspace point of (8.36408 8.5 0.0) but (trans pt 2 3) returns (1155.69 -132.538 0.0). Is there a way to translate a known point in modelspace and relate it to a viewport in paperspace?

Master_Shake

  • Swamp Rat
  • Posts: 1180
Re: Trans help
« Reply #1 on: January 11, 2017, 11:17:27 am »
Should be able to pull the required tidbits from here

https://www.theswamp.org/index.php?action=post;quote=334419;topic=27868.0;last_msg=334437

Hi,

Here's a LISP I wrote some times ago.
It draws a leader with WCS coordinates of a point selected through a paper space viewport.

Code: [Select]
;; Coords
;; Creates a leader in the paper space which text is WCS coordinates of the selected point

(defun c:Coords (/ vp elst os pt1 pt2 pt)
  (vl-load-com)
  (or *acdoc*
      (setq *acdoc* (vla-get-ActiveDocument (vlax-get-acad-object)))
  )
  (if (= (getvar "TILEMODE") 0)
    (progn
      (vla-put-MSpace *acdoc* :vlax-False)
      (and
(setq vp (car (entsel "\nSelect a viewport: ")))
(setq elst (entget vp))
(or (= (cdr (assoc 0 elst)) "VIEWPORT")
    (and (member (cdr (assoc 0 elst))
'("CIRCLE" "ELLIPSE" "LWPOLYLINE" "REGION" "SPLINE")
)
(setq vp (cdr (assoc 330 elst)))
(= (cdr (assoc 0 (entget vp))) "VIEWPORT")
    )
)
(setq vp (vlax-ename->vla-object vp))
(= (vla-get-ObjectName vp) "AcDbViewport")
(setq os (osmodes))
(while
  (and
    (setq pt1 (getpoint "\nFirst point of the leader: "))
    (setq pt1 (trans pt1 1 0))
    (not (vla-put-MSpace *acdoc* :vlax-true))
    (not (vla-put-activePViewport *acdoc* vp))
    (setq pt (osnap (trans (trans pt1 3 2) 2 1) os))
    (setq pt (trans pt 1 0))
    (not (vla-put-MSpace *acdoc* :vlax-False))
    (setq pt1 (trans pt1 0 1))
    (setq pt2 (getpoint pt1 "\nFollowing point: "))
  )
   (vl-cmdf "_.leader"
    "_non"
    pt1
    "_non"
    pt2
    ""
    (strcat
      (rtos (car pt))
      "  "
      (rtos (cadr pt))
      ;"  "
      ;(rtos (caddr pt))
    )
    ""
   )
)
(vla-put-MSpace *acdoc* :vlax-False)
      )
    )
    (princ
      "\nThis command is only available in layouts."
    )
  )
  (princ)
)


;; osmodes
;; Returns a strin of active osnaps

(defun osmodes (/ os str)
  (setq os  (getvar 'osmode)
str ""
  )
  (mapcar
    (function
      (lambda (m b)
(if (= b (logand b os))
  (setq str (strcat str m ","))
)
      )
    )
    '("_end" "_mid" "_cen" "_nod" "_qua" "_int" "_ins" "_nea")
    '(1 2 4 8 16 32 64 512)
  )
  str
)

Lee Mac

  • Seagull
  • Posts: 11680
  • AutoCAD 2015 Windows 7 London, England
Re: Trans help
« Reply #2 on: January 11, 2017, 01:06:09 pm »
To go from Modelspace to Paperspace:
Code: [Select]
(trans (trans <point> 0 2) 2 3)
Assuming the Modelspace point is relative to WCS and the viewport is active.

CincyJeff

  • Newt
  • Posts: 60
Re: Trans help
« Reply #3 on: January 11, 2017, 01:58:40 pm »
Thanks Master_Shake, the routine from mjguzik did the trick.
Code - Auto/Visual Lisp: [Select]
  1. (defun ms->ps (point / x y) (mapcar 'set '(x y) (trans (trans (trans point 1 0) 0 2) 2 3)))
Thanks to Lee as well, my points are relative to WCS and I can activate the viewport. Someday I'll understand the trans command.