Author Topic: Getting and setting coordinates and scale of viewports  (Read 2194 times)

0 Members and 1 Guest are viewing this topic.

Red Nova

  • Newt
  • Posts: 69
Getting and setting coordinates and scale of viewports
« on: June 08, 2018, 04:05:46 PM »
Hi.

The way I work with dwg files is I always have a frame block in the model space that is of size of the paper and has appropriate annotative scale.
Then I go to paper space, and through the viewport I am navigating to this block and setting the scale accordingly. See attached file for reference.

I am willing to write a code that would allow me:
- While being on the paper space go inside the viewport, select the frame block in modelspace - after this annotative scale of the viewport and it's coordinates should be adjusted based on scale and location of the frame block in model space.
This would be useful every time I would create a new page.

Are there some functions that would allow to set coordinates and annotative scale of the viewport?
Express tools has a similar command but it's not exactly the same....

Thank you


Red Nova

  • Newt
  • Posts: 69
Re: Getting and setting coordinates and scale of viewports
« Reply #2 on: June 13, 2018, 02:43:27 PM »
HasanCAD, I don't think you got my question right way. I know CHANGESPACE, but it's not connected to what I am looking for.
alignspace is closer, but still not the same.

rayakmal

  • Newt
  • Posts: 49
Re: Getting and setting coordinates and scale of viewports
« Reply #3 on: June 16, 2018, 10:25:56 PM »
I usually do this:
1. Create or Name a view of the Block Frame in Model Space.
2. Switch to Paper Space.
3. Activate the Viewport.
4. Call that Named view of the Block Frame

Marco Jacinto

  • Newt
  • Posts: 47
Re: Getting and setting coordinates and scale of viewports
« Reply #4 on: June 18, 2018, 06:54:53 PM »
rayakmal, simple and effective, haven't figure it out, thanks.

Red Nova

  • Newt
  • Posts: 69
Re: Getting and setting coordinates and scale of viewports
« Reply #5 on: June 21, 2018, 05:17:13 PM »
rayakmal,

Thanks for the suggestion.
But I still think it's too slow for me.

rayakmal

  • Newt
  • Posts: 49
Re: Getting and setting coordinates and scale of viewports
« Reply #6 on: June 22, 2018, 07:48:25 PM »
rayakmal,

Thanks for the suggestion.
But I still think it's too slow for me.

It's a pseudo-code. You can speed up the process by using Lisp.

Red Nova

  • Newt
  • Posts: 69
Re: Getting and setting coordinates and scale of viewports
« Reply #7 on: June 24, 2018, 10:20:32 PM »
Your post gave me idea for this ։).
Not universal since it will work with exact blocks and exact viewport setup. But it's something to start with...

Code - Auto/Visual Lisp: [Select]
  1. (defun C:test ( / sourceann adoc blk vlablk blkXY pt1 pt2)
  2.     );_ end of vla-startundomark
  3.   (setq blk (car(entsel)))
  4.   (setq vlablk (vlax-ename->vla-object blk))
  5.   (setq sourceann (/ 1 (car(getannoscalevalues blk))))
  6.   (setq blkXY (vlax-safearray->list (vlax-variant-value (vla-get-insertionpoint vlablk))))
  7.   (setq pt1 (list (+ (car blkXY) (* sourceann 1)) (+ (cadr blkXY) (* sourceann 0.5)))
  8.         pt2 (list (+ (car blkXY) (* sourceann 31)) (+ (cadr blkXY) (* sourceann 23.5))))
  9.   (command "zoom" "w" pt1 pt2)
  10.   (vla-endundomark adoc) ; undomark mark
  11.   (princ)
  12. );defun
  13.  
  14.  
  15. (defun getannoscalevalues (e / el dict lst rewind res)
  16.       (if (and e
  17.            (setq dict (cdr (assoc 360 (entget e))))
  18.            (setq lst (dictsearch dict "AcDbContextDataManager"))
  19.            (setq lst (dictsearch (cdr (assoc -1 lst)) "ACDB_ANNOTATIONSCALES")) ;_ end of setq
  20.            (setq dict (cdr (assoc -1 lst)))
  21.           ) ;_ end of and
  22.         (progn
  23.           (setq rewind t)
  24.           (while
  25.             (setq lst   (dictnext dict rewind))
  26.             (setq e     (cdr (assoc 340 lst))
  27.                    ;; RJP 5.9.2017 - added decimal value to list
  28.                    res  (cons (/ (cdr (assoc 140 (entget e))) (cdr (assoc 141 (entget e)))) res)
  29.                    rewind nil
  30.              ) ;_ end of setq
  31.            ) ;_ end of while
  32.         ) ;_ end of progn
  33.       ) ;_ end of if
  34.       (reverse res)
  35.     )