Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Zoom object problem

10 REPLIES 10
Reply
Message 1 of 11
dicra
3076 Views, 10 Replies

Zoom object problem

hi everybody,

 

I'm trying to make a lisp, in which one I need to zoom to the object.

First and the quickest way for me was whit using zoom command in lisp, but there was a problem.

Zoom object command is not working for me on this drawing.

 

I founded the way to zoom to the object with out  using zoom command in lisp, but it is still pretty annoying for me why command zoom object is not working, is anybody having any ideas?

 

I have uploaded file in attachements.

 

Thanks for help.

 

 

10 REPLIES 10
Message 2 of 11
m_badran
in reply to: dicra

try to copy to new template file of yours and see what it does and if that fixes it and try to use this.

 

(defun c:zz()
  (command"_.zoom" "o" )
  (princ)
  )

 

Message 3 of 11
dicra
in reply to: m_badran

Mostafa, thank you for answer.

Have you tried that on the drawing which I uploaded?
I know about that, but my question is why command zoom object, is not working on this drawing.
Message 4 of 11
_gile
in reply to: dicra

Hi,

 

IMO, if the zoom object fails, it's due to the fact the blocs are inserted far away from origin.

 

Try using this routine which requires an ename as argument ( i.e. (zoomObject (car (entsel))) )

 

(defun zoomObject (ent / minPt maxPt)
  (vl-load-com)
  (vla-GetBoundingBox (vlax-ename->vla-object ent) 'minPt 'maxpt)
  (vla-ZoomWindow (vlax-get-acad-object) minPt maxpt)
)

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 5 of 11
_gile
in reply to: _gile

Here's another one which works with a selection set.

Using example: (zoomObjects (ssget))

 

(defun zoomObjects (ss / i minPt maxPt ll ur)
  (vl-load-com)
  (repeat (setq i (sslength ss))
    (vla-GetBoundingBox
      (vlax-ename->vla-object (ssname ss (setq i (1- i))))
      'minPt
      'maxpt
    )
    (setq ll (cons (vlax-safearray->list minPt) ll)
	  ur (cons (vlax-safearray->list maxPt) ur)
    )
  )
  (vla-ZoomWindow
    (vlax-get-acad-object)
    (vlax-3d-point (apply 'mapcar (cons 'min ll)))
    (vlax-3d-point (apply 'mapcar (cons 'max ur)))
  )
)

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 6 of 11
dicra
in reply to: _gile

gile, 

 

Thank you for reply.

Your routines are working fine, on the drawing.

Before this problem, I was using command "zoom" "o" in my routine, I changed to something similar as your code (probably it was your code, which I founded on the web). That was the solution for my problem.

 

But, I'm having this problem only on this one drawing. I  was using same blocks on different drawings for a long time whit out this problem.

So, I was thinking there is probably some kind of system variable which is setting zoom command.

I have founded solution for my problem, but I don't know why is this happening only on this one drawing.

Message 7 of 11
IanGold
in reply to: _gile

This is the message appears after running command in cad  "too few arguments"

 

Could you please upload a lisp for other's convenience.

 

Many Thanks

Tags (1)
Message 8 of 11
_gile
in reply to: IanGold


IanGold a écrit :

This is the message appears after running command in cad  "too few arguments"

 

Could you please upload a lisp for other's convenience.

 

Many Thanks


The upper routines are LISP functions which require an argument.

See the using examples in the messages...



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 9 of 11
rmC86GJ
in reply to: _gile

Would be really nice if the above routines worked as well when in UCS...

Cheers,

Message 10 of 11
_gile
in reply to: rmC86GJ

Hi,

 

What do you mean?

These routines should work whatever the current UCS because both vla-GetBoundingBox and vla-ZoomWindow are related to WCS coordinates, so there's nothing related to the current UCS in these codes.

I think you meant "worked as well when in a view rotated about the UCS". If so, try the following one:

 

(defun gc:TMatrixFromTo	(from to)
  (append
    (mapcar
      (function
	(lambda	(v o)
	  (append (trans v from to T) (list o))
	)
      )
      '((1. 0. 0.) (0. 1. 0.) (0. 0. 1.))
      (trans '(0. 0. 0.) to from)
    )
    '((0. 0. 0. 1.))
  )
)

(defun zoomObjects (ss / i obj minPt maxPt ll ur)
  (vl-load-com)
  (or *acad* (setq *acad* (vlax-get-acad-object)))
  (or *acdoc* (setq *acdoc* (vla-get-ActiveDocument *acad*)))
  (setq  wcs2ucs (vlax-tmatrix (gc:TMatrixFromTo 0 1))
         ucs2wcs (vlax-tmatrix (gc:TMatrixFromTo 1 0))
         )
  (repeat (setq i (sslength ss))
    (setq obj (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
    (vla-TransformBy obj ucs2wcs)
    (vla-GetBoundingBox
      obj
      'minPt
      'maxpt
    )
    (vla-TransformBy obj wcs2ucs)
    (setq ll (cons (vlax-safearray->list minPt) ll)
          ur (cons (vlax-safearray->list maxPt) ur)
    )
  )
  (vla-ZoomWindow
    (vlax-get-acad-object)
    (vlax-3d-point (trans (apply 'mapcar (cons 'min ll)) 1 0))
    (vlax-3d-point (trans (apply 'mapcar (cons 'max ur)) 1 0))
  )
)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 11 of 11
rmC86GJ
in reply to: _gile


@_gile wrote:

... 

I think you meant "worked as well when in a view rotated about the UCS". 


That's exactly right, Gilles, sorry for not been clear enough. Now it's all fine, thanks a lot!

Cheers,

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost