using vla-add* -- converting types

Discussion in 'AutoCAD' started by biot023, Oct 14, 2004.

  1. biot023

    biot023 Guest

    Hallo - I'm having real trouble passing data to the vla-addArc command.
    I'm afraid I'm just generally lost.
    The code (for what it's worth) that I am using is as follows:

    (defun 3dPoint->2dPoint (3dpt)
    (list (float(car 3dpt)) (float(cadr 3dpt)))
    ) ;_ end of defun


    (defun list->variantArray (ptsList / arraySpace sArray)
    ; allocate space for an array of 2d points stored as doubles
    (setq arraySpace
    (vlax-make-safearray
    vlax-vbdouble ; element type
    (cons 0
    (- (length ptsList) 1)
    ) ; array dimension
    )

    )
    (setq sArray (vlax-safearray-fill arraySpace ptsList))
    ; return array variant
    (vlax-make-variant sArray)
    )


    (defun djl:arc (ctr rad angstart angend / pts obj)
    (setq pts (apply 'append (mapcar '3dPoint->2dPoint (list ctr)))
    pts (list->variantArray pts)
    rad (vlax-make-variant rad vlax-vbdouble)
    angstart (vlax-make-variant angstart vlax-vbdouble)
    angend (vlax-make-variant angend vlax-vbdouble)
    obj (vla-addArc *ModelSpace*
    pts
    rad angstart
    angend)
    );_end setq
    (vla-put-closed obj T)
    obj
    );_end defun


    I know this is a mess - I don't really get all the vla stuff, yet.
    Can anyone offer any light?
    Thanks alot,
    doug.
     
    biot023, Oct 14, 2004
    #1
  2. Doug,

    It looks like you didn't "translate" the ActiveX documentation too well. In
    your primary function there are these issues:

    The Center property is documented as requiring a 3D point. Your code makes
    that argument into a 2D point.
    You make the radius argument into a variant, which is not required. The docs
    clearly show a Double is all that is needed.
    You make the starting angle argument into a variant, which is not required.
    The docs clearly show a Double is all that is needed.
    You make the ending angle argument into a variant, which is not required.
    The docs clearly show a Double is all that is needed.
    You attempt to change a Closed property for the Arc object, but there is no
    property for that in the Arc object.

    (defun C:Test ()
    (vl-load-com)
    (setq pt1 (getpoint "\nSpecify center point: "))
    (setq radius (getdist pt1 "\nSpecify radius: "))
    (setq angStart (getangle "\nSpecify starting angle: "))
    (setq angEnd (getangle "\nSpecify ending angle: "))
    (vla-AddArc (vla-Get-ModelSpace (vla-Get-ActiveDocument
    (vlax-Get-Acad-Object)))
    (vlax-3D-Point pt1)
    radius
    angStart
    AngEnd)
    (princ))

    --
    R. Robert Bell


    Hallo - I'm having real trouble passing data to the vla-addArc command.
    I'm afraid I'm just generally lost.
    The code (for what it's worth) that I am using is as follows:

    (defun 3dPoint->2dPoint (3dpt)
    (list (float(car 3dpt)) (float(cadr 3dpt)))
    ) ;_ end of defun


    (defun list->variantArray (ptsList / arraySpace sArray)
    ; allocate space for an array of 2d points stored as doubles
    (setq arraySpace
    (vlax-make-safearray
    vlax-vbdouble ; element type
    (cons 0
    (- (length ptsList) 1)
    ) ; array dimension
    )

    )
    (setq sArray (vlax-safearray-fill arraySpace ptsList))
    ; return array variant
    (vlax-make-variant sArray)
    )


    (defun djl:arc (ctr rad angstart angend / pts obj)
    (setq pts (apply 'append (mapcar '3dPoint->2dPoint (list ctr)))
    pts (list->variantArray pts)
    rad (vlax-make-variant rad vlax-vbdouble)
    angstart (vlax-make-variant angstart vlax-vbdouble)
    angend (vlax-make-variant angend vlax-vbdouble)
    obj (vla-addArc *ModelSpace*
    pts
    rad angstart
    angend)
    );_end setq
    (vla-put-closed obj T)
    obj
    );_end defun


    I know this is a mess - I don't really get all the vla stuff, yet.
    Can anyone offer any light?
    Thanks alot,
    doug.
     
    R. Robert Bell, Oct 14, 2004
    #2
  3. biot023

    Jürg Menzi Guest

    Hi Doug

    Why complicated?
    Code:
    (defun djl:arc (ctr rad angstart angend / pts obj)
    (setq pts (vlax-3d-point ctr)
    obj (vla-addArc *ModelSpace*
    pts
    rad angstart
    angend)
    );_end setq
    ; (vla-put-closed obj T) ;<- arc has no close property
    obj
    );_end defun
    
    Cheers
     
    Jürg Menzi, Oct 14, 2004
    #3
  4. biot023

    biot023 Guest

    Thanks very much for your replies -- obviously both have really sorted this out for me.
    As you can see, I'm very much a beginner in VLISP, & the helpfulness of people on this board cannot be overestimated.
    (& sorry for when my god-awful code offends anyone's sensibilities!)
    Cheers again,
    doug.
     
    biot023, Oct 15, 2004
    #4
  5. biot023

    Jürg Menzi Guest

    Welcome...¦-)

    Cheers
     
    Jürg Menzi, Oct 15, 2004
    #5
  6. Glad to help! At least you were brave enough to ask the question and post
    your code. ;^)

    --
    R. Robert Bell


    Thanks very much for your replies -- obviously both have really sorted this
    out for me.
    As you can see, I'm very much a beginner in VLISP, & the helpfulness of
    people on this board cannot be overestimated.
    (& sorry for when my god-awful code offends anyone's sensibilities!)
    Cheers again,
    doug.
     
    R. Robert Bell, Oct 16, 2004
    #6
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.