TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: csgoh 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?
(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.
-
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
-
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.
-
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 ;
;;;; 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 ;
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 ;
;;;-------------------------------------------------------------
;;;-------------------------------------------------------------
;;
(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
(kb:UCS:NameWorld T)
(vlax-dump-object g:ucss t)
the count will NOW be 1 <one>
so then ..
(vlax-dump-object (vla-item g:ucss 0) t)
will return something like this :
; 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 ;
;;;-------------------------------------------------------------
;;;-------------------------------------------------------------
;;
(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
)
-
.. and this should satisfy most of your needs ;
;;;-------------------------------------------------------------
;;;-------------------------------------------------------------
;;
(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
)
-
Kerry
Cool - man. Thanks.
-
Kerry...c'mon...double colon's please!!!! :-D :-D :kewl:
-
csgoh , my pleasure.
Glenn , yeah .. I C the humour++ in that :-)
-
.. and this should satisfy most of your needs ...
And that ladies and gentlemen is what we call the motherload.
Good stuff Kerry!