SSGET to select a polyline using two coordinates as filters

SSGET to select a polyline using two coordinates as filters

Anonymous
Not applicable
5,896 Views
20 Replies
Message 1 of 21

SSGET to select a polyline using two coordinates as filters

Anonymous
Not applicable

Hello,

Why the SSGET command line using StartPoint AND EndPoint variables/filters doesn't work?

 

(setq SelSet (ssget "_:L" '((0 . "*POLYLINE")))) 
(setq na1 (ssname SelSet 0)) 
(setq obj (vlax-ename->vla-object na1))
(setq StartPoint (vlax-curve-getStartPoint obj) )
(setq EndPoint (vlax-curve-getEndPoint obj) )
(setq ss1 (ssget "C" StartPoint EndPoint '((0 . "*POLYLINE"))  (-4 . "=,=,*") (10 (car StartPoint) (car (cdr StartPoint)) 0.0 )))

 

StartPoint AND EndPoint vertices can be in any position/sequence, not necessary the first vertex coordinate.

The command still incomplete because I need to ADD EndPoint on the filters. 

 

The goal is to complete the RED polyline with the vertices of the WHITE one (check image). It's the next step of the code.

 

Thanks in advance + regards,

lzucco

0 Likes
Accepted solutions (4)
5,897 Views
20 Replies
Replies (20)
Message 2 of 21

dbhunia
Advisor
Advisor

Hi

 

I did not get your point totally.......

 


@Anonymous wrote:

Hello,

Why the SSGET command line using StartPoint AND EndPoint variables/filters doesn't work?

 

(setq SelSet (ssget "_:L" '((0 . "*POLYLINE")))) 
(setq na1 (ssname SelSet 0)) 
(setq obj (vlax-ename->vla-object na1))
(setq StartPoint (vlax-curve-getStartPoint obj) )
(setq EndPoint (vlax-curve-getEndPoint obj) )
(setq ss1 (ssget "C" StartPoint EndPoint '((0 . "*POLYLINE"))  (-4 . "=,=,*") (10 (car StartPoint) (car (cdr StartPoint)) 0.0 )))

 

StartPoint AND EndPoint vertices can be in any position/sequence, not necessary the first vertex coordinate.

The command still incomplete because I need to ADD EndPoint on the filters. 

 

The goal is to complete the RED polyline with the vertices of the WHITE one (check image). It's the next step of the code.

 

Thanks in advance + regards,

lzucco


 

But the Red line should be like.......

 

(setq ss1 (ssget "C" StartPoint EndPoint (list '(0 . "*POLYLINE") (cons 10 (list (car StartPoint) (car (cdr StartPoint)) 0.0 )))))

And what about  "(-4 . "=,=,*")"....


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 3 of 21

Anonymous
Not applicable

Thanks a lot! 

 

I also want to include EndPoint in the filter because I'ld like to select only polylines that contains both StarPoint AND EndPoint vertices, that's why I was trying ("=,=,*") = coordinate X,  = coordinate Y, * any Z coordinate.

 

The result of following command should be 2 polylines (RED and WHITE)

(setq ss1_qt (sslength ss1))

 

Then I remove from the ss1 the manual polyline selected using 

(if (ssmemb na1 ss1)
(ssdel na1 ss1)
)

 

The result of ss1 will be only the polyline I was looking for. (WHITE)

 

0 Likes
Message 4 of 21

dbhunia
Advisor
Advisor
Accepted solution

@Anonymous wrote:

Thanks a lot! 

 

I also want to include EndPoint in the filter because I'ld like to select only polylines that contains both StarPoint AND EndPoint vertices, that's why I was trying ("=,=,*") = coordinate X,  = coordinate Y, * any Z coordinate.

 

The result of following command should be 2 polylines (RED and WHITE)

(setq ss1_qt (sslength ss1))

 

Then I remove from the ss1 the manual polyline selected using 

(if (ssmemb na1 ss1)
(ssdel na1 ss1)
)

 

The result of ss1 will be only the polyline I was looking for. (WHITE)

 


 

For that try this.....

 

(setq ss1 (ssget "_A" (list '(0 . "*POLYLINE") (cons 10 (list (car EndPoint) (car (cdr EndPoint)) 0.0 )) (cons 10 (list (car StartPoint) (car (cdr StartPoint)) 0.0 )))))

Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 5 of 21

dbhunia
Advisor
Advisor
Accepted solution

Hi

 

I also want to include EndPoint in the filter because I'ld like to select only polylines that contains both StarPoint AND EndPoint vertices, that's why I was trying ("=,=,*") = coordinate X,  = coordinate Y, * any Z coordinate.

 

The result of following command should be 2 polylines (RED and WHITE)

(setq ss1_qt (sslength ss1))

 

Then I remove from the ss1 the manual polyline selected using 

(if (ssmemb na1 ss1)
(ssdel na1 ss1)
)

 

The result of ss1 will be only the polyline I was looking for. (WHITE)

 

 

 

(setq ss1 (ssget "_A" (list '(0 . "*POLYLINE") (cons 10 (list (car EndPoint) (car (cdr EndPoint)) 0.0 

 

 

The above mentioned method you will get all those PLINES (after removing "na1") whose Start point / End point / Any vertices passes through the two points (in your code two point are "StartPoint" & "EndPoint")......

 

So to get only those PLINES (after removing "na1") whose Either Start point or End point are the two points (in your code two point are "StartPoint" & "EndPoint")..... Take each PLINE from PLINES selection set (after removing "na1") & check whether the Start point or End point is the two points (in your code two point are "StartPoint" & "EndPoint") or not....


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 6 of 21

Anonymous
Not applicable

This is the code result so far. (attached)

 Next step is using parts of more than one polyline to work in teste.dwg

 

Thanks again!

Message 7 of 21

ВeekeeCZ
Consultant
Consultant

Impressive milestone!

What's your ultimate goal? Select the entire block and all polylines inside get closed?

0 Likes
Message 8 of 21

Anonymous
Not applicable

Hello!

 

The idea is to go thru all open polylines in a selected layer and then to close it using the segments of other(s) polylines.

I have 70 more files like teste.dwg where to use it this routine.

 

0 Likes
Message 9 of 21

ВeekeeCZ
Consultant
Consultant
Accepted solution

I see. Here is this humble attempt just before bedtime, just for you to have fun. Ain't that bad I think... might help.

Perhaps some improvements would be necessary...

 

(defun c:testeclose ( / ss i obj pnt ptlst ptsum )

  (if (setq ss (ssget '((0 . "LWPOLYLINE") (-4 . "<NOT") (-4 . "&=") (70 . 1) (-4 . "NOT>") (-4 . ">") (90 . 2))))
    (repeat (setq i (sslength ss))
      (setq ptlst nil ptsum '(0 0)
	    ptlst (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10))
				      (entget (ssname ss (setq i (1- i)))))))
      (foreach x ptlst (setq ptsum (mapcar '+ x ptsum)))
      (setq pnt (mapcar '/ ptsum (list (length ptlst) (length ptlst))))
      (if pnt (command "_.-boundary" "_non" pnt ""))))
  (princ)
)
Message 10 of 21

Anonymous
Not applicable

WOW! Thanks a lot!

 

Because I'm newbie on LIST I'll need some time to understand how do you do it and how the function works... but, is a incredible much smaller and elegant code. 

 

This is what I was thinking for solving the problem:

1) To create a HATCH using PICK POINTS (centroid or something like that)
    Regenerate HATCH boundaries
    Erase the HATCH

 

2) A more complex logic comming from the original idea

 

Selecting polylines where
Startpoint = some coordinate of a second polyline
Endpoint = some coordinate of a third polyline

 

AND ALSO WHERE
some coordinate of second polyline and third polyline are equal
AND this coordinate is inside the ssget "C" from the incomplete polyline coordinates

 

- catch the coordinates of 2nd polyline between this points
(interrupted by equal coordinate 2nd and 3rd polyline)

- catch the coordinates of 23rd polyline between this points
(interrupted by equal coordinate 2nd and 3rd polyline)

 

- Finally using the (vla-AddVertex... complete the selected polyline (the one we want to reconstruct)

 

Best regards!

0 Likes
Message 11 of 21

ВeekeeCZ
Consultant
Consultant

@Anonymous wrote:

... Because I'm newbie on LIST I'll need some time to understand how do you do it and how the function works... but, is a incredible much smaller and elegant code. 

 

This is what I was thinking for solving the problem:

1) To create a HATCH using PICK POINTS (centroid or something like that)
    Regenerate HATCH boundaries
    Erase the HATCH ...


 

This is basically what my LISP does. Only instead of doing HATCH and delete, it uses the BOUNDARY command, which is essentially the same. Your drawing is quite good, there are no gaps. If they were I would rather use the HATCH command with its skip-gap option. This option is not available within the BOUNDARY command.

 

Unfortunately, we cannot use the 'centroid of an open polyline. But if we close them before... we can.

I calculated the "average point" to get some inside point. (sum all x coords, divided by the number of them)

= (x1+x2+...+xn)/n, the same for y.

 

But here are some things to you to consider to improve/change/simplify.

- for each open polyline (done)

- close the polyline

- get its centroid point

- get its layer

- use the boudary command

- change boundary's layer 

- remove the original polyline.

 

Good luck!

Message 12 of 21

Anonymous
Not applicable

Thanks for the hints,

 

I'ld like to put more filters in the SSGET command

1) How to include in the ssget command to exclude LOCKED LAYERS?
I was trying "_X:L"

 

2) How to pick only polylines from a selected LAYER?
I was trying (8 . layer) but with no success. ; error: bad ssget mode string

 

3) How to select only polylines with AREA > 0 ??

(if (setq ss (ssget "_X:L" '((0 . "LWPOLYLINE") (-4 . "<NOT") (-4 . "&=") (70 . 1) (-4 . "NOT>") (-4 . ">") (90 . 2) (8 . layer) ) ))

 

I confess I do not fully understand your code yet 😞 and I still have a long path to run to reach the complete wished result.

 

Next step: (after cleaning up all the residual lines)
- to create attributes in the closest point of the polylines (lots) and the polyline (square that demarks the sidewalk and is around the lots) to indicate where is the front of the lot.
This will be exported to a Excel sheet where I'll have work later on...

0 Likes
Message 13 of 21

ВeekeeCZ
Consultant
Consultant
Accepted solution

@Anonymous wrote:

...I'ld like to put more filters in the SSGET command

1) How to include in the ssget command to exclude LOCKED LAYERS?
I was trying "_X:L"

It's not that simple. Look HERE for more suggestions about this.

 

2) How to pick only polylines from a selected LAYER?
I was trying (8 . layer) but with no success. ; error: bad ssget mode string

You need to distinguish whether it has to be evaluated or not.

If it's a constant, the quotation is fine: '((8 . "Layer1")). 

If there is somewhere a variable, then the evaluation is required. (list (cons 8 layer)) or (list '(0 . "LINE") (cons 8 layer))

 

3) How to select only polylines with AREA > 0 ??

(if (setq ss (ssget "_X:L" '((0 . "LWPOLYLINE") (-4 . "<NOT") (-4 . "&=") (70 . 1) (-4 . "NOT>") (-4 . ">") (90 . 2) (8 . layer) ) ))

No way. You can only use filter of properties stored in a definition list of entity. You need to go thru the ss...

 

I confess I do not fully understand your code yet 😞 and I still have a long path to run to reach the complete wished result.

Hightlight the parts you have issues with and I'll try to explain it  in words.

 

Next step: (after cleaning up all the residual lines)
- to create attributes in the closest point of the polylines (lots) and the polyline (square that demarks the sidewalk and is around the lots) to indicate where is the front of the lot.

You will need to ilustrate that on dwg.


 

0 Likes
Message 14 of 21

Anonymous
Not applicable

My main doubt is:

- boundary parameters list - (command "_.-boundary" "_non" pnt "") - ?WHERE TO FIND?

 

Attached is the DWG to ilustrate next step. The attributes will be created and put inside the objects using AUTOCAD CIVIL.

 

For the 123 SSGET questions I'll am working on it, later on I'll put the code here.

 

Thanks again.

0 Likes
Message 15 of 21

ВeekeeCZ
Consultant
Consultant

What do you mean by "Where to find?" Where what to find?

Syntax? I guess you do understand the syntax of this short line... or do you?

Point? You don't understand how the pnt is supplied/calculated?

?? Or something else?

0 Likes
Message 16 of 21

ВeekeeCZ
Consultant
Consultant

I've seen your dwg...

Not sure about your "skip-gap" needed. You mean like there is the entire front line of 9,4 m length missing which you need to skip? If so, that would be too much for the HATCH command.

In general, I doubt that you'll be able to solve all the map's issues automatically. Maybe 99,9%, but the rest would be so unique, that would not worth the spent time. I'm afraid that the last manual check would be necessary.

Message 17 of 21

Anonymous
Not applicable

- I did manage to include layer filter in the SSGET command.

- AREA was handled inside the ss loop.

- Polyline Boundary was created in a selected layer

- Old and opened polylines were moved to a layer to be later on deleted.

 

It was a beautiful thing to see... automaticly closing 400 polyline at least. The updated code is attached.

 

Somethings to do automactlly I hope:
- delete duplicate polylines

 

But probably manually
- to compare the drawings
- fine adjustments

 

After that I am going to the next steps.

Thanks a lot!

 

P.S.: About the boundary command: Forget about it.

Message 18 of 21

ВeekeeCZ
Consultant
Consultant

Handling area property is definitely go this, just the commentary amused me.

Do you know what the blue part is for? 🙂

 

(setq ss (ssget "_X" (list ...... (cons 70 1) (cons -4 "NOT>") (cons -4 ">") (cons 90 2)) ))

 

 


@Anonymous wrote:

.... It was a beautiful thing to see... automaticly closing 400 polyline at least. .... 


 

Yeah, I'm sure of it! 🙂

 

You need to merge j and i into one!!! Both do the same thing but the later goes the other way around than the first one!!!

j goes from max to 0, i from 0 to max! 

0 Likes
Message 19 of 21

Anonymous
Not applicable

Do you know what the blue part is for? 🙂

NOPE

0 Likes
Message 20 of 21

ВeekeeCZ
Consultant
Consultant

Let's find out then!

Look into help HERE for "dxf lwpolyline" to see what 90 code represents.

Then explore the SSGET filters possibilities HERE (see the entire tree branch), especially then the relation tests HERE