Jump to content

Changing back and forth between UCSs through VLA methods


MJLM

Recommended Posts

Trying to switch from one ucs to an other and then switch back to the first I realized there is something wrong with the routine below. By the way, I found it somewhere on the net.

 

For saving the UCS

(defun saveactiveUCS (/ acadObj doc UCSs)

   (setq acadObj (vlax-get-acad-object))
   (setq doc (vla-get-ActiveDocument acadObj))
   (setq UCSs (vla-get-UserCoordinateSystems doc))

(if (= (vlax-variant-value (vla-GetVariable doc "UCSNAME")) "")			; if the active UCS is not saved (returns empty string "")...
       (progn
    (setq utility (vla-get-Utility doc))
           (setq currUCS
			(vla-Add UCSs
				(vla-GetVariable doc "UCSORG")
				(vla-TranslateCoordinates utility (vla-GetVariable doc "UCSXDIR") acUCS acWorld :vlax-false)
				(vla-TranslateCoordinates utility (vla-GetVariable doc "UCSYDIR") acUCS acWorld :vlax-false)
				"OriginalUCS"
			)
           )
       )
       (setq currUCS (vla-get-ActiveUCS doc))  				;; else, the UCS is saved and we just store it in memory. current UCS is saved
   )
)

 

 

For restoring the UCS

(defun restoreUCS (currUCS /  acadObj doc UCSs currUCS)

(setq acadObj (vlax-get-acad-object))
   (setq doc (vla-get-ActiveDocument acadObj))
   (setq UCSs (vla-get-UserCoordinateSystems doc))

(vla-put-ActiveUCS doc currUCS)
)

 

Apparently, when the initial ucs is not saved in the databse rather just active, it is not working well. The ucs comes to the original location alright but the axes are messed up. Does this happen to you too? If so, what is the problem with the code?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...