Author Topic: mline length  (Read 4905 times)

0 Members and 1 Guest are viewing this topic.

JB

  • Guest
mline length
« on: March 09, 2004, 12:08:29 AM »
Is there a way to get the length on an Mline in vLisp?
Thanks Jamie :D

SMadsen

  • Guest
mline length
« Reply #1 on: March 09, 2004, 12:59:31 PM »
Gotta have a closer look at MLINE's .. but here's some quick stuff to start on:

Code: [Select]
(defun mllength (mline / entl a dist plst)
  (cond ((= (type mline) 'ENAME)
         (setq entl (entget mline)
               a    0
               dist 0
         )
         (foreach n entl
           (if (member (car n) '(10 11))
             (setq plst (cons (cdr n) plst))
           )
         )
         (repeat (1- (length plst))
           (setq dist (+ dist (distance (nth a plst) (nth (1+ a) plst)))
                 a (1+ a))
         )
        )
  )
  (setq mlst plst)
  dist
)

JB

  • Guest
mline entity
« Reply #2 on: March 12, 2004, 03:32:37 PM »
I think the problem lies in the entity statement.
An "mline" only has one point the start point.
Any more sugestions would be appreciated.
Thanks !
Jamie :)

SMadsen

  • Guest
mline length
« Reply #3 on: March 12, 2004, 03:37:38 PM »
Huh?

JB

  • Guest
mline length
« Reply #4 on: March 12, 2004, 03:48:48 PM »
I mean if you do a list on an mline, it gives you 2 3d points. But if you try to extract the information thru entity, it only finds one point. It is always the start or last point of the mline. I could not make the assoc list with the  entity. It only finds one point of the mline.
Make any since?
I have used someone elses code (thanks a bunch) for the start of this program. Here is the "lsum" code modified. This is a great way to get a total on many things, But you can not use it on Mline.
Any suggestions?

Code: [Select]

(defun C:linesumtest ()
  (setq sset (ssget '((0 . "MLINE"))))
  (if sset
    (progn
      (setq tot 0.0)
      (setq num (sslength sset) itm 0)
      (while (< itm num)
        (setq hnd (ssname sset itm))
        (setq ent (entget hnd))
        (setq pt1 (cdr (assoc 10 ent)))
        (setq pt2 (cdr (assoc 11 ent)))
        (setq dis1 (distance pt1 pt2))
        (setq newdis (+ dis1 0.25))
        (setq dis (fix newdis))
        (print (strcat "\nTotal Distance = " (rtos dis)))
        (setq tot (+ tot dis))
        (setq itm (1+ itm))
      )
      (princ (strcat "\nTotal Distance = " (rtos tot)))
    )
  )

DEVITG

  • Bull Frog
  • Posts: 480
mline length
« Reply #5 on: March 12, 2004, 06:29:24 PM »
Hi JB you miss the last ")"

But then it works , not as you want .

The problem is that a MLINE has two 11 in the entity list , see

Quote


((-1 . <Entity name: 400b5d58>) (0 . MLINE) (330 . <Entity name: 400b5cf8>) (5
. 2B) (100 . AcDbEntity) (67 . 0) (410 . Model) (8 . 0) (100 . AcDbMline) (2 .
STANDARD) (340 . <Entity name: 400b5cc0>) (40 . 20.0) (70 . 0) (71 . 1) (72 .
2) (73 . 2) (10 46.9202 164.76 0.0) (210 0.0 0.0 1.0) (11 46.9202 164.76 0.0) (12 0.993089 -0.117364 0.0) (13 0.117364 0.993089 0.0) (74 . 2) (41 . 0.0) (41
. 0.0) (75 . 0) (74 . 2) (41 . -20.0) (41 . 0.0) (75 . 0) (11 362.23 127.497
0.0)
(12 0.993089 -0.117364 0.0) (13 0.117364 0.993089 0.0) (74 . 2) (41 . 0.0)
(41 . 0.0) (75 . 0) (74 . 2) (41 . -20.0) (41 . 0.0) (75 . 0))



You can see it in  BOLD
And from a LIST command you have  

Quote
Command: _list
Select objects: 1 found

Select objects:

                  MLINE     Layer: "0"
                            Space: Model space
                   Handle = 2B

Justification = Top, Scale = 20.00, Style = STANDARD
Vertex 0: X=  46.9202  Y= 164.7604  Z=   0.0000

Vertex 1: X= 362.2304  Y= 127.4970  Z=   0.0000


So the second "11" is the pt2 you need to get .

I do not know how to do it , but sure you will .
Please letme know how do you cope it. :D

I will post the dwg I use on the lilly pond
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
mline length
« Reply #6 on: March 12, 2004, 08:45:15 PM »
JB,

You are mistaken, the code works as expected. :shock:

Try it with the test function I supplied.
I think you may not have fed the routine the ename.

CAB

PS, an observation, it appears that code 10 and the
first code 11 are the same point.
It does not impact the routine.


Code: [Select]
(defun mllength (mline / entl a dist plst)
  (cond ((= (type mline) 'ENAME)
         (setq entl (entget mline)
               a    0
               dist 0
         )
         (foreach n entl
           (if (member (car n) '(10 11))
             (setq plst (cons (cdr n) plst))
           )
         )
         (repeat (1- (length plst))
           (setq dist (+ dist (distance (nth a plst) (nth (1+ a) plst)))
                 a (1+ a))
         )
        )
  )
  (setq mlst plst)
  dist
)
(defun c:test(/ ml)
  (if (setq ml (entsel))
    (if (= (cdr(assoc 0 (entget (setq ml(car ml))))) "MLINE")
      (print (mllength ml))
      (prompt "\nObject was not an mline.")
    )
    (prompt "\nNothing selected.")
  )
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

JB

  • Guest
mline length
« Reply #7 on: March 15, 2004, 09:34:48 AM »
Thanks to everyone for your input.
I will post the final when I get to it.
CAB has the right answer, I do not fully understand how it all works, But I am working on it in my down time. I was not using "test". Once I tried test it gave me the correct answer.
It is appreciated!  Jamie:-).