bOUNDARY DOES NOT WORK IF BOUNDARY SEGMENTS NOT VISIBLE?

bOUNDARY DOES NOT WORK IF BOUNDARY SEGMENTS NOT VISIBLE?

scadcam
Contributor Contributor
1,285 Views
4 Replies
Message 1 of 5

bOUNDARY DOES NOT WORK IF BOUNDARY SEGMENTS NOT VISIBLE?

scadcam
Contributor
Contributor

In my program, I have a terrain divided in parcels, each parcel with a point inside. I try to make a polygon around each parcel point with the instruction

 

(command "_.-boundary" "_a" "_i" "_n" "" "" pt "")

 

but with some points does not work. Not sure if has to do with parcel lines not visible in current zoom (?)
If zoom all, then get "point is directly on an object" or "select point inside.." messages.

How can I run boundary correctly?

If not possible, is there an autolisp function available instead of boundary?

 

Regards

0 Likes
Accepted solutions (3)
1,286 Views
4 Replies
Replies (4)
Message 2 of 5

john.uhden
Mentor
Mentor
Accepted solution

Here's some code excerpted from an old function of mine for labeling tax maps.  Maybe there's something in it that will help guide you to success...

 

;;------------------------------------------------------------
;; Function to get the absolutely last entity in the database:
;;
(defun @entlast ( / e elast)
   (setq elast (entlast))
   (while (setq e (entnext elast))
      (setq elast e)
   )
   elast
)
(defun @str2num (txt / nlist1 nlist2 c char txtlen num)
   (setq nlist1 '("1" "2" "3" "4" "5" "6" "7" "8" "9" "0" "-")
         nlist2 '("1" "2" "3" "4" "5" "6" "7" "8" "9" "0" "." "-")
         c 1
         txtlen (strlen txt)
         num ""
   )
   (while (and (not (vl-position (substr txt c 1) nlist1))
               (<= c txtlen))
      (setq c (1+ c))
   )
   (while (vl-position (setq char (substr txt c 1)) nlist2)
      (setq num (strcat num char) c (1+ c))
   )
   (if (/= num "")
      (atof num)
   )
)
;;---------------------------------------------------------------
;; Function to determine if an item (point, VLA-Object, or ENAME)
;; is within a closed polyline boundary.
;;
(defun @within (item poly / p ilist)
   (cond
      ((= (type item) 'ENAME)
         (setq p (cdr (assoc 10 (entget item))))
      )
      ((= (type item) 'VLA-OBJECT)
         (setq p (cdr (assoc 10 (entget (vlax-vla-object->ename item)))))
      )
      ((and (listp item)
            (> (vl-list-length item) 2)
            (setq item (vl-remove-if-not 'numberp item))
            (> (length item) 1))
         (setq p item)
      )
   )
   (if (and p ray)(vlax-put ray "Basepoint" p))
   (if (= (type poly) 'ENAME)
      (setq poly (vlax-ename->vla-object poly))
   )
   (and
      p
      (= (type poly) 'VLA-OBJECT)
      (setq ilist (vlax-invoke ray "IntersectWith" poly acExtendNone))
      (= (rem (/ (length ilist) 3) 2) 1)
   )
)
(defun @get_items_within (etypes layers poly / ss ssl i items)
   (if (setq ss (ssget "X" (list (cons 0 etypes)(cons 8 layers)'(410 . "Model"))))
      (progn
         (setq i 0.0 ssl (sslength ss))
         (while (< i ssl)
            (setq e (ssname ss i)
                  i (1+ i)
            )
            (if (@within e poly)(setq items (cons e items)))
         )
      )
   )
   items
)
;;---------------------------------------------------------------
;; Function to create a boundary polyline from LINES ans ARCs
;; given the internal point (point, VLA-Object, or ENAME),
;; a comma-delimited string of the layers to use to select the lines, and arcs,
;; a string to use as the layer of the new object,
;; and a string (text) to describe the boundary.
;;
(defun @bpoly (node layers layer text / p ss e elast ent)
   (cond
      ((= (type node) 'ENAME)
         (setq p (cdr (assoc 10 (entget node))))
      )
      ((= (type item) 'VLA-OBJECT)
         (setq p (cdr (assoc 10 (entget (vlax-vla-object->ename node)))))
      )
      ((and (listp node)
            (> (vl-list-length node) 2)
            (setq node (vl-remove-if-not 'numberp node))
            (> (length node) 1))
         (setq p node)
      )
   )
   (if
      (and p
         (= (type layers) 'STR)
         (= (type layer) 'STR)
         (setq ss (ssget "X" (list '(0 . "LINE,ARC")(cons 8 layers))))
         (setq elast (@entlast))
         (setq ucs (not (command "_.UCS" "_Origin" (getvar "viewctr"))))
         (if (= (type text) 'STR)(princ (strcat "\nCreating boundary for " text " ...")) 1)
         (not (command "_.boundary" "_A" "_I" "_N" "" "_O" "_P" "_B" "_N" ss "" "" (trans p 0 1) ""))
         (setq ucs (command "_.UCS" "_P") e (entlast))
         (or (not (equal e elast))(prompt " Failed."))
      )
      (progn
         (if text (princ " Okay."))
         (setq ent (entget e))
         (entmod (subst (cons 8 layer)(assoc 8 ent) ent))
         (vlax-ename->vla-object e)
      )
   )
)

i don't think you need all the functions, but I know that you do need @entlast and @bpoly.  I think the UCS has a lot to do with its working properly.

John F. Uhden

Message 3 of 5

Ranjit_Singh
Advisor
Advisor
Accepted solution

In addition to what @john.uhden has provided, another (easy but not so efficient) option would be to add a zoom command before calling the boundary command. Something like this

(command "._zoom" "_c" pt 10 "._-boundary" "_a" "_i" "_n" "" "" pt "")

Visually determine which is your largest parcel and run the zoom command to determine what magnification you need to roughly fit that parcel on screen. Use that magnification number instead of 10 that I used as an example.

0 Likes
Message 4 of 5

scadcam
Contributor
Contributor
Accepted solution

I have not tested what @john.uhden kindly provided because I had already tested something close to your suggestion. In my case, I had used  2 points near enclosed point to make a zoom window. The (command "zoom "w" pt1 pt2 "") that I was using before (command "boundary" ..) wouldn´t make the zooms but I don´t why, in your suggestion, you include zoom and boundary in the same (command..) and makes all the difference. Of course, had to try different zoom scales. When you run a loop of zoom and boundary for a set of enclosed points, it seems like the zooms get behind and most of them do not show but somehow, still the boundary works correctly with the not yet displayed zoom. I still have to learn more about (command ..) to fully understand why your solution works and mine didn´t.

Thanks Ranjit.Singh !

0 Likes
Message 5 of 5

scadcam
Contributor
Contributor

Thanks John !

 

I ended up using a combination of your answer and that from Ranjit.Singh and now is quite stable !

 

Regards

0 Likes