VLA Polyline & VLA Points

Discussion in 'AutoCAD' started by BillZ, Aug 9, 2004.

  1. BillZ

    BillZ Guest

    R2005:

    If I want to create a polyline in vlisp:

    1.) Would I use (vla-addpolyline *mspace* pointarray)
    2.) I so, what is the best way to put the points I have (in WCS) into the OCS and an array.
    I know about l vla-translatecoordinates but that returns a VLA object of the point. And that's fine but how can I get all the translated points into an array?

    TIA

    Bill
     
    BillZ, Aug 9, 2004
    #1
  2. BillZ

    Jürg Menzi Guest

    Hi Bill
    Better use (no need to use an array):
    (vlax-invoke *mspace* 'AddLightweightPolyline '(x y x y x y x y...))
    In case of WCS coordinates you've nothing to translate...

    Cheers
     
    Jürg Menzi, Aug 9, 2004
    #2
  3. BillZ

    BillZ Guest

    Thanks,
    I can't get it to work with WCS points.

    From the help files:

    VerticesList

    Variant (array of doubles)
    The array of 2D OCS coordinates specifying the vertices of the polyline.

    I can create the pline using the points but it's off in space.

    Bill
     
    BillZ, Aug 9, 2004
    #3
  4. BillZ

    Jürg Menzi Guest

    Hi Bill

    You can't translate points to OCS without an existing object because you need
    the normal of the object for translation:
    (trans Point 0 NormalOfTheObject)
    Assuming your UCS is not equal WCS, you've to translate the points from UCS to
    the WCS:
    (trans Point 1 0)
    Another point to pay attention, LwPolylines need 2D points:
    (setq PntLst (mapcar '(lambda (l) (trans l 1 0)) '((0.0 0.0) (20.0 20.0))))
    returns 3D points, eg.: '((105.468 133.437 0.0) (115.468 143.437 0.0))
    (setq PntLst (append (mapcar '(lambda (l) (list (car l) (cadr l))) PntLst)))
    returns the correct list format, eg.: '(105.468 133.437 115.468 143.437)
    (vlax-invoke *mspace* 'AddLightweightPolyline PntLst)

    Cheers
     
    Jürg Menzi, Aug 10, 2004
    #4
  5. BillZ

    BillZ Guest

    You can't translate points to OCS without an existing object because you need
    the normal of the object for translation:<<<

    Jürg,
    I understand what I have to do to create my pline.

    I am tring to understand what way would be the correct way of using these vla functions.

    For example, To use the vla-add-lightweigthpolyline function:

    First, before I can translate to the OCS, the points in my list, I have to convert them into a vlax 3d point, and then immediately convert back into a list of regular points so I can use the points to do other things like turn them into a 2d list.

    So first I have to do this:
    (foreach n ptlst
    (setq Ocs_pts (cons
    (vlax-safearray->list
    (vlax-variant-value
    (vla-TranslateCoordinates *util* (vlax-3d-point n) acWorld acOCS :vlax-false norm1)
    )
    )
    Ocs_pts) ;cons
    ) ;setq
    ) ;end foreach

    Okay great, works fine!
    And then I have to convert the list to a 2d point AND a single list:

    (setq OCS_pts (apply 'append (mapcar '3dPoint->2dPoint OCS_pts))
    This too works fine.

    Now, IF I want to use the vla-addlightweightpolyline function I have to create a safearray AND add the point list to the array:

    (setq OCS_array (vlax-SafeArray-Fill (vlax-Make-SafeArray vlax-vbDouble (cons 0 (1- (length OCS_pts)))) OCS_pts))
    (setq FinallyMyPline (vla-AddLigthweightPolyline *mspace* OCS_array))

    Isn't there some more convenient way to do all this?
    I am not necessarily looking for a quick fix/shortcut as much as I am the correct proceedure to do this.

    Thanks for all input.


    Bill
     
    BillZ, Aug 10, 2004
    #5
  6. BillZ

    Jürg Menzi Guest

    Hi Bill

    First of all I've to ask for the contents of the variable norml. Do you use
    '(0 0 1) or the normal you wish to draw the Polyline? Second, why do you use
    arrays they need a lot of translations?
    Code:
    (foreach n ptlst
    (setq Ocs_pts (cons
    (vlax-safearray->list
    (vlax-variant-value
    (vla-TranslateCoordinates *util*
    (vlax-3d-point n) acWorld acOCS :vlax-false norm1
    )
    )
    )
    Ocs_pts)	;cons
    )				;setq
    )				;end foreach
    ;can be replaced by ('norml' must be a list):
    (setq Ocs_pts (mapcar '(lambda(l) (trans l 0 norml)) ptlst))
    
    ;Assuming that '3dPoint->2dPoint' is a conversion function, this line is ok:
    (setq OCS_pts (apply 'append (mapcar '3dPoint->2dPoint OCS_pts))
    
    ;The use of 'vlax-invoke' accepts standard LISP lists:
    (vlax-invoke *mspace* 'AddLightweightPolyline OCS_pts)
    
    Cheers
     
    Jürg Menzi, Aug 10, 2004
    #6
  7. BillZ

    BillZ Guest

    First of all I've to ask for the contents of the variable >>>norml. Do you use
    Jürg,
    I appreciate you help.
    As a beginner in Vlisp, I am only trying to understand.
    I know that you can use (vlax-invoke and use a regular list of points.
    But then what is the purpose of (vla-AddLightweightPolyline? Are these functions put there only to frustrate and confuse new learners of the code?
    I am not trying to be disrespectful, I just would like to understand why there are so many ways to accomplish the same thing in Vlisp.


    Bill
     
    BillZ, Aug 10, 2004
    #7
  8. BillZ

    Jürg Menzi Guest

    Hi Bill
    If you've an array anyway, maybe with data from an other object...
    For example, it makes no sense to convert a point to a variant, translate
    them to the OCS by vla-TranslateCoordinates, convert them back to a list,
    convert to 2d point and then the whole thing back to an array...
    If you've variant type points as base information and you need a result
    in variant value, it makes sense to use vla-TranslateCoordinates.
    I understand your confusion, but there are several implementations in Vlisp:
    vl- Generic extensions to AutoLISP
    vlax- Generic ActiveX functions
    (vlax-get, vlax-put, vlax-invoke are from old VitalLisp)
    vla- AutoCAD-specific ActiveX properties and methods
    vlr- Visual LISP reactor related functions
    In short:
    vla-xxx is VBA flavor, vl-xxx, vlr-xxx and vlax-xxx are Lisp flavor

    For my solutions, I use the way with lowest number of conversion steps.

    Cheers
     
    Jürg Menzi, Aug 10, 2004
    #8
  9. BillZ

    BillZ Guest

    Thanks Jürg,

    That put's a little more light on the subject.
    This is all new to me and I don't have an extended background in programming (started w/autolisp), so anything I can learn about this helps.
    I'll re-think what I'm trying to do here now.
    Thanks again.

    Bill
     
    BillZ, Aug 10, 2004
    #9
  10. BillZ

    Jürg Menzi Guest

    You're always welcome...¦-)

    Cheers
     
    Jürg Menzi, Aug 10, 2004
    #10
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.