TheSwamp

Code Red => VB(A) => Topic started by: Keith™ on January 05, 2007, 09:06:42 PM

Title: Creating a new UCS from a supplied set of point in WCS
Post by: Keith™ on January 05, 2007, 09:06:42 PM
Ok ... I must admit I am stumped ...

UserCoordinateSystems.Add takes 4 parameters, the origin, xAxis normal, yAxis normal, and UCS name ...

Now ... when I am running the sample code on AutoCAD 2000 with a supplied set of points, I am greeted with a new ucs ... however in all other versions I receive an error that the Y axis is not parallel to the Z axis ....

In the sample code the axis is specified by 1,1,0 and -1,1,0 respecively .. this works fine ... but no matter what I do, I cannot create a UCS using a supplied set of points.
Title: Re: Creating a new UCS from a supplied set of point in WCS
Post by: Kerry on January 05, 2007, 09:22:57 PM
would that be 'cause the parameters are vectors, not points ..
Title: Re: Creating a new UCS from a supplied set of point in WCS
Post by: Bryco on January 05, 2007, 11:08:55 PM
Most Ucs problems are caused by the Origin. You must make the the Ucs then set the origin. That is the origin is 0,0,0 set the ucs  then change the origin
Title: Re: Creating a new UCS from a supplied set of point in WCS
Post by: Kerry on January 05, 2007, 11:13:04 PM
Here's how I calc the vector from 2 points in VLisp

Simply deduct the origin from the target .. I'll leave the VBA translation to you.

Code: [Select]
(defun KDUB:VEC:points->vector (3dPt1 3dPt2) (mapcar '- 3dPt2 3dPt1))
 
Title: Re: Creating a new UCS from a supplied set of point in WCS
Post by: Chuck Gabriel on January 05, 2007, 11:14:20 PM
So something like this:

Code: [Select]
Dim wcs As AcadUCS
Dim origin(2) As Double, xVector(2) As Double, yVector(2) As Double
origin(0) = 0: origin(1) = 0: origin(2) = 0
xVector(0) = 1: xVector(1) = 0: xVector(2) = 0
yVector(0) = 0: yVector(1) = 1: yVector(2) = 0
Set wcs = ThisDrawing.UserCoordinateSystems.Add(origin, xVector, yVector, "WCS")

will work in AutoCAD 2000 but not in any later version?
Title: Re: Creating a new UCS from a supplied set of point in WCS
Post by: Bryco on January 05, 2007, 11:41:18 PM
Sub u()
Dim wcs As AcadUCS
Dim origin(2) As Double, xVector(2) As Double, yVector(2) As Double
origin(0) = 5: origin(1) = 7: origin(2) = 0
xVector(0) = 1: xVector(1) = 1: xVector(2) = 0
yVector(0) = -1: yVector(1) = 1: yVector(2) = 0
Set wcs = ThisDrawing.UserCoordinateSystems.Add(origin, xVector, yVector, "WCS")
End Sub
This errors  where as Chuck's wont.
Title: Re: Creating a new UCS from a supplied set of point in WCS
Post by: Kerry on January 05, 2007, 11:52:08 PM
Bryco, I recall the same issue with VLisp ActiveX

... resulted in this ..

Code - Auto/Visual Lisp: [Select]
  1. ;;
  2. ;;;-------------------------------------------------------------
  3. ;;;-------------------------------------------------------------
  4. ;;
  5. (defun KDUB:UCS:BlackBox (NewUcsName Origin XAxis YAxis Activate / objUCS)
  6.   ;;
  7.   ;;    by Kerry Brown  2004.Feb.11
  8.   ;;    Revised kwb  2005.Jul.02
  9.   ;;    Create a Named UCS and Optionally Activate it.
  10.   ;|
  11. Required globals                        : g:activedoc, g:ucss
  12. Required dependancies : nil
  13. Parameters  :-
  14.         NewUcsName      :<string>
  15.         Origin                  :<PointList (X Y Z)>                   
  16.         XAxis                           :<VectorList (X Y Z)>
  17.         YAxis                           :<VectorList (X Y Z)>
  18.         Activate                :<nil or NonNil> Set as ActiveUCS
  19.  
  20. Returns : <VLA-OBJECT IAcadUCS ....>  or nil.
  21.  
  22. |;
  23. ;;;;----------------
  24.   (or NewUcsName (setq NewUcsName "TempUCS"))
  25.   (or Origin (setq Origin (getvar "ucsorg")))
  26.   (or XAxis (setq XAxis (getvar "ucsxdir")))
  27.   (or YAxis (setq YAxis (getvar "ucsydir")))
  28.   ;;
  29.   (setq objUCS (vla-add (kdub:iacaducss)
  30.                         (vlax-3d-point '(0.0 0.0 0.0)) ;origin
  31.                         (vlax-3d-point XAxis)          ;x-axis
  32.                         (vlax-3d-point YAxis)          ;y-axis
  33.                         NewUcsName
  34.                )
  35.   )
  36.   (vla-put-origin objUCS (vlax-3d-point Origin))
  37.   (if Activate
  38.     (vla-put-activeucs (kdub:iacaddocument) objUCS)
  39.   )
  40.   objUCS
  41. )
  42. ;;
  43. ;;;-------------------------------------------------------------
  44. ;;;-------------------------------------------------------------

referenced from http://www.theswamp.org/index.php?topic=5794.0
Title: Re: Creating a new UCS from a supplied set of point in WCS
Post by: Bryco on January 06, 2007, 12:02:30 AM
If I read that right, Origin last.
Kerry that's interesting as I thought it was a vba problem, namely vba being a bit hows your father on the doubles, but now you have shown it to be all over.
Title: Re: Creating a new UCS from a supplied set of point in WCS
Post by: Kerry on January 06, 2007, 12:34:28 AM
Yes Bryco, Origin last ; it's a condition of using ActiveX .. just the way the methods work.