How to get length of spline in vba?

How to get length of spline in vba?

Anonymous
Not applicable
1,546 Views
10 Replies
Message 1 of 11

How to get length of spline in vba?

Anonymous
Not applicable
I'm writing a small script in vba and need to get the length of a spline for some calculations. I see that length is not a property of AcadSpline linetype. Does anyone know how I can go about doing this in my script?

Dim MyLine As AcadLine
MyLineLength = MyLine.Length(intellisense has length listed for line)

but when I go to do this for my spline:
Dim MySpline As AcadSpline
MyLineLength = MySpline. (intellisense doesn't have length listed for spline)
0 Likes
1,547 Views
10 Replies
Replies (10)
Message 2 of 11

Anonymous
Not applicable
i also searched the same, with no success.
for the last, i used vba-calling-lisp, since there is lisp function "vlax-curve-dist-at-param", which returns distance-over-curve-up-to-given-param, so, if you supply end-param-value, you get the curve length. in fact, you need to check start-param as well, bnecause one of them will report you distance=0
just check the topic "calling lisp from vba", it is quite descriptive
0 Likes
Message 3 of 11

Anonymous
Not applicable
Thanks for giving me some dirrection to go in....I've been racking my brains trying to find a solution.

I've never created a lisp routine. Can you please tell me where I can find the barebone basics I need ...just to get the length value?

Thanks again,
Proctor
0 Likes
Message 4 of 11

Anonymous
Not applicable
When calling vlax-curve-dist-at-param, you said I need to pass in a start and end param....do you mean the start and end tangent?

Thanks,
Proctor
0 Likes
Message 5 of 11

Anonymous
Not applicable
no, they're params as he said
look at the vlax-curve- functions in vlisp help

wrote in message news:5822238@discussion.autodesk.com...
When calling vlax-curve-dist-at-param, you said I need to pass in a start
and end param....do you mean the start and end tangent?

Thanks,
Proctor
0 Likes
Message 6 of 11

Anonymous
Not applicable
Thanks...I get it now...need to utilize the help more.

Thanks again,
Proctor
0 Likes
Message 7 of 11

Anonymous
Not applicable
as illustartion, here is a part of my vba-lisp sub. this works for me, maybe there is better way, somebody correct me?
(hope there is no missing brackets)
-----------8<------------------------
'acad 2008, written with vbscript, all vars are variants
option explicit
dim acad,draw,model
set acad=getobject(,"autocad.application.17")
set draw=acad.activedocument
set model=draw.modelspace
dim vl,vlf
'need to have loaded (vl-load-com) by cmd line or acad.lsp
set vl = acad.getinterfaceobject("vl.application.16")
set vlf = vl.activedocument.functions
dim lispobj,length,curve
'curve is your curve object,
'set curve=something ...
set lispobj=vlf.item("read").funcall("hspline")
vlf.item("set").funcall lispobj,curve.handle
set lispobj=vlf.item("read").funcall( _
"(progn " & _
"(setq vlhspline (vlax-variant-value hspline)) " & _
"(setq spl (handent vlhspline)) " & _
"(setq lng (vlax-curve-getdistatparam spl (vlax-curve-getendparam spl))) " & _
")" _
)
length=vlf.item("eval").funcall(lispobj)
0 Likes
Message 8 of 11

jbooth
Advocate
Advocate
FYI: These kind of functions (like GetDistAtParam) are only available in LISP or ObjectARX, so you will not find them available in the AutoCAD COM libraries (VBA).
0 Likes
Message 9 of 11

Anonymous
Not applicable
Type (vl-load-com) in the command line before
or pass the same in .SendCommand

~'J'~
0 Likes
Message 10 of 11

Anonymous
Not applicable
Thanks for all your help. Here's my final code that works perfectly to get the length of a spline:

If TypeOf ssobject Is AcadSpline Then
Set MySpline = ssobject
MyLineType = MySpline.Linetype
'THIS SCRIPT SENDS IN PARAMS and calls A LISP FUNCTION TO CALCULATE THE LENGTH OF A SPLINE
'WASNT ABLE TO FIND LENGTH W/ VBA SO HAD TO MAKE CALL LISP FUNCTION vlax-curve-getdistatparam to get it.
With ThisDrawing
ThisDrawing.SetVariable "USERR1", sVar
'load lisp
.SendCommand "(vl-load-com)" & vbCr
'call lisp function and pass in params. return length of spline
strCom = "(setvar " & Chr(34) & "USERR1" & Chr(34) & Chr(32) & "(vlax-curve-getdistatparam (vlax-ename->vla-object (handent " & Chr(34) & ssobject.Handle & Chr(34) & ")) (vlax-curve-getendparam (vlax-ename->vla-object (handent " & Chr(34) & ssobject.Handle & Chr(34) & ")))))" & vbCr
.SendCommand strCom
MyLineLength = .GetVariable("USERR1")
End With
End if
Message 11 of 11

Anonymous
Not applicable
Happy computing 🙂

~'J'~
0 Likes