trans help please?

Discussion in 'AutoCAD' started by rgrainer, Apr 6, 2005.

  1. rgrainer

    rgrainer Guest

    Hi all

    When i have a block inserted at 0,0,0 in paperspace, the function below will
    return the correct value for "stpoint". However if I move the block from
    0,0,0 I get incorrect results. I have looked at the help files for the trans
    function and they mention integer codes of 2 and 3 ....but I am unable to
    get anywhere with it. if anyone could throw me a pointer....Thanks

    Richard

    ;;;(defun c:doya ( / ent einfo stpoint endpoint)

    (defun c:doya ( )

    (setq ent (nentsel "\n Select Entity to copy:" ) )

    (setq einfo (entget (car ent))

    etype (cdr (assoc 0 einfo))

    stpoint (trans (cdr (assoc 10 einfo))0 1)

    endpoint (trans (cdr (assoc 11 einfo))0 1)

    )

    (princ stpoint)

    (princ)

    )
     
    rgrainer, Apr 6, 2005
    #1
  2. rgrainer

    Joe Burke Guest

    Richard,

    How to deal with this depends... For instance, if the block containing the line is
    only moved, and not rotated or scaled, that's one thing. Another consideration is
    whether the line is nested just one level deep in the block. IOW, it's not nested in
    a block inside the primary block.

    If those conditions apply to your situation, then what you want to do is add the
    block's insertion point to the start or end point returned. What you need to find is
    the block's insertion point. Nentsel returns something like this with a block.

    Command: (setq lst (nentsel))
    Select object: (<Entity name: 7ef70bb8> (-543.304 -327.199 0.0) ((1.0 0.0 0.0)
    (0.0 1.0 0.0) (0.0 0.0 1.0) (-817.293 -472.483 0.0)) (<Entity name: 7ef70c08>))

    Get the line start point in OCS coordinates:
    Command: (setq stpoint (cdr (assoc 10 (entget (car lst)))))
    (119.126 119.085 0.0)

    Get the block ename:
    Command: (setq blk (last (last lst)))
    <Entity name: 7ef70c08>

    Get the block insertion point:
    Command: (setq inspt (cdr (assoc 10 (entget blk))))
    (-817.293 -472.483 0.0)

    The start point transposed to WCS:
    Command: (setq pt (mapcar '+ stpoint inspt))
    (-698.168 -353.398 0.0)

    Now if the block is moved and also rotated and/or scaled, you'd want a function to
    deal with that. I'll post if you need it.

    HTH,
    Joe Burke
     
    Joe Burke, Apr 6, 2005
    #2
  3. rgrainer

    Richard Guest

    thanks Joe
    I had actually thought of the addition or subtraction of the insert point,
    but was hoping that I didn't want to/have to go there. Thanks again for your
    help
    Richard
     
    Richard, Apr 6, 2005
    #3
  4. Are you the one I know?.... from LA in one presentation I did related about
    vlisp reactors?

    LE.
     
    Luis Esquivel, Apr 6, 2005
    #4
  5. rgrainer

    rgrainer Guest

    Hi Luis
    Yes I am he (in both post Richard & rgrainer) from the presentation in LA
    how are you?...I've seen some of your posts from time to time.
    I have relocated jobs recently. I hope is all is well with you and your
    family
    Richard
     
    rgrainer, Apr 7, 2005
    #5
  6. Hi,

    Glad to see you here....

    Everything is just fine... doing the same, are you still in LA?

    I'm going to sent to you a module I did for transformations, so you can give it a try.... Joe and James have done also their own approach's, so maybe tomorrow you will get more help on this.

    What is your e-mail?

    Good night,
    Luis.
     
    Luis Esquivel, Apr 7, 2005
    #6
  7. rgrainer

    rgrainer Guest

    Wow
    thanks so much. yes still in LA. I have a sheet that is a block (not 0,0,0)
    and I want to be able to offset a line after reading a line entity from the
    block.
    that's what this whole thing is about. Joes idea was good I was just hoping
    for an easier way.
    my email is rgrainer@sbc nospam= global=.net
    (just take out the npspam and equals sign)
    Good Night

    give it a try.... Joe and James have done also their own approach's, so
    maybe tomorrow you will get more help on this.
     
    rgrainer, Apr 7, 2005
    #7
  8. rgrainer

    Joe Burke Guest

    Richard,

    You're welcome.

    I might as well post this since you might need it. Or maybe you'll find it easier
    with these as toolbox functions.

    The @PTrans function deals with the fact the block may be rotated and/or scaled, as
    well as moved. The nested block consideration still applies.

    Regarding, "thought of the addition or subtraction..." it's always addition going
    from OCS to WCS.

    Joe Burke

    Code:
    ;; Function based on Doug Wilson's Transpose function
    ;; to convert a 4x3 matrix from (nentsel)
    ;; to a 4x4 matrix from (nentselp)
    ;; (c)2002, John F. Uhden, Cadlantic (05-18-02)
    (defun 4x3->4x4 (matrix)
    (append (apply 'mapcar (cons 'list matrix))'((0.0 0.0 0.0 1.0)))
    )
    
    ;; Function to transform a point from either:
    ;;   the MCS of an entity selected by (nentsel), or
    ;;   the OCS of an entity selected by (nentselp)
    ;;   to the WCS.
    ;; Given:
    ;;   P = point to transform (list of 3 reals)
    ;;   M = transormation matrix:
    ;;       either 4x3 as returned by (nentsel)
    ;;       or 4x4 as returned by (nentselp)
    ;; (c)2003, John F. Uhden, Cadlantic (08-03-03)
    (defun @PTrans (P M)
    (if (= (length P) 2)
    (setq P (append P '(0.0 1.0)))
    (setq P (append P '(1.0)))
    )
    (if (= (length (car M)) 3)
    (setq M (4x3->4x4 M))
    )
    (mapcar
    (function (lambda (x)(apply '+ x)))
    (list (mapcar '* P (car M))
    (mapcar '* P (cadr M))
    (mapcar '* P (caddr M))
    )
    )
    )
    
     
    Joe Burke, Apr 7, 2005
    #8
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.