Nentsel

Discussion in 'AutoCAD' started by Casey Roberts, Oct 29, 2004.

  1. I'm trying to get the radius and center point of a circle that is part of a
    block.

    When I use:

    (cdr (assoc 10 (entget (car (nentsel))))

    It doesn't return the correct center point...how come?, and how do i get the
    correct center point?
     
    Casey Roberts, Oct 29, 2004
    #1
  2. Casey Roberts

    T.Willey Guest

    You are getting the center point as it relates to the insertion point of the block. I guess you have to find that point and the distance from the insertion point of the block. Then the point where the block is at in the current drawing, and then do some math to find where it is currently.

    Hope that helps.
    Tim
     
    T.Willey, Oct 30, 2004
    #2
  3. Casey Roberts

    T.Willey Guest

    Try passing the points to this.
    (mapcar '(lambda (a b) (+ a b) )tm1 tm2)
    tm1 could be the block insertion point
    tm2 is the center point of the circle.

    Tim
     
    T.Willey, Oct 30, 2004
    #3
  4. Casey Roberts

    Joe Burke Guest

    Tim,

    Your suggestion would work if the block containing the circle isn't scaled and/or
    rotated. If it is, you'd need something like these two functions.

    ;; 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))
    )
    )
    )

    ;; 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)))
    )

    Example use:
    (defun c:test ( / lst cirobj cenpt matrix res )
    (and
    (setq lst (nentsel "Select circle contained in block: "))
    (setq cirobj (vlax-ename->vla-object (car lst)))
    (if (vlax-property-available-p cirobj 'Center)
    (setq cenpt (vlax-get cirobj 'Center)))
    (setq matrix (caddr lst))
    (setq res (@PTrans cenpt matrix))
    )
    res
    ) ;end

    Joe Burke
     
    Joe Burke, Oct 30, 2004
    #4
  5. Casey Roberts

    T.Willey Guest

    Joe,

    Thanks. I didn't think it would have been that easy.

    Tim
     
    T.Willey, Nov 2, 2004
    #5
  6. Casey Roberts

    Tom Smith Guest

    Why lambda? You can add points with (mapcar '+ pt1 pt2).
     
    Tom Smith, Nov 2, 2004
    #6
  7. Casey Roberts

    T.Willey Guest

    Tom,

    Just because I don't really have the best understanding of mapcar still, so I thought you had to do it that way. Thanks for pointing out that it doesn't have to be done that way. Another thing I learned from this post. Cool

    Tim
     
    T.Willey, Nov 2, 2004
    #7
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.