TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Amsterdammed on October 10, 2005, 10:41:32 AM

Title: length of a 3dpoly
Post by: Amsterdammed on October 10, 2005, 10:41:32 AM
Hello there,

Who can i get the length of a 3dpoly?

Thanks, Bernd
Title: Re: length of a 3dpoly
Post by: MP on October 10, 2005, 10:45:52 AM
Forgive me, but did you look at the length property?
Title: Re: length of a 3dpoly
Post by: Mark on October 10, 2005, 11:12:44 AM
Forgive me, but did you look at the length property?

Something like this?

Code: [Select]
(if (setq ent (car (entsel)))
  (progn
    (setq obj (vlax-ename->vla-object ent))
    (if (vlax-property-available-p obj 'Length)
      (print (strcat (rtos (vlax-get-property obj 'Length)) " = Length"))
      )
    )
  )
Title: Re: length of a 3dpoly
Post by: MP on October 10, 2005, 11:29:51 AM
That would work. :)

So many ways to skin the cat (Tracey made me say it). Here's a very simple variant ...

Code: [Select]
(defun c:SumLengths ( / getlen ss i result )
    (defun getlen ( ename / result )
        (vl-catch-all-apply
           '(lambda ( )
                (setq result
                    (vla-get-length
                        (vlax-ename->vla-object ename)
                    )
                )   
            )
        )
        (if result result 0.0)
    )
    (if (setq result 0.0 ss (ssget))
        (repeat (setq i (sslength ss))
            (setq result
                (+
                    (getlen (ssname ss (setq i (1- i))))
                    result
                )
            )
        )
    )
    result
)

You can go a lot deeper with the vlax-curve-* functions as has been demonstrated elsewhere on le swamp.
Title: Re: length of a 3dpoly
Post by: LE on October 10, 2005, 11:35:17 AM
Command: lengthen
Select an object or [DElta/Percent/Total/DYnamic]:
Current length: 7.9172
Title: Re: length of a 3dpoly
Post by: jonesy on October 10, 2005, 11:39:11 AM
That would work. :)

So many ways to skin the cat (Tracey made me say it). Here's a very simple variant ...

Did not ^-^ :angel:
Title: Re: length of a 3dpoly
Post by: t-bear on October 10, 2005, 12:13:56 PM
I like that LE ... sticking with the programs basic functions for the solution......... Saves writing a bunch of silly code thingies.  :ugly:(although that IS what this forum is all about, right?  Writing silly little code thingies?  The kind T-Bear can't live without?)......... :angel: :lmao:
Title: Re: length of a 3dpoly
Post by: Amsterdammed on October 11, 2005, 03:17:02 AM
Michael,

I was already out of office when you posted
Yes I tought the ‘Length property must do it.

But when I run

Code: [Select]
  (vlax-get-property (vlax-ename->vla-object (entlast)) 'Length)
 
 
I get
Quote
  ActiveX Server returned the error: unknown name: LENGTH
 

Although when I inspect the
Code: [Select]
  (vlax-ename->vla-object (entlast))

I get in the inspect window

(wanted to paste in here)
i get
Quote
  Acad3Dpolyline
 

in the header

If i do the same with a normal line, i get the length property.


That was when I posted it to the swamp.

Marks post gives nil as a result and yours 0.0
I use Acad 2002, but that should not be it.


Thanks in advance

Bernd
Title: Re: length of a 3dpoly
Post by: Amsterdammed on October 11, 2005, 03:23:45 AM
Of course Luis approach works, but i need the length in a calculation, not on the printscreen.
Title: Re: length of a 3dpoly
Post by: Kerry on October 11, 2005, 03:58:52 AM
The vla-curve stuff is available with AC2002

So ... try something like this perhaps
Code: [Select]
(if (and (setq obj (vlax-ename->vla-object (car (entsel))))
         (= (vla-get-objectname obj) "AcDb3dPolyline")
    )
  (setq len (vlax-curve-getdistatparam obj (vlax-curve-getendparam obj)))
)
Title: Re: length of a 3dpoly
Post by: Kerry on October 11, 2005, 04:02:45 AM
Quote
I use Acad 2002, but that should not be it.

You think ??

Yes it could .. The Length Property became available for stuff other than lines in AC2004.

Have a look at the properties of a 3DPline in the Object Model Diagram ..


[added]
.. and just goes to show that it helps to mention which version of Autocad we are using ...
Title: Re: length of a 3dpoly
Post by: Kerry on October 11, 2005, 04:18:32 AM
should have mentioned ..

If you change the ObjectName test to suit, this should work for
Polylines, 3DPolylines, Splines, Lines, Arcs, Circles and Ellipses
Title: Re: length of a 3dpoly
Post by: Amsterdammed on October 11, 2005, 05:42:23 AM
Thanks Kerry

Right in all cases.
Your approach works perfectly.

And I added my Acad version to my profile………..

You saved my ass, again,

Thanks a lot

Bernd
 
 :-D
Title: Re: length of a 3dpoly
Post by: Kerry on October 11, 2005, 05:52:31 AM
My pleasure.

BTW. Saving a$$ is part of my job description. I have a cardboard box in my office, almost full.
Title: Re: length of a 3dpoly
Post by: Amsterdammed on October 11, 2005, 05:54:06 AM
Noo doubt  : :-)
Title: Re: length of a 3dpoly
Post by: LE on October 11, 2005, 09:10:10 AM
I like that LE ... sticking with the programs basic functions for the solution......... Saves writing a bunch of silly code thingies.  :ugly:(although that IS what this forum is all about, right?  Writing silly little code thingies?  The kind T-Bear can't live without?)......... :angel: :lmao:

Yes... but now that I am reading what OP was looking for, the LENGHTHEN command is not handy for this case...