Author Topic: UCS vs WCS with ActiveX  (Read 3521 times)

0 Members and 1 Guest are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
UCS vs WCS with ActiveX
« on: May 16, 2006, 08:38:49 PM »
I've been putting together some samples as part of lessons I'm giving, so I thought I'd share this bit, cause the use of WCS and UCS  can get confusing when comparing command use and ActiveX use.


Code: [Select]
(DEFUN c:testucs ()      ; vars left global for testing demonstration
  ;;
  ;; Force the UCS to World in Plan
  ;;
  (VL-CMDF "ucs" "World")
  (VL-CMDF "Plan" "World")
  ;;
  ;; Change the UCS
  ;;
  (SETQ point_in_wcs (LIST 200.0 300.0 0.0))
  (VL-CMDF "ucs" "New" point_in_wcs)
  (VL-CMDF "Zoom" "C" (LIST 0 0 0) 3000)
  ;;
  (SETQ zerozero_in_ucs (LIST 0.0 0.0 0.0))
  ;;
  ;; Draw circle 1 < relative to the Current UCS >
  ;;
  (VL-CMDF "CIRCLE" zerozero_in_ucs 100.0)
  (VL-CMDF "CHPROP" (ENTLAST) "" "CO" ACRED "")
  (SETQ ;;
        ;; Collect the DXF Data
        ;;
        circle_ent        (ENTLAST)
        circle_data       (ENTGET (ENTLAST))
        circle_dxf_center (CDR (ASSOC 10 circle_data))
        ;;
        ;; collect the ActiveX Data
        ;;
        circle_obj        (VLAX-ENAME->VLA-OBJECT circle_ent)
        circle_obj_center (VLAX-GET circle_obj 'center)
  )
  ;;
  ;; Draw circle 2 < relative to the WCS >
  ;;
  (SETQ ax_circle_obj        (VLA-ADDCIRCLE
                               (VLA-GET-MODELSPACE
                                 (VLA-GET-ACTIVEDOCUMENT
                                   (VLAX-GET-ACAD-OBJECT)
                               ))
                               (VLAX-3D-POINT (LIST 0.0 0.0 0.0))
                               200.0
                             )
        ax_circle_data       (ENTGET (ENTLAST))
        ax_circle_dxf_center (CDR (ASSOC 10 ax_circle_data))
        ax_circle_obj_center (VLAX-GET ax_circle_obj 'center)
  )
  (VLA-PUT-COLOR ax_circle_obj ACGREEN)
  (VLA-REGEN (VLA-GET-ACTIVEDOCUMENT (VLAX-GET-ACAD-OBJECT)) ACACTIVEVIEWPORT)
  ;;
  (ALERT (STRCAT "UCS Origin in World = "
                 (VL-PRIN1-TO-STRING (GETVAR "UCSORG"))
                 "\n -- Circle 1 with COMMAND draws at 0,0,0 --  \n"
                 "Circle 1 Center Drawn In UCS = "
                 (VL-PRIN1-TO-STRING zerozero_in_ucs)
                 "\n"
                 "Circle 1 Dxf Center     = "
                 (VL-PRIN1-TO-STRING circle_dxf_center)
                 "\n"
                 "Circle 1 ActiveX Center = "
                 (VL-PRIN1-TO-STRING circle_obj_center)
                 "\n-----------------------------\n"
                 "\n -- Circle 2 with ActiveX draws at 0,0,0 --  \n"
                 "Circle 2 Dxf Center     = "
                 (VL-PRIN1-TO-STRING ax_circle_dxf_center)
                 "\n"
                 "Circle 2 ActiveX Center = "
                 (VL-PRIN1-TO-STRING ax_circle_obj_center)
         )
  )
  (PRINC)
)

« Last Edit: May 16, 2006, 08:53:38 PM 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: UCS vs WCS with ActiveX
« Reply #1 on: May 16, 2006, 09:10:30 PM »
and this follows ..
Code: [Select]
;;;---------------------------------------------------------------------------------
(GETVAR "UCSORG")
;;-> (200.0 300.0 0.0)

(SETQ Selected_point_in_UCS (getpoint "\nSelect Point :"))
;;-> returns point in the current UCS
;;-> (-200.0 -300.0 0.0)

(setq Selected_point_Translated_to_WCS (trans Selected_point_in_UCS acUCS acWorld))
;;-> Translate the selected point from the current UCS to WCS
;;-> (0.0 0.0 0.0)
;;;---------------------------------------------------------------------------------
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.

Joe Burke

  • Guest
Re: UCS vs WCS with ActiveX
« Reply #2 on: May 18, 2006, 07:23:48 AM »
Kerry,

These might be of interest.

Code: [Select]
;; Doug C. Broad, Jr.
;; can be used with vla-transformby to
;; transform objects from the UCS to the WCS
(defun UCS2WCSMatrix ()
  (vlax-tmatrix
    (append
      (mapcar
        '(lambda (vector origin)
          (append (trans vector 1 0 t) (list origin))
         )
         (list '(1 0 0) '(0 1 0) '(0 0 1))
         (trans '(0 0 0) 0 1)
      )
      (list '(0 0 0 1))
    )
  )
)
;; transform objects from the WCS to the UCS
(defun WCS2UCSMatrix ()
  (vlax-tmatrix
    (append
      (mapcar
        '(lambda (vector origin)
          (append (trans vector 0 1 t) (list origin))
         )
         (list '(1 0 0) '(0 1 0) '(0 0 1))
         (trans '(0 0 0) 1 0)
      )
      (list '(0 0 0 1))
    )
  )
)
;; Example: transform an object from the current UCS to
;; WCS. Note, UCS that the objects is drawn in must
;; be current for this to work as expected.
; (defun c:test (/ ent obj)
;   (setq ent (car (entsel))
;         obj (vlax-ename->vla-object ent))
;   (vla-transformby obj (ucs2wcsmatrix))
;   (vla-update obj)
; )

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: UCS vs WCS with ActiveX
« Reply #3 on: May 18, 2006, 08:07:21 AM »
Absolutely of interest Joe, I use similar functionality myself.
That's probably a little above the level I'm teaching to at the moment, but definately worth serious study, by anyone.

Thanks Joe.
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.

Joe Burke

  • Guest
Re: UCS vs WCS with ActiveX
« Reply #4 on: May 18, 2006, 11:08:27 AM »
Kerry,

You're welcome.

Maybe off-topic a bit, but I'm often impressed with how the TransformBy method can be used.

Example, bear wtih me whiile I explain. I was recently given a set of architectural drawings done by another firm. The site plan contained xrefs to multiple buildings. Unlike what you'd expect, the xrefs of the buildings were not inserted at 0,0 and they were rotated. IOW, the site plan looked right, but the data contained in the source building xrefs had not been changed. Basically, someone applied a band-aide. Not the proper fix which involves moving and rotating the data in many xref floor plans. Which also happen to contain nested/attached xrefs.

Given this mess my solution was something like this.

Code: [Select]
(defun c:GetMatrix ( / elst)
  (while
    (not (setq elst (nentselp "\nSelect object in primary block: ")))
  )
  (print (vlax-get (vlax-ename->vla-object (last (last elst))) 'Name))
  (vl-bb-set '%matrix% (caddr elst))
  (princ)
) ;end

;------------------------------------
;shortcut
(defun c:GM () (c:GetMatrix))
;------------------------------------

(defun c:ApplyMatrixModelSpace ( / matrix tmat)
  (if
    (and
      (setq matrix (vl-bb-ref '%matrix%))
      (setq tmat (vlax-tmatrix matrix))
    )
    (vlax-for x *mspace*
      (vla-transformby x tmat)
    )
  )
  (princ)
) ;end

;------------------------------------
;shortcut - apply matrix to model space
(defun c:AMM () (c:ApplyMatrixModelSpace))
;------------------------------------

(defun c:ApplyMatrixSS ( / matrix tmat lst)
  (if
    (and
      (setq matrix (vl-bb-ref '%matrix%))
      (setq tmat (vlax-tmatrix matrix))
      (setq lst (SSVLAList (ssget)))
    )
    (foreach x lst
      (vla-transformby x tmat)
    )
  )
  (princ)
) ;end

;------------------------------------
;shortcut - apply matrix to selecton set
(defun c:AMS () (c:ApplyMatrixSS))
;------------------------------------

Given those functions, I was able to derive the transformation matrix from the site plan for each building. Then open each of the floor plans and transform the objects with one function, either all in model space, or by selection. That distinction because the sheet files which contained notes and dimensions could also be fixed in a similar fashion using the same matrix.

The alternative, standard methods, would have been time consuming and error prone.






EDIT: Sorry, Joe, just took your trailing comments out of the code tags
« Last Edit: May 18, 2006, 11:48:39 AM by nivuahc »

nivuahc

  • Guest
Re: UCS vs WCS with ActiveX
« Reply #5 on: May 18, 2006, 11:49:31 AM »
Thanks to both of you for posting this. It's been quite eye opening and educational. For me, at least. :)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: UCS vs WCS with ActiveX
« Reply #6 on: May 18, 2006, 05:16:42 PM »
Interesting use of the blackboard Joe. .. nice.
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.

Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Re: UCS vs WCS with ActiveX
« Reply #7 on: May 18, 2006, 07:50:47 PM »
Just when I think the coast is clear and I won't have to learn something new today....then I read this thread. Thanks Kerry, Joe, and by association Doug B.

Transformations have been one of my weak points and this discussion had gotten that light up there a tad brighter. I've bookmarked this for future reference.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: UCS vs WCS with ActiveX
« Reply #8 on: May 18, 2006, 08:18:40 PM »
hehehe

unusual day for me to post something new to Jeff ..   :wink:
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.