Jump to content

Recommended Posts

Posted (edited)
(defun c:Bdry ()
  ; Get all polylines selected by the user
  (setq ss (ssget '((0 . "LWPOLYLINE")))) ; Filter for polylines
  (setq points '())
  
  ; Check if any polylines were selected
  (if ss
    (progn
      ; Get the number of selected polylines
      (setq n (sslength ss))
      (setq p 0)

      ; Loop through each selected polyline
      (repeat n
        (setq k (ssname ss p))                   ; Get the selected polyline
        (setq m (entget k))                      ; Get the entity list for the selected polyline
        (setq b (append  m (list (assoc 10 m))))              
        
        (foreach y b 
        (if (= (car y) 10)
               
                  (progn
                  (setq points (append points (list (cdr y))))      ; Get the vertex list (points)                       
                 ;(setq bl (vlax-invoke k intersectWith  (vlax-ename->vla-object entnext) acextendnone)))
                 ); end progn
        ) ; end if
      ) ; end foreach

        (setq p (+ p 1))                          ; Increment polyline index
      ) ; end repeat

      (if points
        (progn
          ; Draw the new polyline from the collected points
          (command "pline")
          (foreach pt points
                         
            (command pt)           ; Add points to the polyline command
          )
          (command "")                              ; End the polyline command
        )
      ) ; end if points

    ) ; end progn
  ) ; end if
)

 

Try to intersect each polyline, then break it at the intersecting point connect all point vertexes, and intersect the point, I can not replace repeat function to foreach function

BOUNDARY.pdfFetching info...

Edited by maahee
Posted

Hi Maahee
It's better if you attach a drawing

  • Agree 1
Posted (edited)

Easy solution NO CODE,  draw a closed pline around your shapes, Type Bpoly, pick point between shapes and out side pline, a pline around outside of shapes should be there now erase outer plines, yes plines as bpoly adds one to outside.

Edited by BIGAL
  • Agree 1
Posted (edited)
  On 3/20/2025 at 2:12 PM, GLAVCVS said:

Hi Maahee
It's better if you attach a drawing

Expand  
(defun c:kol ()
  
  (setq p1 (getpoint "\nSpecify the bottom-left corner point: "));; Prompt user to specify the bottom-left corner point
  (setq p2 (getpoint p1 "\nSpecify the top-right corner point: "));; Prompt user to specify the top-right corner point
  (setq f (ssget "w" p1 p2 '((0 . "LWPOLYLINE,circle,arc")))) ;; f selection set
(setq ssadd pt)
(command "RECTANGLE" p1 p2) ;; Create a rectangle using the RECTANGLE command
(setq pt (entlast)) ;create selection set 

(setq m (polar p1 (* pi 1.75) 1));; point pick inside the rect

(setq ssadd bm)
(command "_.boundary" "a" "b" "n" f pt "" "" m "") ;; Create boundary command
(setq bm (entlast));create selection set 

(setq p (ssget "-w-p" p1 p2 '((0 . "LWPOLYLINE"))));;; Create a rectangle using the RECTANGLE command remove f setectiol set from p
(command "_.erase" pt "" );; erase a rectangle 

(ssdel f p)
(command "_.erase" P) ;; erase a p sset

)

(setq f (ssget "w" p1 p2 '((0 . "LWPOLYLINE,circle,arc")))) 

(setq p (ssget "-w-p" p1 p2 '((0 . "LWPOLYLINE"))))  remove the f selection set from the p selection set then delete the p selection set both having the same entity except the rectangle.

Drawing100.dwgFetching info...

Edited by maahee
Posted

Just an idea for internal boundaries, not just one, if you make a list of ((area1 ent1)(area2 ent2)...) you can sort on areas the only one to keep is the second largest area, you have entity names so can erase all the others. Have a go plenty here will help if you get stuck.

  • Agree 1
Posted (edited)

@maahee Are you sure that this point '(polar p1 (* pi 1.75) 1))' will lie inside the rectangle?

Edited by GLAVCVS
  • Agree 1
Posted

Shouldn't it be better, for example, '(polar p1 0.79 1))'?

  • Agree 1
Posted

Another thing to keep in mind is that calculating a point just 1 drawing unit from the bottom corner of the rectangle may cause "boundary" to not work correctly.
You may want to calculate that point by applying the drawing distance equivalent to one pixel.

  • Agree 1
Posted

You can calculate this using:
 

(/ (getvar "VIEWSIZE") (cadr (getvar "SCREENSIZE")))

 

  • Thanks 1
Posted

And one last thing: you can't use 'ssadd' as a variable. It's a reserved word in the language.

Posted (edited)
  On 3/23/2025 at 1:05 AM, GLAVCVS said:

Shouldn't it be better, for example, '(polar p1 0.79 1))'?

Expand  
(setq p1 (getpoint "\nSpecify the  corner point: ")) ;; Prompt user to specify the corner point
(setq p2 (getcorner p1 "\nSpecify the corner point: ")) ;; Prompt user to specify the corner point
(setq m (polar p1 (angle p1 p2) 5))

try to keep the point always inside the rectangle

 

  On 3/22/2025 at 11:45 PM, BIGAL said:

Just an idea for internal boundaries, not just one, if you make a list of ((area1 ent1)(area2 ent2)...) you can sort on areas the only one to keep is the second largest area, you have entity names so can erase all the others. Have a go plenty here will help if you get stuck.

Expand  
      (setq bm (ssadd)) 
      (command "_.boundary" "a" "b" "n" dm rect "" "" m "") 
      (ssadd (entlast) bm)  

entlast function always stores the last created entity so external rectangular can easily find out and other polylines sort by area.

(defun c:kol ()
  (setq p1 (getpoint "\nSpecify the  corner point: ")) ;; Prompt user to specify the corner point
  (setq p2 (getcorner p1 "\nSpecify the corner point: ")) ;; Prompt user to specify the corner point
  (setq dm (ssget "w" p1 p2 '((0 . "LWPOLYLINE,CIRCLE,ARC,LINE")))) ;; Get selection set of objects within the specified window
  (/ (getvar "VIEWSIZE") (cadr (getvar "SCREENSIZE")))
  (if dm
    (progn
      (setq rect (ssadd)) ;; Initialize a new selection set for the rectangle
      (command "RECTANGLE" p1 p2) ;; Create the rectangle using the RECTANGLE command
      (ssadd (entlast) rect) ;; Add the created rectangle to the selection set
      
      ;; Calculate a point slightly inside the rectangle to use with the boundary command
      (setq m (polar p1 (angle p1 p2) 5)) 

      (setq bm (ssadd)) ;; Initialize a new selection set for the boundary
      ;; Create a boundary using the selected objects and the rectangle
      (command "_.boundary" "a" "b" "n" dm rect "" "" m "") 
      (ssadd (entlast) bm) ;; Add the created boundary to the selection set 

      
      (command "_.erase" rect "") ;; Erase the rectangle
      (command "_.erase" bm "") ;; Erase the boundary
      (princ "\nBoundary created successfully.")
    )
    (princ "\nNo objects found in the specified area.") ;; Message if no objects are found
  )
  (princ) ;; Exit quietly
) ;; end of c:kol

 

Edited by maahee
Posted

I think you misunderstood me. You should write:

(setq m (polar p1 (angle p1 p2) (/ (getvar "VIEWSIZE") (cadr (getvar "SCREENSIZE")))))

 

  • Thanks 1
Posted (edited)

After that, all that's left is to identify which of the objects created by 'boundary' matches the rectangle.

'(ssadd (entlast) dm)' is useless because it might select the wrong polyline.
I would use, for example:

(setq f (ssget "_X" (list '(0 . "LWP*") '(-4 . "=,=,*") (list 10 (car p1) (cadr p1) 0.0))))

 

Edited by GLAVCVS
  • Thanks 1

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...