Author Topic: Reset UCS to world  (Read 6921 times)

0 Members and 1 Guest are viewing this topic.

csgoh

  • Newt
  • Posts: 176
Reset UCS to world
« on: January 10, 2006, 12:22:12 AM »
What's the equivalent of (command "ucs" "world") in Vlisp/activeX?
I am currently learning to write a Vlisp/ActiveX to change the UCS but do not know how to change it back to the world UCS?
Code: [Select]

(defun c:test ()
  (setq acadObj           (vlax-get-acad-object)
        ;; acad Object
        ActivedocumentObj (vla-get-Activedocument acadObj)
        ;; the current dwg
        mSpace     (vla-get-ModelSpace ActivedocumentObj)
        ;; the modelspace collection
        objUtilitytypes   (vla-get-Utility ActivedocumentObj)
        ;; the utility collection
        objUCStypes   (vla-get-UserCoordinateSystems Activedocumentobj)
        ;; the UCS collection
        objAppNames (vla-get-RegisteredApplications ActivedocumentObj)
        ;; the Application names for xdata collection
        2pi (* 2 pi)
        orig (list 5 5 0)
        x-crd (list 10 10 0)
        y-crd (polar orig (+ (angle orig x-crd) (* 0.5 pi)) 10.0)
  )
 (wg:ChangeUCS (vlax-3d-point orig) (vlax-3d-point x-crd)
               (vlax-3d-point y-crd) "TESTUCS"
 )
)

;;
;; Function to change the UCS to a selected entity
;; USAGE:
;; Arguments
;; orig  - origin of the new UCS
;; X-crd - the X-axis of the new UCS
;; Y-crd - the Y-axis of the new UCS
;; UCSName - the UCS name
;;
(defun wg:ChangeUCS( orig X-crd Y-crd UCSName / localUCS )

   (vla-put-origin (setq localUCS (vla-add objUCStypes
                                          Orig    ;origin
                                          x-crd   ;x-axis
                                          y-crd   ;y-axis
                                          UCSName ; the UCS name
                                 )) Orig
   )
  (vla-put-activeucs Activedocumentobj localUCS)
 ; (vla-put-activeucs Activedocumentobj acWorld)
);wg:ChangeUCS
Any help is appreciated.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Reset UCS to world
« Reply #1 on: January 10, 2006, 12:32:32 AM »
If you use an origin of 0,0,0, an xdir of 1,0,0 and ydir of 0,1,0 I believe AutoCAD will recognize that as "world".

/guess
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

csgoh

  • Newt
  • Posts: 176
Re: Reset UCS to world
« Reply #2 on: January 10, 2006, 01:02:57 AM »
MP,
In order to revert to the UCS world as explained, you will need to create a new UCS name  for the World UCS.
Is there any way that you do  not have  to create a new name for  the World UC?
Thanks.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Reset UCS to world
« Reply #3 on: January 10, 2006, 04:21:58 AM »
csgoh ,
You are correct, there is no named world ; you need to create a new name for  the World UC.

This can be demonstrated in a new drawing ;
Code: [Select]
;;;; IAcadUCSs Collection
(or g:ucss
    (setq g:ucss
           (vla-get-usercoordinatesystems (vla-get-activedocument (vlax-get-acad-object)))
    )
)

(vlax-dump-object g:ucss t)

You'll see that the count is 0 < zero >

or simply ;
Quote
Command: UCS

Current ucs name:  *WORLD*
Enter an option [New/Move/orthoGraphic/Prev/Restore/Save/Del/Apply/?/World]
<World>: R

Enter name of UCS to restore or [?]: ?

Enter UCS name(s) to list <*>: *

Current ucs name: *WORLD*

Saved coordinate systems:

  No matching UCS names found.

Enter name of UCS to restore or [?]:

Try comething like this ;
Code: [Select]
;;;-------------------------------------------------------------
;;;-------------------------------------------------------------
;;
(defun kb:UCS:NameWorld (MakeActive / localUCS)
  ;;
  ;; IAcadDocument Object
  ;;
  (or g:activedoc (setq g:activedoc (vla-get-activedocument (vlax-get-acad-object))))
 
  ;;
  ;; IAcadUCSs Collection
  ;;
  (or g:ucss
      (setq g:ucss
             (vla-get-usercoordinatesystems (vla-get-activedocument (vlax-get-acad-object))
             )
      )
  )
  ;;
  (setq localUCS (vla-add g:ucss
                          (vlax-3d-point '(0.0 0.0 0.0)) ;origin
                          (vlax-3d-point '(1.0 0.0 0.0)) ;x-axis
                          (vlax-3d-point '(0.0 1.0 0.0)) ;y-axis
                          "_WorldUCS"
                 )
  )
 
  (if MakeActive
    (vla-put-activeucs g:activedoc localUCS)
  )
 
  localUCS
)

Then try
Code: [Select]
(kb:UCS:NameWorld T)
(vlax-dump-object g:ucss t)

the count will NOW be 1 <one>

so then ..
Code: [Select]
(vlax-dump-object (vla-item g:ucss 0) t)will return something like this :
Quote
; IAcadUCS: A user-defined coordinate system that determines the orientation of the X, Y, and Z axes in 3D space
; Property values:
;   Application (RO) = #<VLA-OBJECT IAcadApplication 00c2eb8c>
;   Document (RO) = #<VLA-OBJECT IAcadDocument 058cff84>
;   Handle (RO) = "E5"
;   HasExtensionDictionary (RO) = 0
;   Name = "_WorldUCS"
;   ObjectID (RO) = 2130190184
;   ObjectName (RO) = "AcDbUCSTableRecord"
;   Origin = (0.0 0.0 0.0)
;   OwnerID (RO) = 2130189368
;   XVector = (1.0 0.0 0.0)
;   YVector = (0.0 1.0 0.0)
; Methods supported:
;   Delete ()
;   GetExtensionDictionary ()
;   GetUCSMatrix ()
;   GetXData (3)
;   SetXData (2)

kb:UCS:NameWorld  is from my Library Routines
http://www.theswamp.org/forum/index.php?topic=5794.0

This one may be usefull too ;
Code: [Select]
;;;-------------------------------------------------------------
;;;-------------------------------------------------------------
;;
(defun kb:UCS:NameCurrent (name / Origin localUCS)
    ;;
  ;; IAcadDocument Object
  ;;
  (or g:activedoc (setq g:activedoc (vla-get-activedocument (vlax-get-acad-object))))
 
  ;;
  ;; IAcadUCSs Collection
  ;;
  (or g:ucss
      (setq g:ucss
             (vla-get-usercoordinatesystems (vla-get-activedocument (vlax-get-acad-object))
             )
      )
  )
 
  (setq Origin   (getvar "ucsorg")
        localUCS (vla-add g:ucss
                          (vlax-3d-point '(0.0 0.0 0.0)) ;origin
                          (vlax-3d-point (getvar "ucsxdir")) ;x-axis
                          (vlax-3d-point (getvar "ucsydir")) ;y-axis
                          (if name name "_TempUCS")
                 )
  )
 
  (vla-put-origin localUCS (vlax-3d-point Origin))
 
  (vla-put-activeucs g:activedoc localUCS)
 
  localUCS
)
« Last Edit: January 10, 2006, 04:52:34 AM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Reset UCS to world
« Reply #4 on: January 10, 2006, 04:30:26 AM »
.. and this should satisfy most of your needs ;
Code: [Select]
;;;-------------------------------------------------------------
;;;-------------------------------------------------------------
;;
(defun kb:UCS:BlackBox (NewUcsName Origin XAxis YAxis Activate / objUCS)
  ;;
  ;; by Kerry Brown  2005.Jun.11
  ;; Create a Named UCS and Optionally Activate it.
  ;|
Required globals : g:activedoc, g:ucss
Required dependancies : nil
Parameters  :-
NewUcsName :<string>
Origin :<PointList (X Y Z)>
XAxis :<VectorList (X Y Z)>
YAxis :<VectorList (X Y Z)>
Activate :<nil or NonNil> Set as ActiveUCS

Returns : <VLA-OBJECT IAcadUCS ....>  or nil.

|;
;;;;----------------
  ;;
  ;; IAcadDocument Object
  ;;
  (or g:activedoc (setq g:activedoc (vla-get-activedocument (vlax-get-acad-object))))
  ;;
  ;; IAcadUCSs Collection
  ;;
  (or g:ucss
      (setq g:ucss
             (vla-get-usercoordinatesystems (vla-get-activedocument (vlax-get-acad-object))
             )
      )
  )
  ;; 
  (or NewUcsName (setq NewUcsName "TempUCS"))
  (or Origin (setq Origin (getvar "ucsorg")))
  (or XAxis (setq XAxis (getvar "ucsxdir")))
  (or YAxis (setq YAxis (getvar "ucsydir")))
  ;;
  (setq objUCS (vla-add g:ucss
                        (vlax-3d-point '(0.0 0.0 0.0)) ;origin
                        (vlax-3d-point XAxis)          ;x-axis
                        (vlax-3d-point YAxis)          ;y-axis
                        NewUcsName
               )
  )
  (vla-put-origin objUCS (vlax-3d-point Origin))
  ;;
  (if Activate
    (vla-put-activeucs g:activedoc objUCS)
  )
  objUCS
)

« Last Edit: January 10, 2006, 04:35:13 AM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

csgoh

  • Newt
  • Posts: 176
Re: Reset UCS to world
« Reply #5 on: January 10, 2006, 07:13:57 AM »
Kerry
Cool - man. Thanks.

Glenn R

  • Guest
Re: Reset UCS to world
« Reply #6 on: January 10, 2006, 07:21:57 AM »
Kerry...c'mon...double colon's please!!!!   :-D :-D :kewl:

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Reset UCS to world
« Reply #7 on: January 10, 2006, 07:25:47 AM »
csgoh , my pleasure.

Glenn , yeah .. I C the humour++ in that :-) 



kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Reset UCS to world
« Reply #8 on: January 10, 2006, 10:53:56 AM »
.. and this should satisfy most of your needs ...

And that ladies and gentlemen is what we call the motherload.

Good stuff Kerry!
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst