Author Topic: Data list manipulation  (Read 5527 times)

0 Members and 1 Guest are viewing this topic.

noadea

  • Guest
Data list manipulation
« on: April 16, 2007, 05:49:21 AM »
Hi All,
I have a problem to manipulate the data list. Here are example of data in csv format:
1   1
2   -
3   -
4   -
5   4
6   5
7   6
8   -
9   7
10   8
11   -
12   -
13   10

From the data list, i suppose to draw line according to data by row. For better understanding, I attached the roughly drawing to describe my need. If refer to data square1 connect to circle1, square5 to circle4, square6 to circle5... But the problem here is the circles with "-" value in csv file. Example square2, square3 and square4 which connect to 3 different points between circle1 and circle4. How to get the  different points refer to the total of "-" at the time? (3 points between circle1 and circle4, 1 point between circle6 and circle7, 2 points between circle8 and circle10). Then the line should be drawn from square to point according to data in row. Thanks.



It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8746
  • AKA Daniel
Re: Data list manipulation
« Reply #1 on: April 16, 2007, 05:57:37 AM »
Got any code so we can see what you have so far?

noadea

  • Guest
Re: Data list manipulation
« Reply #2 on: April 16, 2007, 06:54:21 AM »
Here I attached the code that I  have for this moment.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Data list manipulation
« Reply #3 on: April 16, 2007, 07:18:05 AM »
For thoses interestd, here is the original thread:
http://forums.augi.com/showthread.php?t=58847
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.

noadea

  • Guest
Re: Data list manipulation
« Reply #4 on: April 17, 2007, 03:06:28 AM »
This problem is outside of my programming level. I hope there are experts would help me solve this problem. Thank you.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Data list manipulation
« Reply #5 on: April 17, 2007, 05:45:00 AM »
Where is the datalist for a sampling of squares and circle locations ?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Data list manipulation
« Reply #6 on: April 17, 2007, 05:52:06 AM »
Is the connection pattern different each time ?

Do you have a sample csv file ?

Do you have a sample drawing file. ?

at least give us ALL the information.

How many of these are you doing. ?

Is it a school project ?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

noadea

  • Guest
Re: Data list manipulation
« Reply #7 on: April 17, 2007, 07:30:28 AM »
Here are sample of drawing and csv file.
« Last Edit: April 17, 2007, 07:31:58 AM by noadea »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Data list manipulation
« Reply #8 on: April 17, 2007, 07:32:38 AM »
Good questions Kerry, I hope we get the answers.
I had very little time yesterday & less time today. :(
But here is what I started with. An assumption about the data list from the cvs file.
Then several hoops to get the data in a usable form.
I was about to replace the nil values according to the specifications when time ran out.
So here is what I have so far. Maybe tomorrow will be better for me. :?

Code: [Select]
(defun c:test ()
  ;;  given output from CVS file
  (setq output '("5,23,27,24"      "5,22,-,-"        "5,21,-,-"
                 "5,20,-,-"        "5,19,29,19.5"    "5,18,30,17.75"
                 "5,17,30,16.5"    "5,16,-,-"        "5,15,30,15"
                 "5,14,30,13"      "5,13,-,-"        "5,12,-,-"
                 "5,11,30,10"
                )
  )

  ;;===========================
  ;;  parser by CAB single character delim
  (defun sparser (str delim / ptr lst)
    (while (setq ptr (vl-string-search delim str))
      (setq lst (cons (substr str 1 ptr) lst))
      (setq str (substr str (+ ptr 2)))
    )
    (reverse (cons str lst))
  )
 
  ;; CAB 05/07/06
  ;;  group on the first two elements  A B of a flat list A B C D
  ;;  InpLst is the flat list ((A B) (C D) (E F)...)
  (defun group_on2 (InpLst / OutLst tmp grp idx sub)
    (while InpLst
      (setq OutLst (cons (list (car InpLst) (cadr InpLst)) OutLst))
      (setq InpLst (cddr InpLst))
    )
    (reverse OutLst)
  )


 
  ;; create a list of list with 4 items in each sub list
  (setq lst (apply 'append (mapcar '(lambda (x) (sparser x ",")) output)))
  ;;  convert to numbers
  (setq lst (mapcar '(lambda (x)(if (numberp (read x))(read x))) lst))
  ;;  group in pairs
  (setq lst (group_on2 (group_on2 lst)))
  ;;  Replace nil points
  ;| -=< Under Construction  >=-
  (setq idx 0)
  (while (< idx (length lst))
    (cond
      ((null stpt) (setq stpt (nth idx lst)))
      ((null (cadr (nth idx lst)))
      )
    )
  )
|;

 
  (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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Data list manipulation
« Reply #9 on: April 17, 2007, 07:40:10 AM »
Oops, see there, I guessed wrong on the data. :-( The groups of 4 are reversed & there is an index number.
From CVS file:
Code: [Select]
("56,-,-0.62766,0.19281"
  "55,-,-0.71186,0.19281"   "54,-,-0.33241,0.69237"
  "53,-,-0.41661,0.69237"   "52,-,-0.50081,0.69237"
  "51,-,-0.83871,0.69237"   "50,-,-0.92291,0.69237"
......................
 )
Looks like this "56,-,-0.62766,0.19281" needs to be decoded to
 this  (0.19281  -0.62766)  (nil nil)   which are two points.
 
 Gotta go..
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.

noadea

  • Guest
Re: Data list manipulation
« Reply #10 on: April 17, 2007, 09:52:29 AM »
FYI
Regarding to the data in csv file:
column A : number according to square
column B : number according to circle
column C : x-coordinate of square's centre point
column D : y-coordinate of square's centre point

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Data list manipulation
« Reply #11 on: April 17, 2007, 12:48:34 PM »
This does not match the drawing.
From the CVS file:
Code: [Select]
1   1    -1.4668   1.1332
 From the Drawing, Pad 1
Code: [Select]
                   BLOCK REFERENCE  Layer: "Pad"
                            Space: Model space
                   Color: 6 (magenta)    Linetype: "Continuous"
                   Handle = 326F
                  "GDM7211_VCO_TEST.Pad"
                at point, X=0'-8 9/16"  Y=0'-1 19/32"  Z=    0'-0"
                 X scale factor   1.00000
                 Y scale factor   1.00000
          rotation angle 0.0000
                 Z scale factor   1.00000
                 
Note that x = 8.5625   y = 1.59375
Why the discrepancy?
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.

Fatty

  • Guest
Re: Data list manipulation
« Reply #12 on: April 17, 2007, 04:59:03 PM »
Alan, those coordinates are relative to
center of detail (to the crosshair)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Data list manipulation
« Reply #13 on: April 17, 2007, 05:09:30 PM »
Oh, thanks Fatty.
I never would have guessed. :?

So that means we are only interested in column A & B.
In the original post I thought the data file contained points for A & B but as we see now they contain text labels.

« Last Edit: April 17, 2007, 05:15:28 PM by CAB »
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.

Fatty

  • Guest
Re: Data list manipulation
« Reply #14 on: April 18, 2007, 08:23:38 AM »
Oh, thanks Fatty.
I never would have guessed. :?

So that means we are only interested in column A & B.
In the original post I thought the data file contained points for A & B but as we see now they contain text labels.


Alan,
I've tried to solve ir entire last weekend
with no luck
Perhaps my poor brain is not in the good
condition at the moment :-)

~'J'~

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Data list manipulation
« Reply #15 on: April 18, 2007, 10:21:38 AM »
OK, I think I understand the goal. That is often 90 percent of the battle.

I am out of time again today, but this is where I ended up.
Still needs work AND I am not sure the CVS data is correct.
Why is 5 connected to 4?  ("5" "4" "-1.4668" "0.3832")
And 14 connected to 11?  ("14" "11" "-0.9832" "-1.4668")


<edit: usless code removed>
« Last Edit: April 19, 2007, 10:36:50 AM by CAB »
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.

noadea

  • Guest
Re: Data list manipulation
« Reply #16 on: April 18, 2007, 11:40:42 PM »
The idea is there already. The csv file is correct.
If you run my code on that drawing, you will get like in tst1.dwg.
But I want it be like tst2.dwg.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Data list manipulation
« Reply #17 on: April 18, 2007, 11:58:43 PM »
Ah, the mystery unfolds.  8-)
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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Data list manipulation
« Reply #18 on: April 19, 2007, 12:28:25 AM »


Ah, the mystery unfolds.  8-)

Yeah, I gave up cause getting information was worse than pulling teeth.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

noadea

  • Guest
Re: Data list manipulation
« Reply #19 on: April 19, 2007, 03:03:12 AM »
This is the new attempt.
But still got wrong somewhere cause there are several points which are wrong connection then also not connected. Please help correct it. Thanks.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Data list manipulation
« Reply #20 on: April 19, 2007, 10:35:46 AM »
Needs error checking, but worked in my test.
Code: [Select]
(defun strlist (strexp strdel / itm )
  (setq strlst nil)
  (while (setq pos (vl-string-position (ascii strdel) strexp))
    (setq itm (substr strexp 1 pos))
    (setq strlst (append strlst (list itm)))
    (setq strexp (substr strexp (+ pos 2)))
  )
  (setq strlst (append strlst (list strexp)))
)

;(defun read-csv ( / rdlst output)
(defun read-csv ()
(setq output nil
      rdlst nil)
  (setq fname (getfiled "Select a .csv file :" (getvar "dwgprefix") "csv" 16))
  (setq fname (open  fname  "r"))
  (while
  (setq rdlst (read-line fname))
  (setq output (cons rdlst output))
  ):end while
  (close fname)
  (mapcar (function (lambda (x)(strlist x ",")))
  (reverse output)
  )
)
(defun c:oln1a()
(setq OldOsmode (getvar "OSMODE"))
(setvar "OSMODE" 0)
(setq adoc (vla-get-activedocument (vlax-get-acad-object))acsp (vla-get-block (vla-get-activelayout adoc)))
(setq data (read-csv))
(setq CutObject (vlax-ename->vla-object (car (entsel "\nSelect Ground Bond Line...."))))
(setq CVSdata ;= list csv (including gl's)
       (mapcar (function (lambda(x)
    (list (car x)
  (cadr x)
             )))
data));end setq CVSdata

;get all squares
(setq Squaretxtlst nil)
(setq st (ssget "_X" (list (cons 0 "INSERT")(cons 8 "Pad"))))
(vlax-for a (vla-get-activeselectionset adoc)
(vla-GetBoundingBox a 'MinPnt 'MaxPnt)
(setq SquareInsPnt (vlax-get a 'InsertionPoint))
(setq MinPt (vlax-safeArray->list minPnt))
(setq MaxPt (vlax-safeArray->list maxPnt))
 
(vl-cmdf "._zoom" "_E")  ; needed for ssget _W, will not work if not visiable on screen

(setq SquareTxt (cdr (assoc 1 (entget (ssname  (ssget "_W" minPt maxPt '((0 . "TEXT")))0)))))
(setq SquareTxtLst (append SquareTxtLst (list (cons (atoi SquareTxt) SquareInsPnt ))))
);end vlax-for

(setq CircleTxtLst nil)
(setq sc (ssget "_X" (list (cons 0 "CIRCLE")(cons 8 "Tag"))))
(vlax-for a (vla-get-activeselectionset adoc)
  (setq ip (vlax-get a 'Center))
  (setq rad (vlax-get a 'Radius))
  (setq p1 (list (- (car ip)(* rad 3))(- (cadr ip)(* rad 3)))
    p2 (list (+ (car ip)(* rad 3))(+ (cadr ip)(* rad 3)))
    cp (list (car ip)(cadr ip) 0.0)
  )
(setq txtstr (cdr (assoc 1 (entget (ssname  (ssget "_W" p1 p2 '((0 . "TEXT"))) 0)))))
(setq CircleTxtLst (append CircleTxtLst (list (cons (atoi txtstr) ip))))
);end vlax for


(setq count 0) ; nth pointer
(setq datalen (1- (length  CVSdata)))
(while (< count datalen)
   (if (not (vl-position (cadr(nth count CVSdata)) '("GL" "-")))
     
     ;;  Add a Wire
       (progn   ; no GL found         
           (setq SqPointer (atoi (car(nth count CVSdata))))
           (setq CirPointer (atoi (cadr(nth count CVSdata))))
           (setq lnobj (vlax-invoke acsp 'AddLine (cdr (assoc SqPointer Squaretxtlst))(cdr (assoc CirPointer circletxtlst))))
           (vlax-put lnobj 'Layer "Wire")
           (setq count (1+ count))
       );end progn no GL found
     
     ;;  Else Add Ground Wire
       (progn   ; GL found         
          (setq SqPointer (atoi (car(nth count CVSdata))))
          (if CirPointer
            (setq  CirPnt1 CirPointer) ;CirPointer = last known used circle
            (setq  CirPnt1 1)
          )
         ;;  find next valid Wire
          (setq  CirPnt2 (1+ count))       
          (while (vl-position (cadr(nth CirPnt2 CVSdata)) '("GL" "-"))
            (setq  CirPnt2 (1+ CirPnt2))
          )
          (if (< CirPnt2 (length CVSdata))
            (progn
            (setq  CirPnt2 (atoi (cadr (nth CirPnt2 circdata))))
          (setq pt1 (cdr (assoc CirPnt1 circletxtlst))
                pt2 (cdr (assoc CirPnt2 circletxtlst)))
          (setq ang (angle pt1 pt2))
          (setq stepcnt (- CirPnt2 CirPnt1))
          (setq stepdis (/ (distance pt1 pt2) (+ stepcnt 1)))
          ;;  Create the Ground Wire(s)
          (setq idx 1)
          (repeat stepcnt       
            (setq Cutlnobj (vlax-invoke acsp 'AddLine (cdr (assoc SqPointer Squaretxtlst))
                                                    (polar pt1 ang (* stepdis idx))
                         )
            )                         
            (setq InterSect (vlax-invoke CutLnObj "intersectwith" CutObject acextendnone))
            (vla-delete Cutlnobj)
            (setq lnobj (vlax-invoke acsp 'AddLine InterSect (cdr (assoc SqPointer Squaretxtlst))))
            (vlax-put lnobj 'Layer "Wire GB")
            (setq idx (+ idx 1))
            (setq SqPointer (+ SqPointer 1))
          )
          (setq count (+ count (1- idx)))
            )
            (setq count (length  CVSdata))
          )
       );end progn GL found
   );end and

);end while

(setvar "OSMODE" OldOsmode)
);end defun
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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Data list manipulation
« Reply #21 on: April 20, 2007, 09:07:37 AM »
noadea,
I see you were here last night. No comment though.
Did the routine work for you as you desired?
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.

noadea

  • Guest
Re: Data list manipulation
« Reply #22 on: April 23, 2007, 02:14:15 AM »
Hi CAB,
It works fine on that csv file. But it doesn't work on the csv file that has 'GL' value in the first line of the data. For example if using this attached csv file. Anyway thanks a lot for your help.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Data list manipulation
« Reply #23 on: April 23, 2007, 08:17:43 AM »
OK, I fixed that, but another problem cropped up.

What signals the end of the squares? In this example I assume #48 is the last square to received a wire. How do you know that?
What is the difference between "GL" and "-"?
Guessing, "GL" is Ground Lead & "-" is No Connection.
« Last Edit: April 23, 2007, 08:19:04 AM by CAB »
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.

noadea

  • Guest
Re: Data list manipulation
« Reply #24 on: April 23, 2007, 10:40:27 PM »
Yes, you're right.
"-" means no connection.