Author Topic: UCS question  (Read 1411 times)

0 Members and 1 Guest are viewing this topic.

hermanm

  • Guest
UCS question
« on: September 12, 2013, 09:30:18 PM »
classic AutoLISP:
Code: [Select]
Command: (trans '(0 0 1) 1 0 1)
(0.0 -1.0 2.22045e-016)

Q: Is there a way to do this using Active X without calling either COMMAND or vl-cmdf, assuming the current UCS is unnamed?

AX docs say:
Quote
If you try to get the active UCS value when the current UCS is unsaved, an error will occur. It is recommended that you confirm that the value of the UCSNAME system variable is not empty before you get the active UCS value. Alternatively, you can add a new UCS object and set it to active before getting the active UCS value.

Yes, I know it is possible to create a "temporary" named UCS via above methods & delete when done, but hoping to avoid that.

danallen

  • Guest
Re: UCS question
« Reply #1 on: September 12, 2013, 09:39:29 PM »
totally guessing, can you get the current UCS values from vars UCSXDIR & UCSYDIR, & UCSORG, then use conventional translation matrix rather than trans?

gile

  • Gator
  • Posts: 2520
  • Marseille, France
Re: UCS question
« Reply #2 on: September 13, 2013, 03:18:10 AM »
Hi,

AFAIK you cannot change the current UCS to an unnamed UCS with ActiveX.
You can get the current UCS matrix using the following routine:

Code: [Select]
;; gc:TMatrixFromTo
;; Returns the 4x4 transformation matrix from a Coordinates System to another one (same args as trans)
;;
;; Arguments
;; from : from  coordinates system (integer, vector or ename)
;; to : to coordinates system (integer, vector or ename)
(defun gc:TMatrixFromTo (from to)
  (append
    (mapcar
      (function
(lambda (v o)
  (append (trans v from to T) (list o))
)
      )
      (list '(1. 0. 0.) '(0. 1. 0.) '(0. 0. 1.))
      (trans '(0 0 0) to from)
    )
    (list '(0. 0. 0. 1.))
  )
)

To get the current UCS transformation matrix:
Code: [Select]
(gc:TMatrixFromTo 0 1)
To tranform an entity (vla-object) from WCS to current UCS:
Code: [Select]
(vla-TransformBy ent (vlax-tmatrix (gc:TMatrixFromTo 0 1)))
Speaking English as a French Frog

Lee Mac

  • Seagull
  • Posts: 12924
  • London, England
Re: UCS question
« Reply #3 on: September 13, 2013, 06:20:04 AM »
Minor question gile, why use:
Code: [Select]
(list '(1. 0. 0.) '(0. 1. 0.) '(0. 0. 1.))and:
Code: [Select]
(list '(0. 0. 0. 1.))instead of the more efficient literals?:
Code: [Select]
'(
     (1.0 0.0 0.0)
     (0.0 1.0 0.0)
     (0.0 0.0 1.0)
 )
Code: [Select]
'((0.0 0.0 0.0 1.0))

gile

  • Gator
  • Posts: 2520
  • Marseille, France
Re: UCS question
« Reply #4 on: September 13, 2013, 06:35:15 AM »
You're right Lee.
This is a quite old code from my libraries I copied without looking deeply.
Anyway, I don't think the efficiency difference is so great.
Speaking English as a French Frog

Lee Mac

  • Seagull
  • Posts: 12924
  • London, England
Re: UCS question
« Reply #5 on: September 13, 2013, 07:05:25 AM »
No worries gile :-)