vla-get-centroid error

vla-get-centroid error

SAPER59
Advocate Advocate
754 Views
8 Replies
Message 1 of 9

vla-get-centroid error

SAPER59
Advocate
Advocate

I have a problem with some regions, when getting the centroid, function  crashes, and if I go to the object properties, centroid said  Automation Error. Region is not on the UCS plane

I tried setting the UCS to region object, before accessing centroid property, but crashes the same

It happens in many dxf files when creating region from original polyline, but in many others works perfectly

 

(setq en (car(entsel)))
(setq obj1 (vlax-ename->vla-object en))
(setq pc (vla-get-centroid obj1));

;;;;here crashes and can not control with error trap in order to know before getting centroid and continue
(vlax-release-object obj1)

 

If somebody knows how to solvethis. thanks

0 Likes
Accepted solutions (1)
755 Views
8 Replies
Replies (8)
Message 2 of 9

-didier-
Advisor
Advisor

Bonjour @SAPER59 

 

Actually I see the same concern but without “crash” just an error in the search of the centroid.

The concern is the entity not the software, it must be redesigned “properly” and everything will come back into order.

 

Amicalement

 

Éternel débutant.. my site for learning : Programmer dans AutoCAD

DA

EESignature

0 Likes
Message 3 of 9

SAPER59
Advocate
Advocate

Thanks but the point is when the app is running I must detect the error before, in order not to let the function crashes , and go on alerting the user about that object has a problem.

The function handle hundred of dxf inserting , modifying and exporting, and if crashes, there are many dxf that have not been prcessed.

Thanks anyway

0 Likes
Message 4 of 9

sigmmadesigner
Advocate
Advocate

Try It.....

 

(defun CENTROID_EXE (e / obj ll ur)
(if (not (vl-catch-all-error-p
(vl-catch-all-apply 'vla-getboundingbox
(list (setq obj (vlax-ename->vla-object e))
'll
'ur))))
;; Calcula o centro do bounding box
(mapcar '/
(apply 'mapcar
(cons '+ (mapcar 'vlax-safearray->list (list ll ur))))
'(2 2))
)
)

(defun c:centro-textobb ( / ent pt)
(vl-load-com)
(setq ent (car (entsel "\n ADD OBJ: ")))
(if ent
(progn
(setq pt (CENTROID_EXE ent))
(if pt
(progn
(vla-addText
(vla-get-ModelSpace (vla-get-ActiveDocument (vlax-get-acad-object)))
"Centro"
(vlax-3d-point pt)
2.5
)
)
(prompt "\n NOT CENTER")
)
)
(prompt "\n NOT SELECT.")
)
(princ)
)

0 Likes
Message 6 of 9

-didier-
Advisor
Advisor

Bonjour @SAPER59 

 

I understand, then may be with a test like this you can loop over the bad object and continue with the rest

 

(setq ent (car (entsel "Select region")))
(setq vla (vlax-ename->vla-object ent))
(setq result (vlax-safearray->list (vlax-variant-value (vla-get-Centroid vla))))
(if (not (= 'LIST (type result)))
  (alert "Error in centroid search ")
  )
)

 

Amicalement

Éternel débutant.. my site for learning : Programmer dans AutoCAD

DA

EESignature

0 Likes
Message 7 of 9

paullimapa
Mentor
Mentor
Accepted solution

@SAPER59 try this:

(defun rgtest (/ en obj1 pc pt ss)
 (vl-load-com)
 (command "_.UCS" "_OB" pause)
 (setq pt (getvar "lastpoint"))
 (if (setq ss (ssget pt))
  (if (and 
        (eq (cdr (assoc 0 (entget (setq en (ssname ss 0))))) "REGION")
        (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-get-centroid (list (setq obj1 (vlax-ename->vla-object en))))))
      ) 
      (setq pc (vla-get-centroid obj1))
  )
 )
 (command "_.UCS" "_P")
 pc
)

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 8 of 9

SAPER59
Advocate
Advocate

Thanks paullimapa, I coudln't find the right use of catching error

Works perfectly and let me avoid object with problem and continue with others without crashing

Thanks again

0 Likes
Message 9 of 9

paullimapa
Mentor
Mentor

you are welcome...cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes