Author Topic: get the UCS if the object is not on the current one  (Read 9008 times)

0 Members and 1 Guest are viewing this topic.

hendie

  • Guest
get the UCS if the object is not on the current one
« on: September 10, 2004, 05:52:55 AM »
I need some direction here as brainpower is failing fast.
I'm trying to get the centroid of a solid or region. That is no problem, however, if the solid or region is not on the current UCS then it fails with a
Quote
; error: Automation Error. Region is not on the UCS plane

Using the UCS command there is an option to set the UCS to an object, so my initial thought was to set the UCS to the object, get the centroid then return back to the original UCS.
and I can't seem to find a way to do this using vlisp...
can anyone provide some insight or suggestions for me ?

hendie

  • Guest
get the UCS if the object is not on the current one
« Reply #1 on: September 10, 2004, 06:33:32 AM »
I managed to find acet-ucs-to-object which looked interesting.
I can use
Code: [Select]
(setq ObjUCS (acet-ucs-to-object (car (entsel))))
which is fine but I want to pass the object and not to select the object as it has been selected previously so I thought, easy...
Code: [Select]
(setq ObjUCS (acet-ucs-to-object (car Cobj)))
but that returns
Code: [Select]
; error: Function cancelled
for reference:
Code: [Select]
$ (car cobj)
<Entity name: 4002df80>
_$ (car (entsel))
<Entity name: 4002df80>

why would it work when selecting an object but not when an object is passed to it ?

hendie

  • Guest
get the UCS if the object is not on the current one
« Reply #2 on: September 10, 2004, 06:53:56 AM »
and I just realised that if someone doesn't have the express tools then the acet-function won't work anyway.  :fart:

hendie

  • Guest
get the UCS if the object is not on the current one
« Reply #3 on: September 10, 2004, 07:14:56 AM »
and I'd prefer not to write the properties out (massprop) to a file then read them back in.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
get the UCS if the object is not on the current one
« Reply #4 on: September 10, 2004, 07:26:09 AM »
Unless I'm doing something wrong I don't have this problem hendie.

>however, if the solid or region is not on the current UCS then it fails

maybe you could send me the dwg.
TheSwamp.org  (serving the CAD community since 2003)

hendie

  • Guest
get the UCS if the object is not on the current one
« Reply #5 on: September 10, 2004, 07:34:38 AM »
draw a rectangle, make it into a region. then copy it @ 0,0,50
then try to get the centroid

as long as it's planar to some UCS, it has a centroid property, but if it's not planar to the ucs  I get the error:

Quote
Select object: ; IAcadRegion: AutoCAD Region Interface
; Property values:
;   Application (RO) = #<VLA-OBJECT IAcadApplication 00adc088>
;   Area (RO) = 8177.54
;   Centroid (RO) = AutoCAD.Application: Region is not on the UCS plane
;   Color = 256
;   Document (RO) = #<VLA-OBJECT IAcadDocument 01059694>
;   Handle (RO) = "22A"
;   HasExtensionDictionary (RO) = 0
;   Hyperlinks (RO) = #<VLA-OBJECT IAcadHyperlinks 02319c74>
;   Layer = "0"
;   Linetype = "ByLayer"
;   LinetypeScale = 1.0
;   Lineweight = -1
;   MomentOfInertia (RO) = AutoCAD.Application: Region is not on the UCS plane
;   Normal (RO) = (0.0 0.0 1.0)
;   ObjectID (RO) = 1073930128
;   ObjectName (RO) = "AcDbRegion"
;   OwnerID (RO) = 1073929464
;   Perimeter (RO) = 371.865
;   PlotStyleName = "ByLayer"
;   PrincipalDirections (RO) = AutoCAD.Application: Region is not on the UCS plane
;   PrincipalMoments (RO) = AutoCAD.Application: Region is not on the UCS plane
;   ProductOfInertia (RO) = AutoCAD.Application: Region is not on the UCS plane
;   RadiiOfGyration (RO) = AutoCAD.Application: Region is not on the UCS plane
;  
 Visible = -1

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
get the UCS if the object is not on the current one
« Reply #6 on: September 10, 2004, 08:09:15 AM »
I get the same thing hendie.

Centroid (RO) = AutoCAD.Application: Region is not on the UCS plane
TheSwamp.org  (serving the CAD community since 2003)

SMadsen

  • Guest
get the UCS if the object is not on the current one
« Reply #7 on: September 10, 2004, 08:45:41 AM »
Hendie, I tried to use the Normal property to get the plane of the region but can't seem to wrap my head around it right now (perhaps 'cos it's Friday?). I'm sure you can use it to move the UCS momentarily and get the centroid.
Maybe you or someone else can figure it out.

Instead I had some old code to calculate 3D offsets. Just tried to apply it to your problem and it seems to work. Have in mind, it was not made for this task so it's VERY primitive!

*smadsen hides in shame for even having posted it*

Code: [Select]
(defun getEnt (lst / ent)
  (setvar "ERRNO" 0)
  (while (and (not ent) (/= (getvar "ERRNO") 52))
    (cond ((setq ent (car (entsel)))
           (if (not (member (cdr (assoc 0 (entget ent))) lst))
             (setq ent nil)
           )
          )
    )
  )
  ent
)

(defun centreg (/ changeUCS a aang b c centroid ent norm obj p1 p1h p2 p2h ph pt ta tb)
  (cond ((/= (getvar "WORLDUCS") 1)
         (setq changeUCS T)
         (command "UCS" "Save" "temp")
        )
  )
  (cond ((setq ent (getent '("REGION")))
         (setq obj  (vlax-ename->vla-object ent)
               norm (vla-get-normal obj)
         )
         (setq p1 '(0.0 0.0 0.0)
               p2 (vlax-safearray->list (vlax-variant-value norm))
         )
         (setq b    (distance (list (car p1) (cadr p1))
                              (list (car p2) (cadr p2))
                    )
               c    (distance p1 p2)
               a    (- (caddr p2) (caddr p1))
               aAng (atan (/ a b))
               ta   (* c (sin aAng))
               tb   (* c (cos aAng))
               ph   (polar p1 (angle p1 p2) (- b ta))
               p2h  (list (car ph) (cadr ph) (+ (caddr p2) tb))
               ph   (polar p1 (angle p2 p1) ta)
               p1h  (list (car ph) (cadr ph) (+ (caddr p1) tb))
         )
         (cond ((setq pt (getpoint "\nSpecify corner of region: "))
                (command "UCS" "Origin" "_none" pt)
                (command "UCS" "3p" "_none" p1 "_none" p2 "_none" p1h)
                (command "UCS" "Y" 90.0)
                (if (not (vl-catch-all-error-p
                           (setq centroid (vl-catch-all-apply 'vla-get-centroid (list obj)))
                         )
                    )
                  (setq cent (trans (vlax-safearray->list (vlax-variant-value centroid)) 1 0))
                )
               )
         )
        )
  )
  (cond (changeUCS
         (command "UCS" "Restore" "temp")
         (command "UCS" "Delete" "temp")
        )
        ((command "UCS" "World"))
  )
  (mapcar 'princ (list "\nCentroid: " (cond (cent)((vl-catch-all-error-message centroid)))))
  (princ)
)

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
get the UCS if the object is not on the current one
« Reply #8 on: September 10, 2004, 08:52:00 AM »
Hendie, this error only happens on a region and not a 3dsolid, so resetting the UCS might be a better solution.

What might work is...
reset the UCS to object when you select the object
Get the centroid data (and any other you want)
translate the points from UCS to WCS
reset the previous UCS

I could reproduce your error and when I followed the above scenario, the results were good.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

hendie

  • Guest
get the UCS if the object is not on the current one
« Reply #9 on: September 10, 2004, 09:11:12 AM »
Stig, I considered the normal earlier but like you I had my friday head on and just couldn't get enough brain power into it.
Keith, I think you have the method I'm going to use. I just need to figure out which way to go about it.
it's interesting to note that it doesn't happen with a solid, I never checked that. So, in theory, if my object is a region, then I could check the bounding box and work out a UCS from there

SMadsen

  • Guest
get the UCS if the object is not on the current one
« Reply #10 on: September 10, 2004, 09:15:01 AM »
Hendie, did you try the code? Instead of asking for a point on the region you could perhaps use the lower bbox point.

hendie

  • Guest
get the UCS if the object is not on the current one
« Reply #11 on: September 10, 2004, 09:24:21 AM »
I'll try it out this afternoon Stig, thanks.

it's just really annoying because I thought ( :P ) it was going to be no big deal ~ using Massprop returns the centroid regardless of whether it is on the current UCS or not and I, in a moment of madness assumed that ..get-property 'centroid would do the same.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
get the UCS if the object is not on the current one
« Reply #12 on: September 10, 2004, 10:39:28 AM »
Why did Autodesk create such an obvious error in their programming.

Heck if massprop can return the centroid of a region not in the current UCS, then why can't the properties be accessable via ActiveX?
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

hendie

  • Guest
get the UCS if the object is not on the current one
« Reply #13 on: September 10, 2004, 10:49:08 AM »
tell me about it !

hendie

  • Guest
get the UCS if the object is not on the current one
« Reply #14 on: September 13, 2004, 08:09:08 AM »
Stig, I'm getting a divide by zero error at the line
Code: [Select]
aAng (atan (/ a b))

However, your code gave me another idea and I think I'm going to change tack on this one a bit. Since everything else was working OK, I'm going to trap the error and prompt the user to reselect the region, which I'll use to reset the UCS temporarily.
I toyed with the idea of forcing snaps to select the object and if the "Z" coordinate was /= 0 then reset the UCS to another plane but I think I'm going to go with reselecting the object.