Control my ucs

Control my ucs

WeTanks
Mentor Mentor
1,615 Views
15 Replies
Message 1 of 16

Control my ucs

WeTanks
Mentor
Mentor

I need your help,

I want to control myucs with the keyboard.
for example
Keyboard input u1,
World UCS → UCS_1
keyboard input u2,
UCS_1  → UCS_2

(defun c:myucs ()
(if (= 0 (getvar "UCSFOLLOW"))
(progn  (setvar "UCSFOLLOW" 1) )



(princ)

 

 

 

Sorry for my expressions, I'm not a programmer.
Many thanks in advance for your help.

 

We.Tanks

EESignature

A couple of Fusion improvement ideas that could your vote/support:
図面一括印刷

0 Likes
Accepted solutions (2)
1,616 Views
15 Replies
Replies (15)
Message 2 of 16

Sea-Haven
Mentor
Mentor

Are the different UCS's saved ? UCS1, UCS2. Not sure what you want.

0 Likes
Message 3 of 16

WeTanks
Mentor
Mentor

I would like to  use the LISP,
keyboard input u1,
UCS can be switched to the UCS_1 I created.

keyboard input u2,
UCS can be switched to the UCS_2 I created.

We.Tanks

EESignature

A couple of Fusion improvement ideas that could your vote/support:
図面一括印刷

0 Likes
Message 4 of 16

Sea-Haven
Mentor
Mentor

Ok simple you need a lisp that has the ucs names in it.

 

(defun c:U1 ()(command "UCS" "R" "UCS_1"))
(defun c:U2 ()(command "UCS" "R" "UCS_2"))
(defun c:U3 ()(command "UCS" "R" "UCS_3"))
..... add more say up to 10

 

I have a startup lisp with these sort of defuns within,  it has like 40 defuns. It is loaded on startup so ready to use, just do Appload and add your startup lisp to the "Start up Suite".

 

The limitation is in the number of defuns made. I would make say 10.

 

 

Message 5 of 16

WeTanks
Mentor
Mentor

Thank you so much

I made it the u1.

(defun c:u1 ()
(if(= 0 (getvar "UCSFOLLOW"))
(progn(setvar "UCSFOLLOW" 1)))
(command-s "._UCS" "R" "UCS_1")
(princ)
)

 

but,Can it be done in a LISP?
u1→UCS_1
u2→UCS_2
u3→UCS_3

 

We.Tanks

EESignature

A couple of Fusion improvement ideas that could your vote/support:
図面一括印刷

0 Likes
Message 6 of 16

Kent1Cooper
Consultant
Consultant

@WeTanks wrote:

....

(defun c:u1 ()
(if(= 0 (getvar "UCSFOLLOW"))
(progn(setvar "UCSFOLLOW" 1)))
(command-s "._UCS" "R" "UCS_1")
(princ)
)

but,Can it be done in a LISP?....


That is doing it in AutoLisp -- define one for each UCS.  But I would suggest a simplification.  Your (progn) function isn't doing anything for you, and since you want UCSFOLLOW to be 1, there's no need to check whether it is currently 0.  Just set it that way, regardless:

(defun c:u1 ()

  (setvar "UCSFOLLOW" 1)

  (command-s "._UCS" "R" "UCS_1")

  (princ)

)

Kent Cooper, AIA
Message 7 of 16

WeTanks
Mentor
Mentor

I need to use 4  defun?

 

(defun c:u1 ()
(setvar "UCSFOLLOW" 1)
(command-s "._UCS" "R" "UCS_1")
(princ)
)

(defun c:u2 ()
(setvar "UCSFOLLOW" 1)
(command-s "._UCS" "R" "UCS_2")
(princ)
)

(defun c:u3 ()
(setvar "UCSFOLLOW" 1)
(command-s "._UCS" "R" "UCS_3")
(princ)
)

(defun c:u4 ()
(setvar "UCSFOLLOW" 1)
(command-s "._UCS" "R" "UCS_4")
(princ)
)

Can a "defun" be used to accomplish this?

 

We.Tanks

EESignature

A couple of Fusion improvement ideas that could your vote/support:
図面一括印刷

0 Likes
Message 8 of 16

komondormrex
Mentor
Mentor
Accepted solution

hey,

check the code to set named ucs if any. run it with "Q" then select and set appropriate named ucs with according number.

 

 

 

 

(defun c:q (/ index  ucs_collection_object active_named_ucs usc_list ucs_numbered_list initget_string getkword_string ucs_no)
	(setq ucs_collection_object (vla-get-usercoordinatesystems (vla-get-activedocument (vlax-get-acad-object)))
	      index -1
	)
  	(if (not (zerop (vla-get-count ucs_collection_object)))
		(progn
			(setvar 'ucsfollow 1)
		  	(if (vl-catch-all-error-p (vl-catch-all-apply 'vla-get-activeucs (list (vla-get-activedocument (vlax-get-acad-object)))))
				(setq active_named_ucs "")
			  	(setq active_named_ucs (vla-get-name (vla-get-activeucs (vla-get-activedocument (vlax-get-acad-object))))) 
		  	)
		  	(repeat (vla-get-count ucs_collection_object)
				(setq usc_list (append usc_list (list (vla-get-name (vla-item ucs_collection_object (setq index (1+ index)))))))  
			)
		  	(setq ucs_numbered_list (mapcar '(lambda (ucs) (strcat (itoa (1+ (vl-position ucs usc_list))) " - " ucs)) usc_list)
		  	      initget_string (apply 'strcat (mapcar '(lambda (ucs) (strcat (itoa (1+ (vl-position ucs usc_list))) " ")) usc_list))
			      getkword_string (apply 'strcat (mapcar '(lambda (ucs) (strcat ucs "/")) ucs_numbered_list))
			)  
		  	(initget initget_string)
		  	(setq ucs_no (getkword (strcat "Set UCS [" getkword_string "] <" active_named_ucs ">: ")))
		  	(vla-put-activeucs (vla-get-activedocument (vlax-get-acad-object)) (vla-item ucs_collection_object (1- (atoi ucs_no))))
		)
	  	(alert "No named UCS found")
	)
  	(princ)
)

 

Message 9 of 16

paullimapa
Mentor
Mentor
Accepted solution

this code will toggle from one to the other in sequence:

; uu toggles between ucsname ucs_1, ucs_2, ucs_3, ucs_4
; OP
; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/control-my-ucs/m-p/11899066#M446737
(defun c:uu (/ do_ucs)
 (defun do_ucs (nam)
  (if(tblsearch"UCS"nam) 
   (progn
    (setvar "UCSFOLLOW" 1)
    (command-s "._UCS" "R" nam)
   )
  )
 ) 
 (cond 
   ((= 1 (atoi(substr (getvar"ucsname") 5)))(do_ucs "UCS_2"))
   ((= 2 (atoi(substr (getvar"ucsname") 5)))(do_ucs "UCS_3"))
   ((= 3 (atoi(substr (getvar"ucsname") 5)))(do_ucs "UCS_4"))
   (t(do_ucs "UCS_1"))
 ) ; cond
 (princ(strcat"\nCurrent UCS is [" (getvar"UCSNAME") "]"))(princ)
) ; defun

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 10 of 16

WeTanks
Mentor
Mentor

Thank you for yourtime!

We.Tanks

EESignature

A couple of Fusion improvement ideas that could your vote/support:
図面一括印刷

0 Likes
Message 11 of 16

WeTanks
Mentor
Mentor

Thank you so so much.

We.Tanks

EESignature

A couple of Fusion improvement ideas that could your vote/support:
図面一括印刷

0 Likes
Message 12 of 16

paullimapa
Mentor
Mentor

you are welcome & glad to have helped...cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 13 of 16

Sea-Haven
Mentor
Mentor

i did not want to confuse you but it is possible to type UX where x is any number, the method is advanced and uses a reactor that looks at the error message when you type U4 as that is not a recognised command and pulls apart the U and the number and would then do the UCS R command, it is a good idea of checking does it exist 1st.

 

Happy to provide code but using Defun's is much easier when learning. Any way if you want to confuse your self have a look at this. It is for the fillet command with any radius.

Message 14 of 16

komondormrex
Mentor
Mentor

you are welcome)

日本語で書きませんか?

0 Likes
Message 15 of 16

Kent1Cooper
Consultant
Consultant

@paullimapa wrote:

this code will toggle from one to the other in sequence:

.... 
 (cond 
   ((= 1 (atoi(substr (getvar"ucsname") 5)))(do_ucs "UCS_2"))
   ((= 2 (atoi(substr (getvar"ucsname") 5)))(do_ucs "UCS_3"))
   ((= 3 (atoi(substr (getvar"ucsname") 5)))(do_ucs "UCS_4"))
   (t(do_ucs "UCS_1"))
 ) ; cond
....

That much can be replaced with just this, when there are 4 UCS's named that way and ending in 1 through 4:

 

(do_ucs (strcat "UCS_" (itoa (1+ (rem (substr (getvar 'ucsname) 5) 4)))))

 

Replace the 4 with whatever the actual number of them is.  Of course, either way has the limitation that UCS names need to be in that format, and the number part must go from 1 to whatever including all digits along the way, whereas I would lean toward naming them something meaningful about what they're for.  That would disallow this kind of approach with the names directly, but an association list could probably be incorporated that would let it cycle in this way even with no numerical component to the names, and including the WCS in the cycling if you want that.

 

It would also need to be adjusted if the number part might get into more than one digit.

Kent Cooper, AIA
Message 16 of 16

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:

.... an association list could probably be incorporated that would let it cycle in this way even with no numerical component to the names, and including the WCS in the cycling if you want that. ....


For example, this does that in limited testing, cycling through UCS names that are not dependent on a number component in them, and with inclusion of the WCS in the cycling:

 

(defun C:UCSC (/ UCSlist ucsn) ; = UCS Cycler
  (setq
    UCSlist '(("Peter" 0) ("Paul" 1) ("Mary" 2) ("Manny" 3) ("Moe" 4) ("Jack" 5) ("" 6)); ["" is WCS]
    ucsn (getvar 'ucsname)
  ); setq
  (command "_.ucs"); [can' use (setvar) -- it's read-only]
  (if
    (and
      (assoc ucsn UCSlist); currently one that's in the list
      (/= (setq ucsn (car (nth (rem (1+ (cadr (assoc ucsn UCSlist))) (length UCSlist)) UCSlist))) "")
    ); next one is not World [can't set that under Restore option]
    (command "_restore" ucsn); then
    (command "_world") ; else -- to WCS if next in list, or if currently not one in list
  ); if
  (prin1)
)

 

If you omit the ("" 6) entry in the list, to omit the WCS in the cycling, as currently written you must in a UCS in the list to be able to cycle through others in the list.  If desired, it could be edited to instead go into a UCS in the list [presumably to start with "Peter"] if either you're currently in the WCS or the current non-World UCS is not in the list [such as any unnamed UCS setting].  But keeping it as it is has the advantage that you can have multiple groups of UCS's, and you could make a command for cycling through each group independently of any other group(s).  It could all be in one command, if there's a User input somehow about which list to use.

 

You can add as many UCS's as you like into the list, in sublists pairing them with the next integer, or remove any as long as the remaining numbers paired with them start with 0 and increase one at a time.  Nothing else needs to be changed in the code, regardless of how many are in the list.

Kent Cooper, AIA
0 Likes