Author Topic: Solved - Need help to extract data from set of lines  (Read 306 times)

0 Members and 1 Guest are viewing this topic.

nekonihonjin

  • Newt
  • Posts: 47
Solved - Need help to extract data from set of lines
« on: August 02, 2022, 02:54:46 PM »
Howdy guys, I would like to automate the extract data command to get the length and angle with respect to horizontal, of a bunch of lines and at the end of the table the sum of those lengths, I just don't even know where to start.
Attached is a file with what I need,
« Last Edit: August 04, 2022, 10:50:49 AM by nekonihonjin »

BIGAL

  • Swamp Rat
  • Posts: 1037
  • 40 + years of using Autocad
Re: Need help to extract data from set of lines
« Reply #1 on: August 03, 2022, 01:07:38 AM »
A couple of questions are the lines always 1- x etc, where they drawn in that order 1 -> 16, just means just pick lines and start at a number eg 1.

Code: [Select]
; http://www.theswamp.org/index.php?topic=57753.0
; simple table example lines to table
l By AlanH Aug 2022

(defun rtd (a)
(/ (* a 180.0) pi)
)

(defun pl-table ( / ss sp curspace tableobj k totlen x len ang rownum)
(setq ss (ssget (list (cons 0 "LWPOLYLINE"))))

(setq sp (vlax-3d-point (getpoint "\nPick point for top left of table ")))

(Setq curspace (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))))
(setq tableobj (vla-addtable curspace sp 2 3 1 25))
(vla-settext tableobj 0 0 "Heading")
(vla-settext tableobj 1 0 "No.")
(vla-settext tableobj 1 1 "Length")
(vla-settext tableobj 1 2 "Angle")

(setq k 0 totlen 0.0)
(repeat (setq x (sslength ss))
  (setq obj (vlax-ename->vla-object (ssname ss (setq x (1- x)))))
  (setq totlen (+ totlen (vlax-get obj 'Length)))
  (setq len (strcat (rtos (vlax-get obj 'Length) 2 2) " m"))
  (setq ang (rtd (angle (vlax-curve-getstartPoint obj)(vlax-curve-getEndPoint obj))))
  (if (> ang 180.0)
    (setq ang (rtos (- ang 360.0) 2 0))
    (setq ang (rtos ang 2 0))
  )
  (setq tableobj (vlax-ename->vla-object (entlast)))
  (setq rownum (vla-get-rows tableobj))
  (vla-InsertRows tableobj  rownum  (vla-GetRowHeight tableobj (- rownum 1)) 1)
  (vla-settext tableobj rownum 0 (rtos (setq K (1+ k)) 2 0))
  (vla-settext tableobj rownum 1 len)
  (vla-settext tableobj rownum 2 ang)
)

(setq tableobj (vlax-ename->vla-object (entlast)))
(setq rownum (vla-get-rows tableobj))
(vla-InsertRows tableobj  rownum  (vla-GetRowHeight tableobj (- rownum 1)) 1)
(vla-settext tableobj rownum 0  "Total")
(vla-settext tableobj rownum 1 (strcat (rtos totlen 2 0) " m"))

(princ)
)
(pl-table)

When it asks to select object type F and can drag lines over your red lines, press enter twice to end selection, then pick a point.
« Last Edit: August 03, 2022, 01:56:00 AM by BIGAL »
A man who never made a mistake never made anything

nekonihonjin

  • Newt
  • Posts: 47
Re: Need help to extract data from set of lines
« Reply #2 on: August 03, 2022, 11:04:49 AM »
Exactly what I needed Bigal, Thanks!

don't know what you mean with lines always 1- x

they were drawn in that order from 1 to 16, it's ok if I have to select lines one by one to make sure that the order matches the text number.



the little I know about it, I can change the lines that have the --- rtos (/lenght/)  2 X ---  to increase-decrease decimals, to be able to get one decimal in the total lenght.   And it needed the defun with a c: for it to wait until I call it. I was able to modify that.

but it returns a reverse order, the first line I pick is the last one in the table, I don't know what line needs to be modified for this to be first pick-first row of table.



Edit:
it was not the case of the example, so I didn't check right on, but if lines points to the left  (-x) it should also be only 0° to 90° range  and 0° to -90° if below horizontal,
gonna try to modify this on my own, but I donīt have to much expectations  :cry2:

Code: [Select]
  (if (> ang 180.0)
    (setq ang (rtos (- ang 360.0) 2 0))
    (setq ang (rtos ang 2 0))
  )


Edit2:

I did this for the angle thing,
Code: [Select]
    (if (> ang 270.0)
    (setq ang (rtos (+ -360 ang) 2 0))
    (  if (> ang 90.0)
    (setq ang (rtos (- 180 ang) 2 0))
    (setq ang (rtos ang 2 0))
  )

still no idea how to invert the order of the table items.
« Last Edit: August 03, 2022, 12:11:09 PM by nekonihonjin »

BIGAL

  • Swamp Rat
  • Posts: 1037
  • 40 + years of using Autocad
Re: Need help to extract data from set of lines
« Reply #3 on: August 03, 2022, 10:02:18 PM »
The list of lines was reversed at one stage I think has something to do with the order they were created in, I did not check to hard. There is a couple of ways to process the selection set can work from 1st item or last item backwards. It may also be select order ie top -> bot or bot -> top did not check when using fence.

(repeat (setq x (sslength ss))
  (setq obj (vlax-ename->vla-object (ssname ss (setq x (1- x)))))

(setq x -1)
(repeat (sslength ss)
  (setq obj (vlax-ename->vla-object (ssname ss (setq x (1+ x)))))

Its like version 1 and your version 2 will be ok.
A man who never made a mistake never made anything

nekonihonjin

  • Newt
  • Posts: 47
Re: Need help to extract data from set of lines
« Reply #4 on: August 04, 2022, 01:12:31 AM »
I tested with similar sets of lines but created in different order, same result.

It is the order in which they are selected.

Code: [Select]
(setq x -1)
(repeat (sslength ss)
  (setq obj (vlax-ename->vla-object (ssname ss (setq x (1+ x)))))

This solved it, thanks a lot Bigal.


BIGAL

  • Swamp Rat
  • Posts: 1037
  • 40 + years of using Autocad
Re: Solved - Need help to extract data from set of lines
« Reply #5 on: August 04, 2022, 07:52:45 PM »
Glad to hear its working, its like a lot of stuff I do "pick left to right" but if in a circle fashion can be actually right to left, think bottom section of rectang.
A man who never made a mistake never made anything