getboundingbox error

getboundingbox error

GeryKnee
Advocate Advocate
644 Views
5 Replies
Message 1 of 6

getboundingbox error

GeryKnee
Advocate
Advocate

 

Theres an error in the following code, at position

(setq ent (entget CurEnt))

 

Of course CurEnt is not valid type for entget  :::::::

 


(defun fn ( / Cur)
(if(setq ss (ssget "_X" '((0 . "TEXT"))))
(setq CurEnt (ssname ss 0))
)
)


(defun c:xx ( / Cur)
(if(setq CurEnt(fn))
(Progn
(setq ent (entget CurEnt)) ;; <------ ERROR HERE
(vlax-invoke-method (vlax-ename->vla-object CurEnt) 'getboundingbox 'minpt 'maxpt)
(setq pt1 (trans (vlax-safearray->list minpt) 0 ent))
(setq pt2 (trans (vlax-safearray->list maxpt) 0 ent))
)
)
(princ)
)

 

Please Help,

Thanks

Gery

0 Likes
Accepted solutions (1)
645 Views
5 Replies
Replies (5)
Message 2 of 6

ronjonp
Advisor
Advisor

Again .. what are you trying to accomplish?

 

This: (setq curent (fn))

Is not an ename to 'entget'.

 

Try this:

(defun c:xx (/ ent maxpt minpt pt1 pt2 ss) ;<- Localize variables
  (if (setq ss (ssget "_X" '((0 . "TEXT"))))
    (progn (setq ent (ssname ss 0))
	   (vlax-invoke-method (vlax-ename->vla-object ent) 'getboundingbox 'minpt 'maxpt)
	   (setq pt1 (trans (vlax-safearray->list minpt) 0 ent))
	   (setq pt2 (trans (vlax-safearray->list maxpt) 0 ent))
    )
  )
  (princ)
)

 

Message 3 of 6

paullimapa
Mentor
Mentor
Accepted solution

the following revision seems to work for me:

(defun c:xx ( / Cur)
(if(setq CurEnt(fn))
(Progn
(setq ent (entget CurEnt))
;(vlax-invoke-method (vlax-ename->vla-object CurEnt) 'getboundingbox 'minpt 'maxpt) ;; <------ ERROR HERE
(vla-GetBoundingBox (vlax-ename->vla-object CurEnt) 'minpt 'maxpt)
;(setq pt1 (trans (vlax-safearray->list minpt) 0 ent)) ;; <------ ERROR HERE
(setq pt1 (trans (vlax-safearray->list minpt) 0 CurEnt))
;(setq pt2 (trans (vlax-safearray->list maxpt) 0 ent)) ;; <------ ERROR HERE
(setq pt2 (trans (vlax-safearray->list maxpt) 0 CurEnt))
)
)
(princ)
)


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 4 of 6

Kent1Cooper
Consultant
Consultant

@GeryKnee wrote:

.....

(setq ent (entget CurEnt)) ;; <------ ERROR HERE
....
(setq pt1 (trans (vlax-safearray->list minpt) 0 ent))
(setq pt2 (trans (vlax-safearray->list maxpt) 0 ent))
....


The 'ent' variable will hold an entity data list, but the (trans) function doesn't want to be given that as a 'to' argument -- it wants an entity name.

Kent Cooper, AIA
0 Likes
Message 5 of 6

GeryKnee
Advocate
Advocate

 

Hello sir,

Thank you very much for your invaluable help.

Here I have to apologize if I don't quite agree with you on some things.

You know , I'm 70 years old and I've spent my life writing thousands of Pascal and Basic routines and now I'm trying
to write in autolisp.

There are many autolisp experts like you here on the forum and I try to learn from them.

But there is one rule I've learned over the years that I try to apply to my autolisp effort as well.

The rule is that if someone is trying to read software written 30 years ago, it must have been written in short sentences, simple and clear wording.
Here's an example :

 


(defun c:xx ( / )
(if(setq ss (ssget "_X" '((0 . "TEXT"))))
(princ "texts found")
(princ "texts missing")
)
)

 

Sould be written as 


;; ssmsTexts --> Get all model space texts collection
(defun ssmsTexts ( / )
(ssget "_X" '((0 . "TEXT")))
)

 


(defun c:xx ( / )
(if(setq ss (ssmsTexts))
(princ "texts found")
(princ "texts missing")
)
)

 

or , if doesn't need the ss  ::

 


(defun c:xx ( / )
(if(ssmsTexts)
(princ "texts found")
(princ "texts missing")
)
)

 

I prefare this way

I say yoy one more time

You help me very much with your knowlwdge

What I get from all of the experts in forum, i rewrite it trying to understand deeply the language secrets.

Thank you,

Gery

 

0 Likes
Message 6 of 6

Sea-Haven
Mentor
Mentor

Hi Gerry, this may not be the case the "X" can find stuff in layouts also adding a 410 filter can help

 

;; ssmsTexts --> Get all model space texts collection
(defun ssmsTexts ( / )
(ssget "_X" '((0 . "TEXT")))
)

 

 I tested on a dwg with no text in "Model" but text in a layout, 

 

(sslength (ssget "_X" '((0 . "TEXT"))))
23

 

;; ssmsTexts --> Get all model space texts collection
(defun ssmsTexts ( / )
(ssget "_X" '((0 . "TEXT")(410 . "Model")))
)

(ssget "_X" '((0 . "TEXT")(cons 410 (getvar 'ctab))))

 

 (ssget "_X" '((0 . "TEXT")(410 . "Model")))
nil

0 Likes