Jump to content

Divide list to parts


Trudy

Recommended Posts

Hello, 

I want to ask for help.

If i have list of points (startX1 X2 X3 X4 Xn EndXn StartX X X X X X EndX ....) --> StartX1 X2 X3 .. EndXn "all of the list is string" 

and i want to divide to different parts ((startX1 X2 X3 X4 Xn EndXn) (StartX X X X X X EndX))

 

Thank you :)

Edited by Trudy
Link to comment
Share on other sites

Post a true example '(start123 123 45 56 78 end78 start456 ……….. etc

 

The only way is if you do have something that can be found like "start". 

Link to comment
Share on other sites

Yes, please post a true example. don't make this a guessing game Trudy. I bet this will be easy.

 

Hows the Pontiac Bandit nowadays?

 

 

 

Edited by pBe
Link to comment
Share on other sites

PFB function that works as per your list and which doesn't limit the sub-list:

(defun foo (l / m n)
  (foreach x l
    (cond ((wcmatch (strcase x) "START*")
	   (if m
	     (setq n (cons (reverse m) n))
	   )
	   (setq m (list x))
	  )
	  (t (setq m (cons x m)))
    )
  )
  (if m
    (setq n (cons (reverse m) n))
  )
  (reverse n)
)

 

Program use:

_1$ (foo '("START" "X1" "X2" "X3" "X4" "XN" "ENDXN" "STARTX" "X" "X" "X" "X" "ENDX"))
(("START" "X1" "X2" "X3" "X4" "XN" "ENDXN") ("STARTX" "X" "X" "X" "X" "ENDX"))

_1$ (foo '("START" "X1" "X2" "X3" "X4" "XN" "ENDXN" "STARTX" "X" "X" "ENDX"))
(("START" "X1" "X2" "X3" "X4" "XN" "ENDXN") ("STARTX" "X" "X" "ENDX"))

_1$ (foo '("START" "X1" "X2" "X3" "X4" "X5" "X6" "XN" "ENDXN" "STARTX" "X" "X" "ENDX"))
(("START" "X1" "X2" "X3" "X4" "X5" "X6" "XN" "ENDXN") ("STARTX" "X" "X" "ENDX"))

 

  • Like 1
Link to comment
Share on other sites

Hello satishrajdev thank you for the lisp, work perfect this is what i looking for.
Sorry for late answer.

 

Its my fault for this missunderstanding because i dont explain all of my idea.

I am land surveyor and when we make some measures we can use codes "Description" and Start-first point of some fence or something else and i want to seperate them to different N X Y Z D from start to start.

The lisp of satishrajdev work perfect for that job.


Thank you all again :)

 

Link to comment
Share on other sites

30 minutes ago, Trudy said:

Its my fault for this missunderstanding because i dont explain all of my idea.

I am land surveyor and when we make some measures we can use codes "Description" and Start-first point of some fence or something else and i want to seperate them to different N X Y Z D from start to start.

 

 

The "Description" will throw off any code using a specific string like "START".  

Again, would it be too much to ask for an actual list ?

 

12 hours ago, satishrajdev said:

PFB function that works as per your list and which doesn't limit the sub-list:


(defun foo (l / m n)
  (foreach x l
...	     (setq n (cons (reverse m) n))
...    (setq n (cons (reverse m) n))
...  (reverse n)
)

 

 

All those call for reverse could;ve been easily avoided if you reverse the l argument 

 

==============================================================================

Another

(Defun BandOFPoint (lst / a l ls)
	(while lst
	  	(while (and
			 (setq a (car lst))
			 (setq l (cons a l) lst (cdr lst))
			 (not (vl-string-search "END" (strcase (car lst)))))
		  )
	  (setq ls (cons l ls) l nil)
	  )
  ls
  )
(Setq lst '("House" "X1" "X2" "X3" "X4" "XN" "ENDHouse" "Fence" "X" "X" "X" "X" "ENDofFence"))

_$ (BandOFPoint (reverse lst))
(("House" "X1" "X2" "X3" "X4" "XN" "ENDHouse") ("Fence" "X" "X" "X" "X" "ENDofFence"))

Also, depends on how you build the LIST, the code may not even need to REVERSE any of the list at all.

 

But then again. it would be nice if you post an actual list.

Edited by pBe
Link to comment
Share on other sites

This is the whole list of things

№            X                      Y                       Z                 D

100  4733186.330   317387.733      564.632     Fence
100  4733217.046   317428.400      564.038     MOGRO
101  4733183.268   317388.865      564.608     MOGRO
102  4733181.337   317390.940      564.549     MOGRO
103  4733181.313   317390.965      564.613     MOGRO
104  4733179.327   317392.687      564.579     MOGRO
105  4733186.197   317400.644      564.545     MOGRO
106  4733188.307   317399.158      564.492     MOGRO
107  4733188.348   317399.116      564.439     MOGRO
108  4733190.561   317397.557      564.475     MOGRO
109  4733193.414   317395.382      564.514     ENDofFence
110  4733193.427   317395.418      564.549     Fence
111  4733200.264   317404.989      564.348     MOGRO
112  4733198.562   317407.461      564.314     MOGRO
113  4733196.854   317409.046      564.295     MOGRO
114  4733196.826   317409.086      564.343     MOGRO
115  4733194.954   317410.919      564.412     MOGRO
116  4733202.781   317420.046      564.292     MOGRO
117  4733204.691   317418.281      564.226     MOGRO
118  4733204.725   317418.231      564.153     MOGRO
119  4733206.701   317416.397      564.164     MOGRO
120  4733208.683   317414.986      564.207     ENDofFence

 

MOGRO - is fence type from my country

i try this for now its not real fence but work for description code.

I want to create pline of all different things because manual is much slow.

 

Thank you for another solution pBe


 

Link to comment
Share on other sites

9 hours ago, Trudy said:

This is the whole list of things

№            X                      Y                       Z                 D

100  4733186.330   317387.733      564.632     Fence
100  4733217.046   317428.400      564.038     MOGRO
101  4733183.268   317388.865      564.608     MOGRO

....

 

 

I take it this was taken from an external file? .csv or .txt format, how were you able to generate the string list Trudy?

 

===================================================================================================

(Defun BandOFPoints (lst / a l ls)
(setq lst (reverse lst))
	(while lst
	  	(while (and
			 (setq a (car lst))
			 (setq l (cons a l) lst (cdr lst))
			 (numberp (read (car lst)))
			 )
		  )
	  (setq ls (cons l ls) l nil)
	  )
  ls
  )

(BandOFPoints lst)

same as before , reverse the list

That is why its important to establish the correct format so there would be no need to do so.

 

[edit] Answer  the question of generating the string list Trudy, we will build this up to the creation of the pline

 

Edited by pBe
Link to comment
Share on other sites

Its come from our Bulgarian program for calculation measurments but Yea its like a .txt  .

I create something about plines its little wooden but work.

I need this for group the different stuff.

 

(repeat (length MOGRO2) ;lenght of all different parts
(setq MOGRO2XY nil) ;X and Y for create polyline
(setq MOGRO3 (car MOGRO2)) ;First part of the whole
	(repeat (length (car MOGRO2)) ;lenght of first part
		(setq MOGRO2XY (cons (list (cadr (car MOGRO3)) (caddr (car MOGRO3))) MOGRO2XY))
		(setq MOGRO3 (cdr MOGRO3))
	)		; THE LISP FOR MAKE POLYLINE IS NOT MINE I FOUNT IT IN INTERNET BUT DONT KNOW WHERE 
	
	(ENTMAKE
     (APPLY
        (FUNCTION APPEND)
        (CONS (LIST '(0 . "LWPOLYLINE")
                    '(100 . "AcDbEntity")
                    '(67 . 0)
                    '(410 . "Model")
                    '(8 . "0")
                    ;; '(6 . "HIDDEN")              ; Linetype
                    ;;  (cons 62 acyellow)             ; Color
                    '(100 . "AcDbPolyline")
                    (CONS 90 (LENGTH MOGRO2XY))   ; Vertices
                    '(70 . 0)
                    ;'(70 . 1)                     ; Closed
              )
              (MAPCAR (FUNCTION LIST)
                      (MAPCAR (FUNCTION (LAMBDA (MOGRO2XY) (CONS 10 MOGRO2XY))) MOGRO2XY)                     
              )
        )
     )
  )
(setq MOGRO2 (cdr MOGRO)); with this i can get second part of whole file
)

 

Link to comment
Share on other sites

From the looks of it, You skipped  "№" , "Z"and "D", while "X" and "Y" are already as REAL numbers.

You did not post the part how the list [ MOGRO2 ] was created, I was hoping to start there. We can even use the "D" as the layer value for the "LWPOLYLINE".

 

But it appears you got it covered anyway Trudy, I will not even try to modify your code.

 

Have fun coding.

 

BTW: it IS  of equal length and can be easily group as Lee Mac suggested early on.

Edited by pBe
Link to comment
Share on other sites

Having been involved in commercial Civil Surveying software understand exactly what your after "stringing" based on Library codes. Do it wrong and get "Spagetti". Yes its in CIV3D or for me "Stringer" by Civil Survey Solutions, Carlson comes to mind also. Has been asked many times basically something for free.

 

A couple of hints do a double sort on point number and description. A field survey is as a rule done in some form of sequence hence the pline join points "MOGRO" 

 

For me the answer is in your coding adding a string number so a start and end is not required.

 

№            X                      Y                       Z                 D

100  4733186.330   317387.733      564.632     01MOGRO
100  4733217.046   317428.400      564.038     01MOGRO
101  4733183.268   317388.865      564.608     02MOGRO
102  4733181.337   317390.940      564.549     02MOGRO

 

the 01mogro will not join to 02mogro this is pretty standard field surveying technique. The image is just read survey data all done. There are so many options available using this method 01F*02F means a point where 2 fences join.

 

The "Library" of descriptions is important as it allows the MOGRO to go on the correct layer. A block insert would be say 00TREE5 that is a point the 00 and block "TREE5" and layer "Trees"

 

This is a typical numeric example

SS        ID=5003,    HA=105.21410, VA=87.40000, SD=35.146, HT=1.525, CO=626001
SS        ID=5004,    HA=131.18040, VA=85.53450, SD=18.757, HT=1.525, CO=626001
SS        ID=5005,    HA=135.12120, VA=85.53320, SD=20.510, HT=1.525, CO=626001
SS        ID=5006,    HA=173.24100, VA=90.58470, SD=11.142, HT=1.525, CO=103101
SS        ID=5007,    HA=203.17480, VA=92.26550, SD=13.991, HT=1.525, CO=103101
SS        ID=5008,    HA=216.24450, VA=92.35240, SD=18.798, HT=1.525, CO=103101
SS        ID=5009,    HA=217.35170, VA=92.28170, SD=23.348, HT=1.525, CO=103101
SS        ID=5010,    HA=212.57260, VA=91.59390, SD=28.317, HT=1.525, CO=103101
SS        ID=5011,    HA=206.23140, VA=91.22100, SD=32.768, HT=1.525, CO=103101
SS        ID=5012,    HA=202.16250, VA=91.03000, SD=36.774, HT=1.525, CO=103101
SS        ID=5013,    HA=187.10480, VA=88.41160, SD=35.063, HT=1.525, CO=903101
SS        ID=5014,    HA=188.19440, VA=88.43440, SD=32.228, HT=1.525, CO=903101
SS        ID=5015,    HA=182.04520, VA=88.28010, SD=31.121, HT=1.525, CO=903101
SS        ID=5016,    HA=187.54330, VA=88.32340, SD=30.763, HT=1.525, CO=310101
SS        ID=5017,    HA=187.28540, VA=88.38090, SD=31.551, HT=1.525, CO=310101
SS        ID=5018,    HA=189.27080, VA=88.42050, SD=31.870, HT=1.525, CO=310101

 

A last comment no need to make a list at all just read line 1 do what "MOGRO" a pline layer "MOGRO"  keep reading line joining points till get a "ENDMOGRO" so look at the 3 characters for END. If nothing then its a point. Oh Yeah the easiest way is a csv as the last description if not exist is "" so its ok.

 

100,  4733186.330,   317387.733,      564.632 ,    01MOGRO

102,  4733186.330,   317387.733,      564.632 , 

 

screenshot144.png

Link to comment
Share on other sites

Hello BIGAL  thank you for the tips. Im not a programer and things go little slow with me but my code for now is just at the start. I have solution for 1 Point object, have .dwt file who separate all object just how i want.  Second part is a lines the Description is important but i will try different stuff. My decision is to collect all lines from one type in one list and after that to separate this list to lines (which was my problem), i  have Ltype for all lines and all of them will go in different layers. I do all of this stuff because some of the lines will need "Reverse" .

---------------------------------------------------------

Hello pBe i understant what you say and i have idea for that just for now my code is in the start and i do things part by part :) 

 

Than you all for the help. 

Link to comment
Share on other sites

 

31 minutes ago, Trudy said:

Hello pBe i understant what you say and i have idea for that just for now my code is in the start and i do things part by part :) 

 

Than you all for the help. 

 

Go for it Trudy. Let us know if you need more help

 

Link to comment
Share on other sites

rudy I was thinking more and a excel answer may be appropriate, you can do things like

 

Pline

x,y

x,y

x,y

 

pline

x,y

x,y

 

In a column just copy the column rows and paste to the command line, pline will be drawn. So code independent can add layer etc. 

 

Do you know about VBA in excel ?

 

Post a real file to have a look at. Excel supports a space as delimeter. 

 

Copy column G1-G26 to the command line two plines will appear. testmogro.xlsx

 

image.png.206afbadb1fcd0e9317862237bba9022.png

Edited by BIGAL
Link to comment
Share on other sites

Hello all again.

I uppload new coord who will look like real Fence 

№    X                       Y                 H           D

1 100030.000 100000.000 464.8 1.2MOGRO
2 100030.000 100035.000 464.8 1.3MOGRO
3 100030.000 100070.000 464.8 1.4MOGRO
4 100000.000 100000.000 464.8 2MOGRO
5  99990.968 100035.000 464.8 2.3MOGRO
6  99987.415 100070.000 464.8 3.4MOGRO
7 100030.000 100105.000 464.8 1MOGRO

 

I like the idea for different code and now i will ask for something more complicated if it possible to group them like

((1 2 3 7) (1 4 5) (2 5 6) (3 6)) when we use D for key.

My idea is to collect all point with "1" at descriptoion after that with "2" and ...

I realy appriciate the help from all 

------------------------------------------------------------------------------------------------------

hello BIGAL i think for this but when i use shape lines some times i need to revers the line.

But i like your idea for code its much better than mine with your method i can have 1 start poit for 2-3-X  lines. 

 

Link to comment
Share on other sites

Post a real file please.

 

As I said earlier a double sort in excel on number and "D" will make it look like your sample, 7 would be at start. 

 

Save as csv much easier for a line that is a point only the "D" becomes a null string. Then yes could multi loop through code looking for patterns using "." so could have more than 2, 1.3.4MOGRO.

 

Just me would make ((layer xy xy xy xy)(layer xy xy)(layer xy xy xy xy xy xy)) etc saves going back through the master list multiple times to get the xy. Did you want 3dpoly ? Can be xyz.

Edited by BIGAL
Link to comment
Share on other sites

7 hours ago, Trudy said:

 

I like the idea for different code and now i will ask for something more complicated if it possible to group them like

((1 2 3 7) (1 4 5) (2 5 6) (3 6)) when we use D for key.

My idea is to collect all point with "1" at descriptoion after that with "2" and ...

 

As long as the list's format is consitent, You can stick with just a name for "D" like "FENCE 1" for rows 1 to 5 and  "FENCE 2" from 6-13.... As soon as "D" change shows a diffrent value the  previous one, the program will stop and start  a new list. Allso the "D" value then can be use as LAYER name.

 

Try not to minimize the changes from the orginal format provided to you by the  "Bulgarian program" you mentioned earlier in the discussion.

Its all up to you Trudy.  

 

Guess you did not pick up the "Pontiac Bandit" reference  on my first post. :)

 

Link to comment
Share on other sites

Hello BIGAL i dont have real measurments with codes, we use other codes  and we draw  piece by piece. 

But these coordinates are pretty real i draw a lines and create the .txt file.

And for that reason i create this lisp and very appriciate your advice.

I create something where sort and create just what i need.

If someone want i can uppload it .

===================================================================

Hello pBe i change everything from the main idea but work for now , i create 1 from maybe 15+ different (fence, Buildings, road, ...) but work, from now on i will just add new things.

But I would not have succeeded without your help.

 

 

Thank you again everyone.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...