AddLightweightPolyline and UCS

Discussion in 'AutoCAD' started by Jason Piercey, Jan 6, 2005.

  1. In the process of fine tuning a routine that generates
    the boundary which defines a named view, I thought it
    would be nice to include any required transformations
    of coordinate systems.

    What I have written thus far code wise works fine if I
    use the command function to draw the boundary but
    when trying to use AddLightweightPolyline things don't
    quite work the same.

    The help file says that AddLightweightPolyline needs
    "The array of 2D OCS coordinates ...."

    (vlax-invoke <modelspace> 'AddLightweightPolyline <lst>)

    So, do I need to translate <lst> from UCS to OCS? Didn't
    see an OCS option in docs on the trans function, other than
    using an ename (which doesn't appear to work when passing
    a named view's ename)

    What am I missing/overlooking?
     
    Jason Piercey, Jan 6, 2005
    #1
  2. Jason Piercey

    Kelie Feng Guest

    Jason,

    I used vla-AddLightweightPolyline in a routine to draw paperspace viewport
    boundary in modelspace and I just used the coordinates in WCS. Worked fine.
     
    Kelie Feng, Jan 6, 2005
    #2
  3. Jason Piercey

    BillZ Guest

    I use the add3dpoly method for 3d stuff.

    It only needs the wcs coords.

    (setq Rec_1 (vlax-invoke *mspace* 'Add3dPoly (apply 'append (list r1p1 r1p2 r1p3)))


    Bill
     
    BillZ, Jan 6, 2005
    #3
  4. Hi Kelie,

    That works fine if the UCS and WCS are the same.
    I figured that if they were not the same my routine
    should still place the boundary in the correct spot.
     
    Jason Piercey, Jan 6, 2005
    #4
  5. Hi Bill,

    I don't really need a 3dpoly, a simple lightweight
    should work fine. Take a 2d named view, change
    the ucs so it is a different plane than the view, and
    draw a boundary around it.

    My immediate need was just for 2d "plan" views
    but I could also use this for 3d views (on occasion)
    so I thought I'd try to get a handle on any required
    TRANSing (using the 2d views with an "odd" ucs).

    After I get this part squared away, I'll incorporate
    any clipping planes that are present.
     
    Jason Piercey, Jan 6, 2005
    #5
  6. Jason Piercey

    Kelie Feng Guest

    Jason,

    Seems to me the lwpolyline will always be placed in the right coordinates if
    WCS coordinates are supplied. I had wondered about what's said in the
    documentation regarding OCS as well.
     
    Kelie Feng, Jan 6, 2005
    #6
  7. Jason Piercey

    T.Willey Guest

    I'm not sure if this is the same thing, but I have a routine that draws a polyline around the area that is defined by a viewport. Once I get those points I switch to model space and trans those points like
    (setq PtList (mapcar '(lambda (x) (trans x 0 2)) PtList))
    and it seems to work when the viewport ucs is different then the model space ucs.

    Hope that helps, if not forget I posted here.
    Tim
     
    T.Willey, Jan 6, 2005
    #7
  8. Jason Piercey

    BillZ Guest

    Jason,
    I use this one from Jeff M.
    Doesn't seem to need any trans and seems to work in any ucs.

    Code:
    ;Reply From: Jeff Mishler
    ;Date: Mar/24/04 - 21:39 (CST)
    ;Draw a rectangle from list of points.
    ;
    ;
    (defun drawsquare (leg pt / coord1 pline)
    (vl-load-com)
    (setq pt (reverse (cdr (reverse pt))))
    (setq coord1 (polar pt (angtof "225" 0) (* (sqrt 2) leg)))
    (setq coord1 (append (polar pt (angtof "135" 0) (* (sqrt 2) leg)) coord1))
    (setq coord1 (append (polar pt (angtof "45" 0) (* (sqrt 2) leg)) coord1))
    (setq coord1 (append (polar pt (angtof "315" 0) (* (sqrt 2) leg)) coord1))
    (setq pline (vlax-invoke
    (vla-get-modelspace
    (vla-get-activedocument
    (vlax-get-acad-object)))
    "addlightweightpolyline"
    coord1
    )
    )
    (vla-put-closed pline :vlax-true)
    )
    
    (defun c:sqr (/ leg pt)
    (if (and
    (setq leg (getdist "\nLength of side of square: "))
    (setq pt (getpoint "\nSelect centerpoint of square: "))
    )
    (drawsquare leg pt)
    )
    (princ)
    )
    Bill
     
    BillZ, Jan 6, 2005
    #8
  9. I was using this.

    ; function to create a list of points representing
    ; the outline of a box based on the center point,
    ; width and height of the box.
    ; Arguments:
    ;
    - list, 2d point
    ; [width] - integer or real, width of outline
    ; [height] - integer or real, height of outline
    ; returns: list of points
    (defun getCornersFromCenter (center width height)
    (setq height (/ height 2.0))
    (setq width (/ width 2.0))
    (list
    (mapcar '+ center (list (- width) (- height)))
    (mapcar '+ center (list width (- height)))
    (mapcar '+ center (list width height))
    (mapcar '+ center (list (- width) height))
    )
    )


    I'll try and post some other code today, right now
    I've got too much real work getting in the way.​
     
    Jason Piercey, Jan 6, 2005
    #9
  10. Jason Piercey

    James Allen Guest

    BillZ wrote > Doesn't seem to need any trans and seems to work in any ucs.

    Only if the current ucs happens to be coincide with the "current" ocs.
    Adding a trans using the ocs normal vector takes care of it as follows.
    --
    James Allen, EIT
    Malicoat-Winslow Engineers, P.C.
    Columbia, MO


    ;Reply From: Jeff Mishler
    ;Date: Mar/24/04 - 21:39 (CST)
    ;Draw a rectangle from list of points.
    ;
    ;
    ;Modified 06Jan05 by James Allen for arbitrary ucs
    (defun drawsquare (leg pt / coord1 ocs pline)
    (vl-load-com)
    (setq coord1 (cons (polar pt (angtof "225" 0) (* (sqrt 2) leg)) coord1)
    coord1 (cons (polar pt (angtof "135" 0) (* (sqrt 2) leg)) coord1)
    coord1 (cons (polar pt (angtof "45" 0) (* (sqrt 2) leg)) coord1)
    coord1 (cons (polar pt (angtof "315" 0) (* (sqrt 2) leg)) coord1)
    ocs (MWE:CrossProd (list (getvar "ucsxdir") (getvar "ucsydir")))
    coord1 (mapcar
    '(lambda (a) (reverse (cdr (reverse (trans a 1 ocs)))))
    coord1
    )
    coord1 (apply 'append coord1)
    pline (vlax-invoke
    (vla-get-modelspace
    (vla-get-activedocument
    (vlax-get-acad-object)
    )
    )
    "addlightweightpolyline"
    coord1
    )
    )
    (vla-put-closed pline :vlax-true)
    )

    (defun c:sqr (/ leg pt)
    (if (and
    (setq leg (getdist "\nLength of side of square: "))
    (setq pt (getpoint "\nSelect centerpoint of square: "))
    )
    (drawsquare leg pt)
    )
    (princ)
    )

    ;;; Calculates the cross product of two three-element vectors
    (defun MWE:CrossProd (arglst / a b)
    (mapcar 'set '(a b) arglst)
    (list (- (* (nth 1 a) (nth 2 b)) (* (nth 2 a) (nth 1 b)))
    (- (* (nth 2 a) (nth 0 b)) (* (nth 0 a) (nth 2 b)))
    (- (* (nth 0 a) (nth 1 b)) (* (nth 1 a) (nth 0 b)))
    )
    )
     
    James Allen, Jan 6, 2005
    #10
  11. Jason Piercey

    James Allen Guest

    So, do I need to translate <lst> from UCS to OCS?
    Yes. If ename doesn't work, use the view's normal (view direction) in the
    trans function.
    -->(trans point 1 normal)
    Check the docs again, mine say you can use either an ename or extrusion
    vector to define an ocs.
    Does that get it?
     
    James Allen, Jan 6, 2005
    #11
  12. Jason Piercey

    BillZ Guest

    Thanks James.

    Makes the sqr function a lot more useable.

    As always my head is starting to hurt because my understanding of math and OCS doesn't match up to all the information I am taking in. :)

    Jason:
    You talked about converting from WCS to UCS.
    Should work for rectangles drawn in the WCS.

    Code:
    ;01/07/05 Bill Zondlo
    ;get current ucs matrix and transform entity drawn in WCS.
    ;
    (defun TransObj2Ucs (entnam / *acad* adoc EntObj Matrx NewUCS UCSObj)
    (vl-load-com)
    (setq *acad* (vlax-get-acad-object)
    adoc (vla-get-activedocument *acad*)
    UCSObj (vla-get-UserCoordinateSystems adoc)
    NewUCS (vla-add UCSObj
    (vlax-3d-point 0 0 0)
    (vlax-3d-point (getvar "ucsxdir"))
    (vlax-3d-point (getvar "ucsydir")) "TempUCS")
    Matrx (vla-GetUCSMatrix NewUCS)
    EntObj (vlax-ename->vla-object entnam)
    )
    (vla-transformby EntObj matrx)
    (vla-delete NewUCS)
    )
    Bill
     
    BillZ, Jan 7, 2005
    #12
  13. Haven't had much of a chance to try any of the
    provided suggestions. Thanks to all for the ideas,
    I'll try them out when I have sufficient time.
     
    Jason Piercey, Jan 10, 2005
    #13
  14. Jason Piercey

    James Allen Guest

    Hi Jason,

    AddLightweightPolyline expects 2D points. Add this line before the append
    in test2:
    (setq lst (mapcar '(lambda (a) (reverse (cdr (reverse a)))) lst))

    Depending on your application, you may also want to be sure your current ucs
    z axis is aligned with the saved view's direction before any trans calls.
    If they are not, your lwpolyline will be added in the wrong plane.

    James
     
    James Allen, Jan 12, 2005
    #14
  15. Thanks James!

    Didn't realize that the TRANSing in test2
    was taking 2d points and returning 3d points.

    I swear I was using 2d points to start with <g>

    --
    Autodesk Discussion Group Facilitator



     
    Jason Piercey, Jan 12, 2005
    #15
  16. On a side note, I would imagine that this would be
    a slightly more sensible approach to dropping the
    z values from a list of 3d points.

    (mapcar '(lambda (p) (list (car p)(cadr p))) lst))

    Although, I have used the double reverse in the past.
     
    Jason Piercey, Jan 12, 2005
    #16
  17. Jason Piercey

    James Allen Guest

    Thanks. Funny, that's actually what I started with and then changed it...
    I've been struggling lately with vague memories of efficiency discussions on
    various list manipulations (rev cdr rev to remove last element; [rev] cons
    vs append to build, nth vs c[a/d]r to access, etc.). But I can't seem to
    come up with the right search to find them. Maybe someone would be willing
    to review...

    James
     
    James Allen, Jan 12, 2005
    #17
  18. I know from discussion here that APPEND
    is the slow beast. I tend to use CONS and
    a REVERSE more than anything.

    While I'm not sure about the speed differential
    between CAR/CADR vs. the double REVERSE
    I can't imagine that reversing a list twice would
    be faster than simply extracting the elements that
    are needed.
     
    Jason Piercey, Jan 12, 2005
    #18
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.