Author Topic: Data list manipulation  (Read 5510 times)

0 Members and 1 Guest are viewing this topic.

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.