Safearray errors

Discussion in 'AutoCAD' started by rmp605, Jan 5, 2005.

  1. rmp605

    rmp605 Guest

    When I run the test code below, I get an error message

    error: Automation Error. Incorrect SafeArray dimension

    in the last function, vla-add3Dmesh. If I try to inspect the value of arraySpace at any point after vlax-make-safearray, I get the message

    error: ActiveX Server returned an error: Invalid index

    What am I doing wrong?

    -- Rick

    [pre]
    ;;; Load ActiveX functionality
    (vl-load-com)

    ;;; Define *ModelSpace* global variable
    (setq *ModelSpace*
    (vla-get-ModelSpace
    (vla-get-ActiveDocument (vlax-get-acad-object))
    )
    )

    (defun C:TestFun ( / SurfaceCoords vla_SurfaceCoords arraySpace)
    (setq SurfaceCoords
    (quote
    (((-255.483 36.2336 30.7249)
    (-255.41 35.7226 30.2416)
    (-255.428 37.0652 32.1144)
    (-255.421 36.6692 31.5674)
    )
    ((-142.4 36.0864 23.2249)
    (-142.709 35.6735 22.7416)
    (-141.773 36.636 24.6144)
    (-142.048 36.351 24.0674)
    )
    ((-76.1623 -18.4176 15.7249)
    (-76.6493 -18.5888 15.2416)
    (-75.336 -18.3088 17.1144)
    (-75.723 -18.3929 16.5674)
    )
    ((-54.1702 -71.7072 8.22493)
    (-54.6856 -71.6791 7.74164)
    (-53.3652 -71.9229 9.61438)
    (-53.7549 -71.8525 9.06744)
    )
    ((-51.3688 -100.536 0.72493)
    (-51.8688 -100.407 0.241643)
    (-50.6212 -100.904 2.11438)
    (-50.9897 -100.759 1.56744)
    )
    )
    )
    )
    (setq arraySpace
    (vlax-make-safearray
    vlax-vbdouble
    (cons 0 4)
    (cons 0 3)
    (cons 0 2)
    )
    )
    (setq vla_SurfaceCoords
    (vlax-make-variant
    (vlax-safearray-fill arraySpace SurfaceCoords)
    )
    )
    (vla-add3Dmesh *ModelSpace* 5 4 vla_SurfaceCoords)
    )
    [/pre]
     
    rmp605, Jan 5, 2005
    #1
  2. rmp605

    Jeff Mishler Guest

    Rick,
    First off, work backwards to see the input required......create a mesh in
    the drawing and inspect the coordinates property. In this case, you need to
    provide a one dimensional array (x1 y1 z1 x2 y2 z2 .... etc):

    Command: (setq test (vlax-ename->vla-object (car (entsel))))

    Select object: #<VLA-OBJECT IAcadPolygonMesh 0200ded4>

    Command: (setq coords (vla-get-coordinates test))
    #<variant 8197 ...>

    Command: (setq var-val(vlax-variant-value coords))
    #<safearray...>

    Command: (setq safaray(vlax-safearray->list var-val))
    (3.9036 1.40148 0.0 6.36601 1.32521 0.0 4.41899 3.02225 0.0 7.58768 3.63242
    0.0
    10.5846 2.52648 0.0 14.3641 1.13453 0.0 14.8222 5.0625 0.0 10.4891 6.47352
    0.0
    7.74039 7.94174 0.0 7.5495 7.99894 0.0 10.9282 8.57097 0.0 13.3333 6.85487
    0.0
    14.7268 5.19597 0.0 17.0556 1.91631 0.0 18.0482 8.13242 0.0 11.4054 8.30403
    0.0
    3.61727 7.99894 0.0 1.7466 5.55826 0.0 2.5674 3.28919 0.0 6.15604 2.29767
    0.0)


    For future reference, you can dispense (in most cases) with the creation of
    the safeaarrays and variants if you use the form
    (vlax-invoke *modelspace* 'add3dmesh 5 4 SurfaceCoords);making sure that
    SurfaceCoords is in the required list format which you can verify by using
    the same technique I used above:

    Command: (setq coord-list (vlax-get test 'coordinates))
    (3.9036 1.40148 0.0 6.36601 1.32521 0.0 4.41899 3.02225 0.0 7.58768 3.63242
    0.0
    10.5846 2.52648 0.0 14.3641 1.13453 0.0 14.8222 5.0625 0.0 10.4891 6.47352
    0.0
    7.74039 7.94174 0.0 7.5495 7.99894 0.0 10.9282 8.57097 0.0 13.3333 6.85487
    0.0
    14.7268 5.19597 0.0 17.0556 1.91631 0.0 18.0482 8.13242 0.0 11.4054 8.30403
    0.0
    3.61727 7.99894 0.0 1.7466 5.55826 0.0 2.5674 3.28919 0.0 6.15604 2.29767
    0.0)


    --
    Jeff
    check out www.cadvault.com
     
    Jeff Mishler, Jan 5, 2005
    #2
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.