TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Coder on April 19, 2012, 02:16:47 AM

Title: code that does the trick as the command -view
Post by: Coder on April 19, 2012, 02:16:47 AM
Hello everybody .

How to do a named view with lisp without using command call ?

Many thanks
Title: Re: code that does the trick as the command -view
Post by: Stefan on April 19, 2012, 02:56:56 AM
Explore properties and methods for Views collection.
Code - Auto/Visual Lisp: [Select]
Title: Re: code that does the trick as the command -view
Post by: Coder on April 19, 2012, 03:22:04 AM
Thank you Stefan .

I tried to change the center point and the start with the end points of the view , but I could not . :oops:

Can you please take a look  .... ?

Code: [Select]

(setq v (vla-item (vla-get-views (vla-get-ActiveDocument (vlax-get-acad-object))) "MyView"))
(vla-put-center v (vlax-3d-point '(10.0 10.0))) ;;; this is return error
(vla-put-startpoint v (vlax-3d-point '(10.0 10.0))) ;;; this is return error
(vla-put-endpoint v (vlax-3d-point '(50.0 50.0))) ;;; this is return error

Title: Re: code that does the trick as the command -view
Post by: Stefan on April 19, 2012, 04:18:24 AM
Center point is a 2d coordinate

View object doesn't have StartPoint and EndPoint properties. Do you mean Height and Width?
If you are looking for a view delimited by '(10 10) and '(50 50) corners, try
Code - Auto/Visual Lisp: [Select]
  1. (setq v (vla-Add views "MyView"))
  2.  
  3. (setq p1 '(10. 10.)
  4.       p2 '(50. 50.)
  5.       c1 (mapcar '(lambda (x y) (* 0.5 (+ x y))) p1 p2)
  6.       ds (mapcar 'abs (mapcar '- p1 p2)))
  7.  
  8. (vlax-put v 'Center c1)
  9. (vlax-put v 'Height (cadr ds))
  10. (vlax-put v 'Width (car ds))
Title: Re: code that does the trick as the command -view
Post by: Coder on April 19, 2012, 04:30:42 AM
Very nice , thanks a lot Stefan  :-)

One last question please .

why this did not work ?

Code: [Select]
(vla-put-center v (vlax-3d-point '(25.0 25.0 0.0)))
Title: Re: code that does the trick as the command -view
Post by: kruuger on April 19, 2012, 04:35:20 AM
small tip. center of view is not in center if view is rotated.
http://www.theswamp.org/index.php?topic=38126.msg431906#msg431906
k.
Title: Re: code that does the trick as the command -view
Post by: Stefan on April 19, 2012, 04:42:55 AM
vlax-3d-point create a 3d coordinate and Center property require a 2D coordinate
Code - Auto/Visual Lisp: [Select]
  1. (vla-put-Center v (vlax-make-variant
  2.                     (vlax-safearray-fill
  3.                       (vlax-make-safearray vlax-vbDouble '(0 . 1))
  4.                       '(25. 25.)
  5.                       )
  6.                     )
  7.   )
Title: Re: code that does the trick as the command -view
Post by: Coder on April 19, 2012, 04:50:40 AM
vlax-3d-point create a 3d coordinate and Center property require a 2D coordinate
Code - Auto/Visual Lisp: [Select]
  1. (vla-put-Center v (vlax-make-variant
  2.                     (vlax-safearray-fill
  3.                       (vlax-make-safearray vlax-vbDouble '(0 . 1))
  4.                       '(25. 25.)
  5.                       )
  6.                     )
  7.   )

That's great Stefan . it is a very kind of you to spend that time for me with the clear explanations .

Many thanks  :-)