Getting Polyline Lengths with VBA?

Getting Polyline Lengths with VBA?

Anonymous
Not applicable
624 Views
4 Replies
Message 1 of 5

Getting Polyline Lengths with VBA?

Anonymous
Not applicable
Can anyone help with this....?
How do I get the total length of 5 different polylines on a layer and place
the total in a listboax?

-Thanks in advance....Sean
0 Likes
625 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
Have a look at Curve.cls. It requires VLAX.cls and you can
get a free copy of both (with source) in the Downloads
section of my site. The Curve class offers a Length
property.

--
http://www.acadx.com


"Sean Jman" wrote in message
news:1E83E01414306061D4EFDABF1BB35281@in.WebX.maYIadrTaRb...
> Can anyone help with this....?
> How do I get the total length of 5 different polylines on
a layer and place
> the total in a listboax?
>
> -Thanks in advance....Sean
>
>
0 Likes
Message 3 of 5

Anonymous
Not applicable
could you tell me in a nutshell, how to use the vlax/curve.cls? with a
simple VBA dialog box?

"Frank Oquendo" wrote in message
news:B89C4CBD7858DF2B9413555C1857318D@in.WebX.maYIadrTaRb...
> Have a look at Curve.cls. It requires VLAX.cls and you can
> get a free copy of both (with source) in the Downloads
> section of my site. The Curve class offers a Length
> property.
>
> --
> http://www.acadx.com
>
>
> "Sean Jman" wrote in message
> news:1E83E01414306061D4EFDABF1BB35281@in.WebX.maYIadrTaRb...
> > Can anyone help with this....?
> > How do I get the total length of 5 different polylines on
> a layer and place
> > the total in a listboax?
> >
> > -Thanks in advance....Sean
> >
> >
>
>
0 Likes
Message 4 of 5

Anonymous
Not applicable
Without any details, I can't comment on the dialog part. However,
using VLAX is just like using any other class:

1) Declare a variable of type VLAX
2) Instantiate a VLAX object

Dim obj As VLAX
Set obj = New VLAX

As for the methods, EvalLispExpression can be used for a wide variety
of tasks. For example, I often use it to define an AutoLISP function
on the fly:

strLISP = "(defun test () (princ ""\nHello world!"") (princ))"
objEvalLispExpression strLISP

You can use it to execute an AutoLISP statement (subject to numerous
restrictions; read the notes):

obj.EvalLispExpression "(test)"

If your function returns an atom (not a list), you can receive that
output:

retval = obj.EvalLispExpression("(+ 2 4)")

If your function returns a list, execute it so that it sets a symbol
then read the symbol into a variant array:

obj.EvalLispExpression "(setq lst (mapcar '* '(2 3) '(3 4)))"
retval = obj.GetLispList "lst"

You can convert an array into an AutoLISP list as well:

Dim a(2) As Variant
a(0) = 2.5: a(1) = "String": a(2) = 3
obj.SetLispSymbol "lst", a

Now when you got the command prompt and type "!lst", you'll get:
(2.5 "String" 3)

Last but not least, use the NullifySymbol method to clean after
yourself. You can even use to undefine functions you defined
previously:

obj.NullifySymbol "test"

This is exactly the same as using EvalLispExpression:

obj.EvalLispExpression "(setq test nil)"

However, NullifySymbol can accept any number of arguments allowing you
to release several symbols at once.

Now as for Curve, declare and instantiate an object (just like with
VLAX). Then set the Entity property with your curve-derived object
(check the notes in Curve.cls):

Dim c As Curve

Set c = New Curve
Set c.Entity = myPolyline

In the above example, myPolyline is an entity you acquired somehow
(programmatically or through user interaction). All the methods are
just VLAX-wrapped calls to the various VLAX-CURVE functions which you
can look up in the VisualLISP online help.

One last note: before you can create a VLAX object, you must have
executed VL-LOAD-COM. The best way to do this is to add (vl-load-com)
to one of your startup files like ACAD2000.LSP or one of your MNL
files.

--
http://www.acadx.com


"Sean" wrote in message
news:364FFF0D43DC596F61FDDE8775F58A97@in.WebX.maYIadrTaRb...
> could you tell me in a nutshell, how to use the vlax/curve.cls? with
a
> simple VBA dialog box?
0 Likes
Message 5 of 5

Anonymous
Not applicable
thanks, i am trying but am newish to VBA and know nothing about lisp..
to simplify this, could you post the code to simply get the length of a
polyline with 5 vertices?
i need to place the Curve and VLAX classes in a class module right?
then i can place the references to them in the code in a form? the VLAX is
to access lisp functions and the Curve is for polylines right?
also, how do i add VL-LOAD-COM to an auto lisp?
thanks....sean

"Frank Oquendo" wrote in message
news:182E0479268491594C515AF5146A8075@in.WebX.maYIadrTaRb...
> Without any details, I can't comment on the dialog part. However,
> using VLAX is just like using any other class:
>
> 1) Declare a variable of type VLAX
> 2) Instantiate a VLAX object
>
> Dim obj As VLAX
> Set obj = New VLAX
>
> As for the methods, EvalLispExpression can be used for a wide variety
> of tasks. For example, I often use it to define an AutoLISP function
> on the fly:
>
> strLISP = "(defun test () (princ ""\nHello world!"") (princ))"
> objEvalLispExpression strLISP
>
> You can use it to execute an AutoLISP statement (subject to numerous
> restrictions; read the notes):
>
> obj.EvalLispExpression "(test)"
>
> If your function returns an atom (not a list), you can receive that
> output:
>
> retval = obj.EvalLispExpression("(+ 2 4)")
>
> If your function returns a list, execute it so that it sets a symbol
> then read the symbol into a variant array:
>
> obj.EvalLispExpression "(setq lst (mapcar '* '(2 3) '(3 4)))"
> retval = obj.GetLispList "lst"
>
> You can convert an array into an AutoLISP list as well:
>
> Dim a(2) As Variant
> a(0) = 2.5: a(1) = "String": a(2) = 3
> obj.SetLispSymbol "lst", a
>
> Now when you got the command prompt and type "!lst", you'll get:
> (2.5 "String" 3)
>
> Last but not least, use the NullifySymbol method to clean after
> yourself. You can even use to undefine functions you defined
> previously:
>
> obj.NullifySymbol "test"
>
> This is exactly the same as using EvalLispExpression:
>
> obj.EvalLispExpression "(setq test nil)"
>
> However, NullifySymbol can accept any number of arguments allowing you
> to release several symbols at once.
>
> Now as for Curve, declare and instantiate an object (just like with
> VLAX). Then set the Entity property with your curve-derived object
> (check the notes in Curve.cls):
>
> Dim c As Curve
>
> Set c = New Curve
> Set c.Entity = myPolyline
>
> In the above example, myPolyline is an entity you acquired somehow
> (programmatically or through user interaction). All the methods are
> just VLAX-wrapped calls to the various VLAX-CURVE functions which you
> can look up in the VisualLISP online help.
>
> One last note: before you can create a VLAX object, you must have
> executed VL-LOAD-COM. The best way to do this is to add (vl-load-com)
> to one of your startup files like ACAD2000.LSP or one of your MNL
> files.
>
> --
> http://www.acadx.com
>
>
> "Sean" wrote in message
> news:364FFF0D43DC596F61FDDE8775F58A97@in.WebX.maYIadrTaRb...
> > could you tell me in a nutshell, how to use the vlax/curve.cls? with
> a
> > simple VBA dialog box?
>
>
0 Likes