TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Lee Mac on June 22, 2009, 07:28:02 AM
-
This is something that I have never really completely understood, even after reading, and re-reading the ACAD help file on it.
I have, in the past, used such functions as:
(vlax-safearray-get-u-bound <var> <dim>)
But I haven't quite understood exactly what is a dimension in a safearray, and what exactly the return of the above function means.
Any help is much appreciated.
Lee
-
Maybe this will illustrate the function:
_$ (setq matrix (vlax-make-safearray vlax-vbString '[color=red](1 . 2)[/color] '[color=green](1 . 2)[/color] ))
#<safearray...>
[color=red]_$ (vlax-safearray-get-u-bound matrix 1)
2[/color]
[color=green]_$ (vlax-safearray-get-u-bound matrix 2)
2[/color]
_$ (vlax-safearray-get-u-bound matrix 3)
; error: ActiveX Server returned an error: Invalid index
_1$
; reset after error
_1$ (setq matrix (vlax-make-safearray vlax-vbString '(1 . 2) '(1 . 3) '(1 . 4)))
#<safearray...>
_1$
; reset after error
_$ (vlax-safearray-get-u-bound matrix 1)
2
_$ (vlax-safearray-get-u-bound matrix 2)
3
_$ (vlax-safearray-get-u-bound matrix 3)
4
_$ (vlax-safearray-get-u-bound matrix 4)
; error: ActiveX Server returned an error: Invalid index
_2$ (setq matrix (vlax-make-safearray vlax-vbString '(1 . 2) '[color=red](2 . 5)[/color] '(1 . 4)))
#<safearray...>
_2$ (vlax-safearray-get-[color=red]u[/color]-bound matrix 2)
5
_3$ (vlax-safearray-get-[color=red]l[/color]-bound matrix 2)
2
_3$
-
ahh, I see now.
The reason I ask this question is in relation to its use with the IntersectWith method.
I now use vlax-invoke... as it returns a list of points instead of a safearray, but, when using the vla-IntersectWith method, there is a check that is performed:
(if (> (vlax-safearray-get-u-bound iArr 1) 0)
(progn
(setq iLst (vlax-safearray->list iArr))
If this is just returning the last element of the first dimension of the safearray, then why is it checking for a positive value, when the contents of the safearray is a set of points - surely these points can be zero?
Maybe I'm on another planet today...
Lee
-
You can save some typing:
Command: (setq m (safearray vlax-vbString '(1 . 2) '(1 . 2) ))
#<safearray...>
Command: (safearray-get-u-bound m 2)
2
-
A safearray with a U-Bound of -1 means it's an empty array.
-
A safearray with a U-Bound of -1 means it's an empty array.
Ahh I see now :-D
-
Ah safearrays. Them be fun:
A little food for thought; you can do so much if you know what you have before you create/parse it.
Command: (vlax-safearray->list (vlax-make-safearray vlax-vbString '(1 . 81)))
("" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
"" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
"" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
"" "" "")
Command: (vlax-safearray->list (vlax-make-safearray vlax-vbString '(0 . 2) '(0 . 2) '(0 . 2) '(0 . 2)))
(
((("" "" "") ("" "" "") ("" "" ""))
(("" "" "") ("" "" "") ("" "" ""))
(("" "" "") ("" "" "") ("" "" "")))
((("" "" "") ("" "" "") ("" "" ""))
(("" "" "") ("" "" "") ("" "" ""))
(("" "" "") ("" "" "") ("" "" "")))
((("" "" "") ("" "" "") ("" "" ""))
(("" "" "") ("" "" "") ("" "" ""))
(("" "" "") ("" "" "") ("" "" "")))
)
-e.g. a sentence, or several words?
Cool huh?
-
Thanks for that Se7en - very helpful, but I am a little confused with the second example, why is it not just:
(("" "" "") ("" "" "") ("" "" "") ("" "" ""))
?
-
sorry im typing this on my phone so i will keep this brief and hope you understand.
3 + 3 + 3 = 9
...
9 + 9 + 9 = 27
...
27 + 27 + 27 = 81
or
3^4 = 81
-
Got it. Thanks Se7en 8-)
-
This is how I visualised it: :roll:
(
(([color=red]("" "" "")[/color] ("" "" "") ("" "" ""))
(("" "" "") ("" "" "") ("" "" ""))
(("" "" "") ("" "" "") ("" "" "")))
((("" "" "") ("" "" "") ("" "" ""))
(("" "" "") ("" "" "") ("" "" ""))
(("" "" "") ("" "" "") ("" "" "")))
((("" "" "") ("" "" "") ("" "" ""))
(("" "" "") ("" "" "") ("" "" ""))
(("" "" "") ("" "" "") ("" "" "")))
)
(
([color=BLUE](("" "" "") ("" "" "") ("" "" ""))[/color]
(("" "" "") ("" "" "") ("" "" ""))
(("" "" "") ("" "" "") ("" "" "")))
((("" "" "") ("" "" "") ("" "" ""))
(("" "" "") ("" "" "") ("" "" ""))
(("" "" "") ("" "" "") ("" "" "")))
((("" "" "") ("" "" "") ("" "" ""))
(("" "" "") ("" "" "") ("" "" ""))
(("" "" "") ("" "" "") ("" "" "")))
)
(
[color=green]((("" "" "") ("" "" "") ("" "" ""))
(("" "" "") ("" "" "") ("" "" ""))
(("" "" "") ("" "" "") ("" "" ""))) [/color]
((("" "" "") ("" "" "") ("" "" ""))
(("" "" "") ("" "" "") ("" "" ""))
(("" "" "") ("" "" "") ("" "" "")))
((("" "" "") ("" "" "") ("" "" ""))
(("" "" "") ("" "" "") ("" "" ""))
(("" "" "") ("" "" "") ("" "" "")))
)
[color=purple](
((("" "" "") ("" "" "") ("" "" ""))
(("" "" "") ("" "" "") ("" "" ""))
(("" "" "") ("" "" "") ("" "" "")))
((("" "" "") ("" "" "") ("" "" ""))
(("" "" "") ("" "" "") ("" "" ""))
(("" "" "") ("" "" "") ("" "" "")))
((("" "" "") ("" "" "") ("" "" ""))
(("" "" "") ("" "" "") ("" "" ""))
(("" "" "") ("" "" "") ("" "" "")))
)[/color]
[color=red]Red = first Dimension[/color]
[color=blue]Blue = second Dimension[/color]
[color=green]Green = Third Dimension[/color]
[color=purple]Purple = Fourth Dimension[/color]
-
That's the way I see it.
Because this:
(vlax-safearray->list (vlax-make-safearray vlax-vbString '(0 . 2) '(0 . 2) '(0 . 2)))
yields this:
'((("" "" "") ("" "" "") ("" "" ""))
(("" "" "") ("" "" "") ("" "" ""))
(("" "" "") ("" "" "") ("" "" "")))
-
I find I can't take something at face value and accept it, I have to break it down and work out why it is the way it is. :-P
-
Not sure i follow your breakdown method exactly. I think i get what your saying, but its been a while since ive played with arrays and i never was all that crystal on everything about them to begin with...more of a theory kind of application.
However, i think you may have that order reversed. Im waiting for someone of a little more clout then a flunky to chime in but i dont see how your breakdown works on these?
(vlax-safearray->list (vlax-make-safearray vlax-vbString '(0 . 2) '(0 . 3)))
(("" "" "" "") ("" "" "" "") ("" "" "" ""))
(vlax-safearray->list (vlax-make-safearray vlax-vbString '(0 . 3) '(0 . 2)))
(("" "" "") ("" "" "") ("" "" "") ("" "" ""))
So: (("" "" "" "") ("" "" "" "") ("" "" "" ""))
or
'(0 . 2) '(0 . 3)
or
[lower] [upper]
=>
(
[lower bounds]
([upper bounds] "" "" "" "" [/upper bounds]) ("" "" "" "") ("" "" "" "")
[/lower bounds]
)
-
Yes I believe you are correct Se7en,
I just took a look at this one:
(vlax-safearray->list (vlax-make-safearray vlax-vbString '[color=purple](0 . 3)[/color] '[color=green](0 . 2)[/color] '[color=blue](0 . 1)[/color] '[color=red](0 . 0)[/color]))
(
(([color=red]("") [/color](""))
(("") (""))
(("") ("")))
((("") (""))
(("") (""))
(("") ("")))
((("") (""))
(("") (""))
(("") ("")))
((("") (""))
("") (""))
(("") ("")))
)
(
([color=blue](("") (""))[/color]
(("") (""))
(("") ("")))
((("") (""))
(("") (""))
(("") ("")))
((("") (""))
(("") (""))
(("") ("")))
((("") (""))
("") (""))
(("") ("")))
)
(
[color=green]((("") (""))
(("") (""))
(("") ("")))[/color]
((("") (""))
(("") (""))
(("") ("")))
((("") (""))
(("") (""))
(("") ("")))
((("") (""))
("") (""))
(("") ("")))
)
[color=purple](
((("") (""))
(("") (""))
(("") ("")))
((("") (""))
(("") (""))
(("") ("")))
((("") (""))
(("") (""))
(("") ("")))
((("") (""))
("") (""))
(("") ("")))
)[/color]
-
Good catch John. 8-)