- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm trying to debug a function ((tr-2ends)) , first of all, these screenshots describe what I want it to accomplish.
Raw drawing
intended result
and here's the code for this function
;|otherelem: a small utility function that takes a list of 2 elements and an item,
it returns the other item |; (defun otherelem (mylist myelem / ret) (foreach o mylist (if (not (equal myelem o)) (setq ret o)) );foreach (progn ret) );end defun [otherelem] ;tr-2ends: this function takes a curve, and 2 points that belong to it, then removes any segment
;that isn't located between those 2 points. ;| Be notified that the curve's entity name doesn't change after trimming it,
but if it's breaked using "Break" command, one of the 2 resulted curves
will take the older entity name and the other will take a new entity name |; (defun tr-2ends (ename pt1 pt2 / elist obj spt ept dir_s2e dir_p2p br_pts ptslist i j elem rement) (vl-load-com) ;load Activex support (setq elist (list ename)) ;list of all elements that will result from breaking the initial curve (setq obj (vlax-ename->vla-object ename)) (setq spt (vlax-curve-getstartpoint obj) ept (vlax-curve-getendpoint obj) );setq (setq dir_s2e (if (< (car spt) (car ept)) 1 -1) ;direction from start to end dir_p2p (if (< (car pt1) (car pt2)) 1 -1) ;direction from breaking point 1 to breaking point 2 br_pts (list pt1 pt2) );|setq dir (dir_s2e, dir_p2p) [specifies the direction of the curve,
from left to right or the opposite] |; (if (not (equal dir_s2e dir_p2p)) (setq br_pts (reverse br_pts)) );if ;(quit);debug line (setq i 0);increment of the loop that's responsible for breaking and removing (setq rement ename);initialize rement (setq elist (list rement));|elist is a list that contains both rement
and the other element resulted from "break" command |; (while (< i 2) (command "_Break" rement (nth i br_pts) (nth i br_pts)) (setq elist (append elist (list (entlast)))) (princ "\nelist: ");debug line (print elist);debug line ;get a list of start and end points of both curves (setq ptslist (mapcar (function (lambda (eobj / obj espt eept entpts dir_ent) (setq obj (vlax-ename->vla-object eobj)) (setq espt (vlax-curve-getstartpoint obj) eept (vlax-curve-getendpoint obj) );setq [of start & end points] (setq entpts (list espt eept)) (setq dir_ent (if (< (car espt) (car eept)) 1 -1));[determine direction] (if (not (equal dir_s2e dir_ent)) (setq entpts (reverse entpts)) );if (progn entpts);return entpts );lambda );function elist );mapcar ); setq ptslist ;get the reminder element and remove the other one (setq j 0) (princ "\nbreak point in use: ");debug line (print (nth i br_pts));debug line (princ "\npoints list: ");debug line (print ptslist);debug line (while (< j 2) (setq elem (nth j elist)) (princ "\ntest value:");debug line (print (equal (nth i br_pts) (nth 0 (nth j ptslist))));|debug line
[the test expression I talk about]|; (princ "\ncomparison point: ");debug line (print (nth 0 (nth j ptslist)));debug line (progn (if (equal (nth i br_pts) (nth 0 (nth j ptslist))) (if (= i 0) (progn (setq rement elem) (entdel (otherelem elist rement)) (print "elem in i=0");debug line );progn [then part of 2nd if], i=0 (progn (setq rement (otherelem elist elem) );setq (entdel elem) (print "elem in i = 1");debug line );progn [else part of 2nd if], i=1 );2nd if ;No else part for the 1st if );if [select the element that have the breaking point as its starting point] (setq j (1+ j)) );progn [of foreach] );end foreach (setq i (1+ i)) (setq elist (list rement));rewind elist );end while [of breaking & removing] (progn rement);what the function returns );end defun [tr-2ends]
____________
Sometimes it works fine with LWPOLYLINEs, especially when starting a fresh new drawing, but fails with POLYLINEs, SPLINEs, and LINEs.
Also, I doubt what I've written before (in the commented introduction to "tr-2ends") about what "Break" command do with the entity names of its resulted 2 objects.
imagine if AutoCAD assigns 2 new entity names for them, and the entity name of the old entity vanishes and is not assigned to anyone of them, how could I track those 2 object with just "entlast" that returns only the last "generated" entity name?!
In Short:
- The function doesn't always behave as intended, and when it doesn't do so, the test expression returns a seemingly incorrect result.
- What does "Break" command really do with the entity names with the old entity and the resulted 2 entities ?
Solved! Go to Solution.