Changing the polyline closed polygon in place where single line intersected him

Changing the polyline closed polygon in place where single line intersected him

miroslav.pristov
Advocate Advocate
1,895 Views
25 Replies
Message 1 of 26

Changing the polyline closed polygon in place where single line intersected him

miroslav.pristov
Advocate
Advocate

Is any one interesting to please help me making this lisp

 

I have polyline closed polygon (in yellow), like on picture bellow and in the example file i attach. The shape of it can be different, this is only the example. I have a line on drawing which intersect the polygon (white line). i need that polygon to change its shape in intersection points A and B like on pictures. To trim the polygon and to add new line A to B in it. The white line must not be erased. Also if i choose some line for defining the UCS (red line) i need that line AB to be dimaligned like on picture and example file.

 

So the input data should be:

 

-pick polygon,

-pick white line,

-pick side from white line for triming the polygon,

-pick red line for defining UCS

 

triming the polygon.jpg

 

Thanks for help

0 Likes
Accepted solutions (1)
1,896 Views
25 Replies
Replies (25)
Message 2 of 26

ВeekeeCZ
Consultant
Consultant

Maybe just like this... (not sure about the PLAN  commnad - if you want it.. you can erase that line if don't.)

 

(defun c:TrimPolygon ( / ensel emsel)
  
  (if (and (setq ensel (entsel "n\Select cutting edge: "))
	   (setq emsel (entsel "n\Select object to trim: ")))
    (command "_.TRIM" ensel "" emsel ""
	     "_.PEDIT" emsel "_Cl" ""
	     "_.UCS" "_Ob" PAUSE
	     "_.PLAN" "" ; ???
	     ))    

  (princ)
)

 

So the input data is:

 -pick polygon,

-pick white line,

-pick side from white line for triming the polygon,

-pick red line for defining UCS

 

0 Likes
Message 3 of 26

miroslav.pristov
Advocate
Advocate

it just trim the poligon but dont make new one including the line AB

0 Likes
Message 4 of 26

stevor
Collaborator
Collaborator

For "make new one"

A possible way is  to use BeekeeCZ's routine, and

add  the Pedit command  to close the resulting pline.

S
0 Likes
Message 5 of 26

miroslav.pristov
Advocate
Advocate

ok i ll explain better,

 

the white line i talked about is a line which intersect many polygons, if i turned it as a line AB for this polygon then i dont have it for other, and then i need to draw new white line. Thats the reason why i dont want the routine not to erase it, but to make new yellow line from point A to B, and make new polygon from not trimed part of polygon and that new line.

 

i think now i explain everything

0 Likes
Message 6 of 26

miroslav.pristov
Advocate
Advocate

and new examle it wont work

0 Likes
Message 7 of 26

ВeekeeCZ
Consultant
Consultant

@miroslav.pristov wrote:

and new examle it wont work


Because you're breaking your own rules. Read your first line of this thread..... The polyline in this example is NOT closed.

 

I added one more line and it does not matter now.

 

(defun c:TrimPolygon ( / ensel emsel)
  
  (if (and (setq ensel (entsel "n\Select cutting edge: "))
	   (setq emsel (entsel "n\Select object to trim: ")))
    (command "_.PEDIT" emsel "_Cl" ""
	     "_.TRIM" ensel "" emsel ""
	     "_.PEDIT" emsel "_Cl" ""
	     "_.UCS" "_Ob" PAUSE
	     "_.PLAN" "" ; ???
	     ))    

  (princ)
)
0 Likes
Message 8 of 26

miroslav.pristov
Advocate
Advocate

Yes now it works perfect, just what i want. Sorry for misunderstanding, english is not my maternal language.

 

Is there a chance to add part with dimension lines and choosing the red line for defining the UCS. I can maybe do it on my own but dont know how to define the A and B points in routine

0 Likes
Message 9 of 26

miroslav.pristov
Advocate
Advocate

one more question, if you have time of course

 

Look at my lower example in picture where white line intersect the longer yellow lines. You see the red simple line intersect the white line too. In this case its one line, but there can be moreon drawings

 

Is there a chance to make that lines trimeed on line AB too. Maybe to add input line in routine for chossing every single lines which will be trimed on line AB. It will be better to choose them all, because maybe there will be lines i dont want to be trimed. 

 

Thank you for your time, I m very grateful

0 Likes
Message 10 of 26

ВeekeeCZ
Consultant
Consultant

@miroslav.pristov wrote:

 

...

Is there a chance to make that lines trimeed on line AB too. Maybe to add input line in routine for chossing every single lines which will be trimed on line AB. It will be better to choose them all, because maybe there will be lines i dont want to be trimed. 

 

...

This is very simple... you could do that yourselve.

 

Spoiler
(defun c:TrimPolygon ( / ensel emsel)
  
  (if (and (setq ensel (entsel "\nSelect cutting edge: "))
	   (setq emsel (entsel "\nSelect outer object to trim: ")))
    (progn
      (command "_.PEDIT" emsel "_Cl" ""
	       "_.TRIM" ensel "" emsel)
      (while (> (getvar 'CMDACTIVE) 0)
	(command PAUSE))
      (command "_.PEDIT" emsel "_Cl" ""
	       "_.UCS" "_Ob" PAUSE
	       "_.PLAN" "" ; ???
	     )))    

  (princ)
)

 


@miroslav.pristov wrote:

... choosing the red line for defining the UCS. ...


 

This was included into routine since very beginning.

 

 


@miroslav.pristov wrote:

Is there a chance to add part with dimension lines ... I can maybe do it on my own but dont know how to define the A and B points in routine


 

I'm sure you can. Use THIS Lee Mac's subfunction to get your points A and B. You have entities, you'll get points, you have red line to get angle, caltulate some DIM distance... that's all you need for DIMLINER / DIMALIGNED command.

 

 

0 Likes
Message 11 of 26

miroslav.pristov
Advocate
Advocate

I make some modifications, ucs command make me a mess so i erase the line. Its look like we dont understand each other again :-). So now routine looks like this

 

(defun c:TrimPolygon ( / ensel emsel)

(if (and (setq ensel (entsel "\nSelect cutting edge: "))
(setq emsel (entsel "\nSelect outer object to trim: ")))
(progn
(command "_.PEDIT" emsel "_Cl" ""
"_.TRIM" ensel "" emsel)
(while (> (getvar 'CMDACTIVE) 0)
(command PAUSE))
(command "_.PEDIT" emsel "_Cl" ""
)))

(princ)
)

 

Is there a chance to make some modification in it to work on both cases. even if yellow lines are pline or just simple lines?

 

I was looking the lee mac subfunctions you send me. the description is good but i still dont know how to make points A and B in routine

 

(setq A (????))

(setq B (????))

 

the rest i can do all by myself. Thank you

 

 

 

 

0 Likes
Message 12 of 26

ВeekeeCZ
Consultant
Consultant

@miroslav.pristov wrote:

 

...

 

I was looking the lee mac subfunctions you send me. the description is good but i still dont know how to make points A and B in routine

 

(setq A (????))

(setq B (????))

 

the rest i can do all by myself. ...


Ok, here are your lines...

 

(if (= 2 (length (setq pts (LM:intersections (vlax-ename->vla-object (car ensel))  (vlax-ename->vla-object (car emsel)) acextendnone))))
	(setq a (car pts)
	      b (last pts)))

I would put this BEFORE trim command. And notice, that you never know which is which. But it should not mind.

 

 


@miroslav.pristov wrote:

 

...Is there a chance to make some modification in it to work on both cases. even if yellow lines are pline or just simple lines?

 


It could be done... just test emsel varible if contains a line. If so, run JOIN command, select the rest of lines and connect them. Then you have a polyline, so you can continue with the code you already have.

0 Likes
Message 13 of 26

miroslav.pristov
Advocate
Advocate

I try what you wrote but got error

 

error: no function definition: LM:INTERSECTIONS

 

i try to put lines on other place its the same

0 Likes
Message 14 of 26

miroslav.pristov
Advocate
Advocate

well do i need to have LM:intersection routine inside my routine? I try everything it dont work. If i need it inside, do i need to change something in it. 

 

I stuck in here, cant define those 2 points

0 Likes
Message 15 of 26

ВeekeeCZ
Consultant
Consultant

@miroslav.pristov wrote:

well do i need to have LM:intersection routine inside my routine?...


I hoped you will figure out this yourselve... so, close enough. Not necessarily inside, but yes. You need to have this sub function loaded. If you need this sub just because this one routine, then put it inside and localize it. 

 

Spoiler
(defun c:TrimPolygon ( / LM:intersections ensel emsel)
  
  
  ;; Intersections  -  Lee Mac
  ;; Returns a list of all points of intersection between two objects
  ;; for the given intersection mode.
  ;; ob1,ob2 - [vla] VLA-Objects
  ;;     mod - [int] acextendoption enum of intersectwith method
  
  (defun LM:intersections ( ob1 ob2 mod / lst rtn )
    (setq lst (vlax-invoke ob1 'intersectwith ob2 mod))
    (repeat (/ (length lst) 3)
      (setq rtn (cons (list (car lst) (cadr lst) (caddr lst)) rtn)
	    lst (cdddr lst)
	    )
      )
    (reverse rtn)
    )
 
  
  (if (and (setq ensel (entsel "\nSelect cutting edge: "))
	   (setq emsel (entsel "\nSelect outer object to trim: ")))
    (progn
      
      (if (= 2 (length (setq pts (LM:intersections (vlax-ename->vla-object (car ensel))  (vlax-ename->vla-object (car emsel)) acextendnone))))
	(setq a (car pts)
	      b (last pts)))
      
      (command "_.PEDIT" emsel "_Cl" ""
	       "_.TRIM" ensel "" emsel)
      (while (> (getvar 'CMDACTIVE) 0)
	(command PAUSE))
      (command "_.PEDIT" emsel "_Cl" ""
	       )))
  (print a)
  (print b)
  (princ)
  )
0 Likes
Message 16 of 26

miroslav.pristov
Advocate
Advocate

here is lisp i made, and again example file. Look what routine did with dimension lines. it doesnt take A and B points it takes some other points

 

i add line for defining ucs, its magenta in example when you choose

0 Likes
Message 17 of 26

miroslav.pristov
Advocate
Advocate

oups sorry didnt see your new post, i ll check it now

0 Likes
Message 18 of 26

miroslav.pristov
Advocate
Advocate

I tried your last post and add lines for dimensioning and again thats not that points, if you have time please take a look if you have time

 

U can use example file i send you few minutes ago

0 Likes
Message 19 of 26

ВeekeeCZ
Consultant
Consultant

@miroslav.pristov wrote:

here is lisp i made, and again example file. Look what routine did with dimension lines. it doesnt take A and B points it takes some other points

 


I does, and correctly, but in WCS. And if you rotated CS to UCS for dimensioning, then you need to translate coords from WCS to UCS. There is (trans) command for that. And don't put those previous lines into COMMAND! 

 

 

(defun c:TrimPolygon ( / LM:intersections ensel emsel esel)
  
  
  ;; Intersections  -  Lee Mac
  ;; Returns a list of all points of intersection between two objects
  ;; for the given intersection mode.
  ;; ob1,ob2 - [vla] VLA-Objects
  ;;     mod - [int] acextendoption enum of intersectwith method
  
  (defun LM:intersections ( ob1 ob2 mod / lst rtn )
    (setq lst (vlax-invoke ob1 'intersectwith ob2 mod))
    (repeat (/ (length lst) 3)
      (setq rtn (cons (list (car lst) (cadr lst) (caddr lst)) rtn)
	    lst (cdddr lst)
	    )
      )
    (reverse rtn)
    )
 
  
  (if (and (setq ensel (entsel "\nSelect cutting edge: "))
	   (setq emsel (entsel "\nSelect outer object to trim: "))
	   (setq esel (entsel "\nSelect object for ucs: "))
	   )
    (progn
      
      (if (= 2 (length (setq pts (LM:intersections (vlax-ename->vla-object (car ensel))  (vlax-ename->vla-object (car emsel)) acextendnone))))
	(setq a (car pts)
	      b (last pts)))
      
      (command "_.PEDIT" emsel "_Cl" ""
	       "_.TRIM" ensel "" emsel)
      (while (> (getvar 'CMDACTIVE) 0)
	(command PAUSE))
      (command "_.PEDIT" emsel "_Cl" ""
	       )))

  (command "_UCS" "_Ob" esel)
  (command "_dimlinear" "_none" (trans a 0 1) "_none" (trans b 0 1) "\\")
  (command "_dimlinear" "_none" (trans a 0 1) "_none" (trans b 0 1) "\\")
  (command "_UCS" "_w")
  
  (princ)
  )
0 Likes
Message 20 of 26

miroslav.pristov
Advocate
Advocate

Perfect, thank you. Now it works just what i want.

 

But there is one thing and that really bothers me. I realize that my idea of drawing dimension lines in ucs which i got choosing magenta line is not a good solution. Because i dont know how will program choose UCS and thats why there are cases, where i got the dimension lines upside down.

 

If you have some more time, can you please take a look what i told about (see yellow revision cloud in example file).

 

is there a chance to fix that? I cant do it by myself. I realize that I am engaged you with these last few days, and i am really grateful on that.

 

Thank you again 

0 Likes