Strange Error when creating New UCS with vla-add

Discussion in 'AutoCAD' started by Alexander V. Koshman, May 16, 2004.

  1. Hello to NG!
    ----------------
    Do anybody have a time and wish to help me? ; )

    I have a problem creating a new UCS via (vla-add ...).
    I want to Copy the current Ucs to the New Named Ucs (e.g. to save it)
    and my question is:

    Why I get this Error in case of current UCS was created with
    [UCS \ New \ 3point]
    and these points are picked by the user (maybe with a snap maybe with
    an object snap)?

    "Automation Error. UCS X axis and Y axis are not perpendicular"

    There is no error if the current UCS was Ortho Ucs or it was created with
    [UCS \ New \ 3point]
    and these points (or directions) was specified like
    (list 0.0 0.0 0.0) (list 1.0 0.0 0.0) (list 0.0 0.0 1.0) ?



    (defun CopyUCS ( / acad doc ucss prevUcs prevOriginPt prevXDir prevYdir
    newUcs )
    ;; **********************************************************
    (setq acad (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acad))
    (setq ucss (vla-get-UserCoordinateSystems doc))
    ;; **********************************************************

    ;; --------------------------------------------------------------------
    ;; Get Properties of Current UCS
    ;; --------------------------------------------------------------------
    (setq prevUcs (vlax-get-property doc 'ActiveUCS))
    (setq prevOriginPt (vlax-get-property prevUcs 'Origin))
    (setq prevXDir (vlax-get-property prevUcs 'XVector))
    (setq prevYDir (vlax-get-property prevUcs 'YVector))
    ;; --------------------------------------------------------------------

    ;; --------------------------------------------------------------------
    ;; SAVES Current UCS Settings
    ;; --------------------------------------------------------------------
    (setq newUcs (vla-add ucss prevOriginPt prevXDir prevYDir "NEW_UCS"))
    ;; --------------------------------------------------------------------

    (princ "\nNew UCS created!")

    ;; **********************************************************
    (vlax-release-object acad)
    (vlax-release-object doc)
    (vlax-release-object ucss)
    (vlax-release-object newUcs)
    ;; **********************************************************
    (princ)
    ) ; - 'defun CopyUCS'
     
    Alexander V. Koshman, May 16, 2004
    #1
  2. Sorry for missing signature!

    It was
    Alexander V. Koshman
    : )
     
    Alexander V. Koshman, May 16, 2004
    #2
  3. Rounding errors crop up far too often with this. That is what causes the
    error.

    --
    R. Robert Bell


    Hello to NG!
    ----------------
    Do anybody have a time and wish to help me? ; )

    I have a problem creating a new UCS via (vla-add ...).
    I want to Copy the current Ucs to the New Named Ucs (e.g. to save it)
    and my question is:

    Why I get this Error in case of current UCS was created with
    [UCS \ New \ 3point]
    and these points are picked by the user (maybe with a snap maybe with
    an object snap)?

    "Automation Error. UCS X axis and Y axis are not perpendicular"

    There is no error if the current UCS was Ortho Ucs or it was created with
    [UCS \ New \ 3point]
    and these points (or directions) was specified like
    (list 0.0 0.0 0.0) (list 1.0 0.0 0.0) (list 0.0 0.0 1.0) ?



    (defun CopyUCS ( / acad doc ucss prevUcs prevOriginPt prevXDir prevYdir
    newUcs )
    ;; **********************************************************
    (setq acad (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acad))
    (setq ucss (vla-get-UserCoordinateSystems doc))
    ;; **********************************************************

    ;; --------------------------------------------------------------------
    ;; Get Properties of Current UCS
    ;; --------------------------------------------------------------------
    (setq prevUcs (vlax-get-property doc 'ActiveUCS))
    (setq prevOriginPt (vlax-get-property prevUcs 'Origin))
    (setq prevXDir (vlax-get-property prevUcs 'XVector))
    (setq prevYDir (vlax-get-property prevUcs 'YVector))
    ;; --------------------------------------------------------------------

    ;; --------------------------------------------------------------------
    ;; SAVES Current UCS Settings
    ;; --------------------------------------------------------------------
    (setq newUcs (vla-add ucss prevOriginPt prevXDir prevYDir "NEW_UCS"))
    ;; --------------------------------------------------------------------

    (princ "\nNew UCS created!")

    ;; **********************************************************
    (vlax-release-object acad)
    (vlax-release-object doc)
    (vlax-release-object ucss)
    (vlax-release-object newUcs)
    ;; **********************************************************
    (princ)
    ) ; - 'defun CopyUCS'
     
    R. Robert Bell, May 17, 2004
    #3
  4. Alexander V. Koshman

    Jeff Mishler Guest

    I've found you must first create the new UCS at origin of 0 0 0 then change
    the origin to where you really want it.

    HTH,
    Jeff
     
    Jeff Mishler, May 17, 2004
    #4
  5. Hello Robert!
    ---------------
    I think so and I tested with (rtos (car (...)) 2 16) and the result was
    1.000000000000000 without any deviations.

    What have I do to get round this rounding problem? ; )

    Maybe VL precision is more than 16 digits???

    Thank you!
     
    Alexander V. Koshman, May 17, 2004
    #5
  6. Alexander V. Koshman

    Jeff Mishler Guest

    Let me a little less cryptic...... this will not work and give the error you
    describe (x is the elist of an existing UCS)
    (setq newucs
    (vla-add ucss (vlax-3d-point (cdr (assoc 10 x)))
    (vlax-3d-point (cdr (assoc 11 x)))
    (vlax-3d-point (cdr (assoc 12 x)))
    "MyUCS"
    )

    Yet this DOES work:
    (setq newucs
    (vla-add ucss (vlax-3d-point '(0.0 0.0 0.0))
    (vlax-3d-point (cdr (assoc 11 x)))
    (vlax-3d-point (cdr (assoc 12 x)))
    "MyUCS"
    )
    (vla-put-origin newucs (vlax-3d-point (cdr (assoc 10 x))))

    HTH,
    Jeff


     
    Jeff Mishler, May 17, 2004
    #6
  7. Oh my God!
    ----------------
    Jeff! You're a genius!
    WHY does it works??? ; )

    One little problem: I don't want AutoCAD to create a new
    "_ActiveNN" Ucs while creating *My* Named Ucs via (vla-add ...)!
    Do you have some ideas???

    Thank you!!!
     
    Alexander V. Koshman, May 18, 2004
    #7
  8. Jeff!
    -------------
    Another question!

    Do you know a way to create an Unnamed Ucs (just
    UCS\ command with \3 or \Origin or \Move options
    does)?
    I don't want to make a new Named Ucs each time?
     
    Alexander V. Koshman, May 18, 2004
    #8
  9. Why don't you just delete the undesired named UCS when you are done with it?

    --
    R. Robert Bell


    Jeff!
    -------------
    Another question!

    Do you know a way to create an Unnamed Ucs (just
    UCS\ command with \3 or \Origin or \Move options
    does)?
    I don't want to make a new Named Ucs each time?
     
    R. Robert Bell, May 18, 2004
    #9
  10. Alexander V. Koshman

    Doug Broad Guest

    Hi Alexander,
    If you look at the arguments to the vla-add operation, it
    takes 3 points: origin, xaxispoint, and yaxispoint. The
    properties saved, however, are origin, xvector, and yvector.

    xvector isn't the same as xaxispoint and
    yvector isn't the same as yaxispoint

    A vector is a direction is a direction from the origin (0 0 0 )
    not from the ucs origin. Jeff's method works fine (nice Jeff) because
    it creates a WCS centered origin with the correct xy directions
    and then moves the origin.

    Remember also that unless an activeucs exists, the call
    to (vla-get-activeucs...) will return Automation Error: Null Object

    If you don't mind command methods, the ucs command can
    create a new unnamed coordinate system. Or you could
    do as Robert suggested (which sounds good).


    Regards,
    Doug
     
    Doug Broad, May 18, 2004
    #10
  11. Hello Doug! Hello Robert!
    -----------------------------
    COOL!!! You're a very attentive person! ; )
    Hey Jeff! Where are you? Have you heard that?
    I want to use this inside of reactors and I know I can't use
    commands?

    Thank you!
    You saved me guys!
     
    Alexander V. Koshman, May 19, 2004
    #11
  12. Alexander V. Koshman

    Jeff Mishler Guest

    Hi Alexander,
    I've been checking in occassionally and I see Doug has explained the "Why"
    of my workaround.
    As for an unnamed UCS, I would think it would be hard to work with,
    (vla-put-activeucs *doc* "")....with many unnamned UCS's what would one use
    in the quotes? I think Robert said it best, just delete the new named UCS
    when you are done with it.

    You're welcome!
    Jeff
     
    Jeff Mishler, May 19, 2004
    #12
  13. Jeff!
    ------
    I want to make a temporary Ucs and don't want to give it any name.
    And
    (setq newUcs (vla-add ucss Origin XDir YDir ""))
    doesn't work with [""] as [NoName]!

    I want simply to save the current Unnamed (probably) Ucs BEFORE
    and restore it AFTER "3DORBIT" command and have the WCS during
    "3DORBIT"!

    And there's no sense to give a name to the Ucs that I will never use after
    "3DORBIT" ends!
    Now I have to make an "WCS3DORBIT_UCS" temporary Ucs before and
    make it active at the end of "3DORBIT"!
    And then I can't delete it because IT IS ACTIVE now!

    What do you think?
     
    Alexander V. Koshman, May 19, 2004
    #13
  14. Alex,

    It gets worse... there may be a non-WCS that is active, yet ActiveX will not
    have anything in the ActiveUCS property. So you are pretty much stuck
    reading the system variables and recreating the UCS afterwards, which makes
    those "active..." named UCS's. It is a mess.

    The command pipeline (shudder) almost makes better sense, sorry to say.

    --
    R. Robert Bell


    Jeff!
    ------
    I want to make a temporary Ucs and don't want to give it any name.
    And
    (setq newUcs (vla-add ucss Origin XDir YDir ""))
    doesn't work with [""] as [NoName]!

    I want simply to save the current Unnamed (probably) Ucs BEFORE
    and restore it AFTER "3DORBIT" command and have the WCS during
    "3DORBIT"!

    And there's no sense to give a name to the Ucs that I will never use after
    "3DORBIT" ends!
    Now I have to make an "WCS3DORBIT_UCS" temporary Ucs before and
    make it active at the end of "3DORBIT"!
    And then I can't delete it because IT IS ACTIVE now!
     
    R. Robert Bell, May 19, 2004
    #14
  15. Good Monday Robert! ; )
    ----------------------------
    Sorry for delay!
    I had absolutely no time to check my post these last days!
    Thank for this idea!
    And I think I can rename this "_Active..." Ucs AFTER AutoCAD makes it?
    And I really can't use it in reactors, I'm right?

    I will try!
     
    Alexander V. Koshman, May 23, 2004
    #15
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.