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,914 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,915 Views
25 Replies
Replies (25)
Message 21 of 26

ВeekeeCZ
Consultant
Consultant

@miroslav.pristov wrote:

...

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.

 

....

I think the UCS could be manageable. Maybe little more complicated, but yes. But I guess it does not worth it. It could work more simple and probably better.

Btw Now remember, when you are selecting the object to trim (the main one) select that close to the corner (that one, where the future dims will cross each other).

 

Spoiler
(defun c:TrimPolygon ( / LM:intersections *error* adoc ensel emsel esel pt)
    
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (vla-endundomark adoc)
    (princ))
  
  
  ;; 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 close to corner: "))
	   (setq pt (osnap (cadr emsel) "_end"))
	   )
    (progn
      
      (vla-startundomark (setq adoc (vla-get-activedocument (vlax-get-acad-object))))
      
      (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 "_dimlinear" "_none" a "_none" b "_R" "_none" pt "_none" b "_none" (polar a (angle a pt) (+ (distance a pt) 0.5))
	       "_dimlinear" "_none" a "_none" b "_R" "_none" pt "_none" a "_none" (polar b (angle b pt) (+ (distance b pt) 0.5)))
      ))
  (*error* "end")
  )

@miroslav.pristov wrote:

.... I realize that I am engaged you with these last few days, and i am really grateful on that.

 

Thank you again 


If so, let it show by the means the page offers you. Just close the thread as solved and give some kudo. Not just to me, to all people who helped you somehow. Even the suggestion you did not take, even that guy tried to help you.

0 Likes
Message 22 of 26

miroslav.pristov
Advocate
Advocate

Thank you again for your time and effort.

 

The problem with text direction of dimension lines now are ok, but there is other problem which i didnt have it before.

 

picture.jpg

 

As you can see the dimension lines are not in ucs of magenta line. One must be parallel and the other must be orthogonal to that line. So i think calling for that line is necessary. In first example i think its ok, or maybe the angle is pretty much similar so i cant see the difference (thats not the one on picture), but in this one like in picture its clearly visible.

 

And one more thing. I see that you make automaticaly position of dimension lines. Its ok but on my drawings i have many other lines and dimension lines, so i deliberately left that in previous lisp i send. I must put them somewhere on clean space.

 

Dont worry the kudo is ready 🙂

 

 

0 Likes
Message 23 of 26

ВeekeeCZ
Consultant
Consultant
Accepted solution

@miroslav.pristov wrote:

 

...

As you can see the dimension lines are not in ucs of magenta line. One must be parallel and the other must be orthogonal to that line. So i think calling for that line is necessary. In first example i think its ok, or maybe the angle is pretty much similar so i cant see the difference (thats not the one on picture), but in this one like in picture its clearly visible.

 

And one more thing. I see that you make automaticaly position of dimension lines. Its ok but on my drawings i have many other lines and dimension lines, so i deliberately left that in previous lisp i send. I must put them somewhere on clean space.

 


Ok, I can see the issue. The difference is whether you cut just one corner, or two corners. But the fix is very simple. It's all the same, just little of thinking.

 

Spoiler
(defun c:TrimPolygon ( / LM:intersections *error* adoc ensel emsel esel pt)
    
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (vla-endundomark adoc)
    (princ))
  
  
  ;; 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 close to corner: "))
	   (setq p1 (osnap (cadr emsel) "_end")
		 p2 (osnap (cadr emsel) "_mid"))
	   )
    (progn
      
      (vla-startundomark (setq adoc (vla-get-activedocument (vlax-get-acad-object))))
      
      (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 "_dimlinear" "_none" a "_none" b "_R" "_none" p1 "_none" p2 PAUSE
	       "_dimlinear" "_none" a "_none" b "_R" "_none" p2 "_none" p1 PAUSE)
      ))
  (*error* "end")
  )

@miroslav.pristov wrote:

... 

 

Dont worry the kudo is ready 🙂


Never mind. Save it, please.

Message 24 of 26

miroslav.pristov
Advocate
Advocate

now the first one example work as the second yesterday 😞 

0 Likes
Message 25 of 26

miroslav.pristov
Advocate
Advocate

actually it works. i saw now you put to choose close to corner. When i do that it works

 

Thank you very much

0 Likes
Message 26 of 26

ВeekeeCZ
Consultant
Consultant

@miroslav.pristov wrote:

now the first one example work as the second yesterday 😞 


It certainly does NOT to me. Post the dwg sample where is this happening. Please test more then one sample. If it goes wrong, focus on some envirnment variables you could have on (ORTHO, SNAP...).

 

Edit: Glad, you sorted out.

0 Likes