how to get that 4x4 matrix

Discussion in 'AutoCAD' started by Joe Burke, Apr 3, 2004.

  1. Joe Burke

    Joe Burke Guest

    I guess there will be an easy answer to this, or rocket science. I can't figure out,
    or I've forgotten, how to find the 4x4 matrix associated with an xref block using
    nentselp, when the object picked is an insert nested in the xref.

    Example - pick an object that's not a nested insert in an xref:
    Command: (nentselp)
    Select object: (<Entity name: 409b81c8> (1385.52 346.645 0.0) ((1.0 0.0 0.0
    0.0) (0.0 1.0 0.0 0.0) (0.0 0.0 1.0 0.0) (0.0 0.0 0.0 1.0)) (<Entity name:
    416d6138>))

    That's the xref matrix, which is what I want. The xref hasn't been moved, scaled or
    rotated.

    Example - pick a nested insert in the same xref:
    Command: (nentselp)
    Select object: (<Entity name: 40991c08> (1050.82 111.489 0.0) ((48.0 0.0 0.0
    170.311) (0.0 48.0 0.0 110.434) (0.0 0.0 48.0 0.0) (0.0 0.0 0.0 1.0)) (<Entity
    name: 40991cd8> <Entity name: 416d6138>))

    That's the nested insert matrix, which is of no interest in this case.

    So is there some trick to get the xref matrix? I don't see how given a single pick
    since nentselp is the only function which returns a 4x4 matrix. BTW, I intend to use
    the matrix with vlax-tmatrix and the TransformBy method.

    My other thought, there's probably a way to build the xref matrix given the
    information contained in (last (last elst)) above. IOW, simply do what nentselp does
    (calculate the matrix) by passing an ename or vla-object to some function. I've never
    seen such a function, though the idea reminds me of Doug Broad's UCS2WCSMatrix and
    WCS2UCSMatrix functions. Thanks for those, Doug.

    I've Goggled this question. If I found the answer, either I didn't recognize it, or
    the matrix math was over my head. Fingers crossed... I'm not just being flat out
    stupid.

    Thanks for any advice.
    Joe Burke
     
    Joe Burke, Apr 3, 2004
    #1
  2. Joe Burke

    Joe Burke Guest

    Here's my attempt at passing a vla-object to some function and return a 4x4 matrix.
    Within context, it assumes the vla-object passed is a primary insert object. Might be
    an xref, or just a block.

    With thanks to Bobby Jones for his example regarding use of Vlad's functions.

    ;; Apply a transformation matrix to a vector by Vladimir Nesterovsky
    (defun mxv (m v)
    (mapcar '(lambda (row) (apply '+ (mapcar '* row v))) m)
    ) ;end

    ;; Multiply two matrices by Vladimir Nesterovsky
    (defun mxm (m q / qt)
    (setq qt (apply 'mapcar (cons 'list q)))
    (mapcar '(lambda (mrow) (mxv qt mrow)) m)
    ) ;end

    ;; argument: primary (not nested) insert vla-object
    ;; returns: 4x4 transformation list like nentselp
    ;; example use: (vla-transformby <vla-object> (vlax-tmatrix resmatrix))
    (defun ObjMatrix ( vobj / ang inspt xsf ysf zxf
    sclmatrix rotmatrix movmatrix ) ;resmatrix
    (setq ang (vlax-get vobj 'Rotation))
    (setq inspt (vlax-get vobj 'InsertionPoint))
    (setq xsf (vlax-get vobj 'XScaleFactor))
    (setq ysf (vlax-get vobj 'YScaleFactor))
    (setq zsf (vlax-get vobj 'ZScaleFactor))
    (setq sclmatrix
    (list
    (list xsf 0 0 0)
    (list 0 ysf 0 0)
    (list 0 0 zsf 0)
    (list 0 0 0 1)
    )
    )
    (setq rotmatrix
    (list
    (list (cos ang) (- (sin ang)) 0 0)
    (list (sin ang) (cos ang) 0 0)
    (list 0 0 1 0)
    (list 0 0 0 1)
    )
    )
    (setq movmatrix
    (list
    (list 1 0 0 (car inspt))
    (list 0 1 0 (cadr inspt))
    (list 0 0 1 (caddr inspt))
    (list 0 0 0 1)
    )
    )
    (setq resmatrix (mxm movmatrix (mxm sclmatrix rotmatrix)))
    ) ;end

    Command: (ObjMatrix (e2v)) ;e2v returns a vla-object picked
    Select object: ((0.34202 -0.939693 0.0 75.0293) (0.939693 0.34202 0.0
    146.373) (0.0 0.0 1.0 0.0) (0.0 0.0 0.0 1.0))

    Command: (caddr (nentselp))
    Select object: ((0.34202 -0.939693 0.0 75.0293) (0.939693 0.34202 0.0
    146.373) (0.0 0.0 1.0 0.0) (0.0 0.0 0.0 1.0))

    Joe Burke
     
    Joe Burke, Apr 4, 2004
    #2
  3. Joe Burke

    John Uhden Guest

    Joe:

    Are you playing with that XCOPY thingy we were working on? I ran into a
    parallel (if not the same) problem that (nentselp) returns the transformation
    matrix for the entity inside a block insertion inside the xref, but I haven't
    figured out how to transform the nested block insertion itself. I'll trade you,
    uh, er, something. :)
     
    John Uhden, Apr 5, 2004
    #3
  4. Joe Burke

    Joe Burke Guest

    John,

    Yes, it's the copy from xref thing. And yes, that's the problem. When I picked an
    insert contained in an xref, the copy would go flying off somewhere because the
    matrix was incorrect. I need the xref matrix for it to work as I want it to. At that
    point I was stuck on how to get the xref matrix if I picked an insert.

    So then ObjMatrix, which works nicely in the other program. There I'm using the
    nentselp matrix as before when the copy object isn't an insert. Otherwise, ObjMatrix
    to get the xref matrix. I could simplify by using ObjMatrix in both cases, but I
    don't have that much confidence in it yet.

    I should explain... what I'm trying to do is something more specific than the general
    copy nested idea. It's intended to only work with xrefs and only one nested level
    deep. So I'm not concerned with objects nested in an insert in the xref. Only what
    I'd get if I copied and pasted objects from the xref file. Plus of course the
    transformation of those objects when needed.

    I'm waiting on you to finish XCOPY. :)

    Joe
     
    Joe Burke, Apr 5, 2004
    #4
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.