Jump to content

Need a Lisp to Zoom fit model space rectangle on layout View.


Recommended Posts

Posted

Hi Saqib_thelo,

 

the BoundingBox is always calculated in WCS...

To use the same method in UCS I have recurred to two Gilles Chanteau's excellent functions, the gc:TMatrixFromTo and gc:UcsBoundingBox.

 

(defun c:demo ( / a b e)
 
 (vl-load-com)

;; by Gilles Chanteau
;; gc:TMatrixFromTo
;; Retourne la matrice de transformation (4x4) d'un système de coordonnées
;; vers un autre (mêmes types d'arguments que trans)
;;
;; Arguments
;; from : système de coordonnées de départ (entier, vecteur ou ename)
;; to : système de coordonnées de destination (entier, vecteur ou ename)
(defun gc:TMatrixFromTo	(from to)
 (append
   (mapcar
     (function
(lambda	(v o)
  (append (trans v from to T) (list o))
)
     )
     (list '(1. 0. 0.) '(0. 1. 0.) '(0. 0. 1.))
     (trans '(0 0 0) to from)
   )
   (list '(0. 0. 0. 1.))
 )
)

;; by Gilles Chanteau
;; gc:UcsBoundingBox
;; Retourne les coordonnées SCU de l'emprise (bounding box) de l'entité
;; par rapport au SCU courant.
;;
;; Arguments
;; obj: une entité (ENAME ou VLA-OBJCET)
;; _OutputMinPtSym: un symbole quoté (output)
;; _OutputMaxPtSym: un symbole quoté (output)
(defun gc:UcsBoundingBox (obj _OutputMinPtSym _OutputMaxPtSym)
 (vl-load-com)
 (and (= (type obj) 'ENAME)
      (setq obj (vlax-ename->vla-object obj))
 )
 (vla-TransformBy obj (vlax-tmatrix (gc:TMatrixFromTo 1 0)))
 (vla-GetBoundingBox obj _OutputMinPtSym _OutputMaxPtSym)
 (vla-TransformBy obj (vlax-tmatrix (gc:TMatrixFromTo 0 1)))
 (set _OutputMinPtSym
      (vlax-safearray->list (eval _OutputMinPtSym))
 )
 (set _OutputMaxPtSym
      (vlax-safearray->list (eval _OutputMaxPtSym))
 )
)

 (if (setq e (car (entsel "\nSelect Rectang : ")))
   (progn
     (gc:UcsBoundingBox e 'a 'b)
     (vl-cmdf "_.zoom" a b)
   )
 )
 (princ)
)

 

Without using the BoundingBox method, maybe something like this will be enough

 

(defun c:demo (/ a b o ss)
 (vl-load-com)
 (if (setq ss (ssget "_+.:E:S" '((0 . "LWPOLYLINE")(-4 . "&=")(70 . 1))))
   (progn
     (setq o (vlax-ename->vla-object (ssname ss 0))
    a (vlax-curve-getpointatparam o 1)
    b (vlax-curve-getpointatparam o 3)
    )
           (vl-cmdf "_.zoom" (trans a 0 1) (trans b 0 1))
   )
 )
 (princ)
)

 

Hope that helps

Henrique

  • Replies 31
  • Created
  • Last Reply

Top Posters In This Topic

  • hmsilva

    9

  • Saqib_theleo

    7

  • EBROWN

    6

  • janaudie

    3

Posted

Hi Henrique,

Many thankss. Both codes are working nice on changed UCS.

Thanks for you time and help. GBY.

Posted

You're welcome, Saqib_thelo

Glad I could help

 

 

Henrique

Posted

Thank you Henrique.

Using the first program I can select a polyline or block. Using the second program I can not select the block only a polyline.

I have tried to add the step to lock the viewport but failed. Could you add that step to the programS.

 

 

Thanks

 

 

EBROWN

Posted

Henrique,

 

 

I gave it one more try and I was able to add the step to lock the viewport.

 

 

Thanks

 

 

EBROWN

Posted

Hi EBROWN,

 

 

glad you got a solution

 

 

Henrique

  • 5 years later...
Posted

It says this error

Select Rectang : ; error: no function definition: VLAX-ENAME->VLA-OBJECT

How to fix this?

Posted
6 hours ago, janaudie said:

It says this error

Select Rectang : ; error: no function definition: VLAX-ENAME->VLA-OBJECT

How to fix this?

Add (VL-LOAD-COM) to the code.

Posted

I added the (vl-load-com) but still the same error.

Posted
On 10/03/2020 at 22:28, janaudie said:

It says this error

Select Rectang : ; error: no function definition: VLAX-ENAME->VLA-OBJECT

How to fix this?

Any update for this error? it's the same error when (vl-load-com) will be added. sorry I'm not expert on lisps

  • 2 years later...
Posted
On 4/18/2014 at 7:56 PM, hmsilva said:

Hi EBROWN,

 


(defun c:demo (/ a b e o)
 (vl-load-com)
 (if (and (= (getvar 'TILEMODE) 0)
   (/= (getvar 'CVPORT) 1)
   (setq e (car (entsel "\nSelect Rectang : ")))
     )
   (progn
     (setq o (vlax-ename->vla-object e))
     (vlax-invoke-method o 'GetBoundingBox 'a 'b)
     (setq a (vlax-safearray->list a)
    b (vlax-safearray->list b)
     )
     (vl-cmdf "_.zoom" a b)
     (vlax-put	(vla-get-activepviewport
	  (vla-get-activedocument (vlax-get-acad-object))
	)
	'DisplayLocked
	:vlax-true
     )
   )
 )
 (princ)
)
 

 

 

HTH

Henrique

 

I want to add when you select the viewport if it is Locked remove it !

(defun SSVPLock ( ss lock / i )
      (if ss (repeat (setq i (sslength ss))
                (vla-put-displaylocked (vlax-ename->vla-object (ssname ss (setq i (1- i)))) lock) t ) ))

;;Unlocks Selected Viewports / Requires a pick
(if (SSVPLock (ssget "_+.:E:S:L" '((0 . "VIEWPORT"))) :vlax-false)
(princ "\n--> Viewport Unlocked."))

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...