Author Topic: Region 'Z' oops for coords conflict..  (Read 995 times)

0 Members and 1 Guest are viewing this topic.

ScottMC

  • Newt
  • Posts: 192
Region 'Z' oops for coords conflict..
« on: November 04, 2022, 03:48:40 PM »
Sorry but forgot to save the author/page but know there must be a way to get the region centroid. It works fine on 3DSOLID w/Z[+/-]. https://www.theswamp.org/Smileys/black/idiot2.gif

Here's what works if I set the UCS to the region to get its center coordinate. What's the easiest way to incorporate a OCS capture in this? THANKS MUCH!

Code: [Select]
(defun c:cnt ( / ss ent enta ptx pty ptz) ;;
  (vl-load-com)
(setvar 'cmdecho 0)
  (setq ss (ssget "_+.:E:S" '((0 . "3DSOLID,REGION"))))
 (setq ent (ssname ss 0))
  (setq enta (vlax-ename->vla-object ent))
  (setq cent (vlax-safearray->list (vlax-variant-value (vla-get-Centroid enta))))
 ;; coords at CMD [regions not wcs/0, error..]
   (setq ptx (rtos (car cent) 2 5)
            pty (rtos (cadr cent) 2 5)
           ptz (if (/= (caddr cent) nil) (rtos (caddr cent) 2 5) (setq ptz "Not WCS"))
    )
(princ (strcat "\n Centroid:   " ptx "," pty "," ptz))
  (vl-cmdf "point" cent)
  (setvar 'cmdecho 1)
  (princ)
)
« Last Edit: November 04, 2022, 03:52:17 PM by ScottMC »

kirby

  • Newt
  • Posts: 132
Re: Region 'Z' oops for coords conflict..
« Reply #1 on: November 04, 2022, 05:03:18 PM »
This works to get a centroid.  Am I missing a something about creating a UCS?

Code - Auto/Visual Lisp: [Select]
  1. (defun C:TestRegionCentroid ()
  2. ; Test function to get the centroid of a region using vla methods
  3.  
  4. (setq MySel (entsel "\nSelect a region..."))
  5. (if MySel
  6.   (progn
  7.         (setq MyEnt (car MySel))
  8.         (setq MyEntData (entget MyEnt))
  9.         (setq EntType (strcase (cdr (assoc 0 MyEntData))))
  10.         (if (eq EntType "REGION")
  11.           (progn
  12.                 (setq MyObj (vlax-Ename->Vla-Object MyEnt))
  13.  
  14.                 (setq MyCentroid (vlax-safearray->list (vlax-variant-value (vla-get-Centroid MyObj))))
  15.                 (prompt "\n  Centroid = ")(princ MyCentroid)(princ)
  16.                
  17.                 (command ".POINT" MyCentroid)
  18.           )    
  19.         ) ; close if
  20.   )
  21. ) ; close if
  22.  

kirby

  • Newt
  • Posts: 132
Re: Region 'Z' oops for coords conflict..
« Reply #2 on: November 04, 2022, 05:07:53 PM »
Ahh, I get it.  If you create a planar region at Z=0, then move it say to Z=10.0, following error is raised:
error: Automation Error. Region is not on the UCS plane