Small Fish Posted May 12, 2009 Posted May 12, 2009 I am using the line (setq e1 (entlast)) to capture the last entity created. The last entity created is a polyline. However in my code I have a selection set of circles and for some reason it captures the last circle entity in the selection set. How can I force it to look for the last polyline created rather than a circle? thanks anyone for your help Quote
Lee Mac Posted May 12, 2009 Posted May 12, 2009 If the polyline is the last object created, then that should be the one that is picked up by "entlast". Are you sure you are not creating the polyline, then the circles, then modifying the polyline maybe? A modified polyline will not be the last entity created. Quote
Commandobill Posted May 12, 2009 Posted May 12, 2009 If you are copying over the circles that also counts as being the last entity created. Just like Lee said i would double check your code. Quote
Small Fish Posted May 12, 2009 Author Posted May 12, 2009 Yes you are both correct. What happens: first I select the closed pline then a ssget over the circles - then the pline is modified. Perhaps entlast is a not a good option to capture the modified pline. Is there some other way to capture this entity? Quote
Lee Mac Posted May 12, 2009 Posted May 12, 2009 If you are selecting it, then surely you have answered your own question.. Quote
Small Fish Posted May 12, 2009 Author Posted May 12, 2009 okay then let me reword my question - how can I capture the polyline that has been modified as a variable? Quote
Lee Mac Posted May 12, 2009 Posted May 12, 2009 okay then let me reword my question - how can I capture the polyline that has been modified as a variable? If it is the same polyline, then it will not matter - referencing the entity name will return the newly modified results. Quote
Small Fish Posted May 12, 2009 Author Posted May 12, 2009 To make it clearer as to what I am trying to achieve- here is my code - similar to a previous post. I thought Regenall would solve it -but no! To use it draw a closed rectangle pline (about 1000x1000) and place some circles inside it. Select the pline then select all the circles. You will find that the first time you try, a region will be created on the pline. However the second time (on a new example) one of the circles will turn into a region. Any ideas how it can be fixed? (defun c:Extpline (/ enaPline ObjName LowLeft UpRightLowRight UpLeft TopCl BotCl lEnt pt1 pt2 lDat test flag ss tCirc subSs total ent subSs_lst cLst Rad LenExtrusion TempPtLt en3L IntPointLt ExtPtL ExtPtTopL ExtPtBotL CircTopL CircBotL en4L IntPointTopL en5L IntPointBotL en6L en7L en8L test FinalOutline) (vl-load-com) (setvar "osmode" 0) (setq enaPline (car (entsel "\nSelect rectangle outline : "))) (setq ObjName (vlax-ename->vla-object enaPline)) (vla-GetBoundingBox ObjName 'LowLeft 'UpRight) (setq LowLeft (vlax-safearray->list LowLeft) UpRight (vlax-safearray->list UpRight) LowRight(list(car UpRight)(cadr LowLeft)) UpLeft (list(car LowLeft)(cadr UpRight)) );setq ;Find vertical centreline rectangle (setq TopCl (mapcar '+ UpLeft (mapcar '/ (mapcar '- UpRight UpLeft) '(2.0 2.0 2.0))));Top of centreline (setq BotCl (mapcar '+ LowLeft (mapcar '/ (mapcar '- LowRight LowLeft) '(2.0 2.0 2.0))));Bottom of centreline (command "LINE" TopCl BotCl "");draw temp line (setq lEnt (entlast)) (if(and ;;; (setq lEnt (car (entsel "\n>>>...Select Vertical Line...>>>: "))) (eq "LINE" (cdadr (entget lEnt))) (null (redraw lEnt 3)) (setq pt1 (getpoint "\n>>>...Pick First Point of Window over circles...>>>: ")) (null (initget 32)) (setq pt2 (getcorner pt1 "\n>>>...Pick Second Point of Window over circles...>>>>: ")) (null (redraw lEnt 4))) (progn (setq lDat (list (cdr (assoc 10 (entget lEnt))) (cdr (assoc 11 (entget lEnt))))) (entdel lEnt) (repeat 2 (setq test 1) (if (setq ss (ssget "_c" pt1 pt2 (list '(0 . "CIRCLE")(cons -4 (if flag ">=,*,*" " (cons 10 (append (list (apply (if flag 'max 'min) (mapcar 'car lDat))) '(0 0)))))) (while (not (zerop (sslength ss))) (setq tCirc (ssname ss 0)) (if (setq subSs (ssget "_c" pt1 pt2 (list (cons 0 "CIRCLE") (cons -4 (if flag ">=,=,*" " (cons 10 (append (list (apply (if flag 'max 'min) (mapcar 'car lDat))) (cddr (assoc 10 (entget tCirc)))))))) (progn (setq total 0.0) (foreach ent (setq subSs_lst (vl-remove-if 'listp (mapcar 'cadr (ssnamex subSs)))) (setq total (+ total (vla-get-Area (vlax-ename->vla-object ent))))) (setq cLst(car (vl-sort (mapcar '(lambda (x) (cdr (assoc 10 (entget x)))) subSs_lst) '(lambda (x1 x2) ( Rad (car(vl-sort (mapcar '(lambda (x) (cdr (assoc 40 (entget x)))) subSs_lst) '(lambda (r1 r2) (> r1 r2))))) (setq LenExtrusion 800);test length of extrusion (if flag (progn (setq TempPtRt (polar cLst 0 3000));temp pt to right (command "_.pline" cLst TempPtRt "") (setq en3R (entlast)) (setq IntPointRt (safearray-value(variant-value(vla-intersectwith (vlax-ename->vla-object enaPline ) (vlax-ename->vla-object en3R)acExtendNone))) );setq (setq ExtPtR (polar IntPointRt 0 LenExtrusion)) (setq ExtPtTopR (polar ExtPtR (* 0.5 pi) rad)) (setq ExtPtBotR(polar ExtPtR (* 1.5 pi) rad)) (setq CircTopR (polar cLst (* 0.5 pi) rad)) (setq CircBotR(polar cLst (* 1.5 pi) rad)) (command "_.pline" CircTopR ExtPtTopR "") (setq en4R (entlast)) (setq IntPointTopR (safearray-value(variant-value(vla-intersectwith (vlax-ename->vla-object enaPline ) (vlax-ename->vla-object en4R)acExtendNone))) );setq (command "_.pline" CircBotR ExtPtBotR "");temp bottom pline (setq en5R (entlast)) (setq IntPointBotR (safearray-value(variant-value(vla-intersectwith (vlax-ename->vla-object enaPline) (vlax-ename->vla-object en5R)acExtendNone))) );setq (command "_.pline" IntPointBotR ExtPtBotR "") (setq en6R (entlast)) (command "_.pline" IntPointTopR ExtPtTopR "") (setq en7R (entlast)) (command "_.pline" ExtPtTopR ExtPtBotR "") (setq en8R (entlast)) (entdel en4R) (entdel en5R) (entdel en3R) (command "BREAK" enaPline IntPointBotR IntPointTopR) (command "_.PEDIT" enaPline "_JOIN" en6R en7R en8R "" "") );progn );if (mapcar '(lambda (x) (ssdel x ss)) subSs_lst) );progn );if (ssdel tCirc ss) (setq test (1+ test)))) (and (not flag)) (setq flag T)) );progn );if (setq FinalOutline (entlast));capture new polyline entity (command "_.REGION" FinalOutline "" );make region (princ ) );defun Quote
Lee Mac Posted May 12, 2009 Posted May 12, 2009 Give this a shot: (defun c:Extpline (/ enaPline ObjName LowLeft UpRight LowRight UpLeft TopCl BotCl lEnt pt1 pt2 lDat test flag ss tCirc subSs total ent subSs_lst cLst Rad LenExtrusion TempPtLt en3L IntPointLt ExtPtL ExtPtTopL ExtPtBotL CircTopL CircBotL en4L IntPointTopL en5L IntPointBotL en6L en7L en8L test FinalOutline) (vl-load-com) (setvar "osmode" 0) (setq enaPline (car (entsel "\nSelect rectangle outline : "))) (setq ObjName (vlax-ename->vla-object enaPline)) (vla-GetBoundingBox ObjName 'LowLeft 'UpRight) (setq LowLeft (vlax-safearray->list LowLeft) UpRight (vlax-safearray->list UpRight) LowRight (list (car UpRight) (cadr LowLeft)) UpLeft (list (car LowLeft) (cadr UpRight)) ) ;setq ;Find vertical centreline rectangle (setq TopCl (mapcar '+ UpLeft (mapcar '/ (mapcar '- UpRight UpLeft) '(2.0 2.0 2.0)))) ;Top of centreline (setq BotCl (mapcar '+ LowLeft (mapcar '/ (mapcar '- LowRight LowLeft) '(2.0 2.0 2.0)))) ;Bottom of centreline (command "LINE" TopCl BotCl "") ;draw temp line (setq lEnt (entlast)) (if (and ;;; (setq lEnt (car (entsel "\n>>>...Select Vertical Line...>>>: "))) (eq "LINE" (cdadr (entget lEnt))) (null (redraw lEnt 3)) (setq pt1 (getpoint "\n>>>...Pick First Point of Window over circles...>>>: ")) (null (initget 32)) (setq pt2 (getcorner pt1 "\n>>>...Pick Second Point of Window over circles...>>>>: ")) (null (redraw lEnt 4))) (progn (setq lDat (list (cdr (assoc 10 (entget lEnt))) (cdr (assoc 11 (entget lEnt))))) (entdel lEnt) (repeat 2 (setq test 1) (if (setq ss (ssget "_c" pt1 pt2 (list '(0 . "CIRCLE") (cons -4 (if flag ">=,*,*" "<=,*,*")) (cons 10 (append (list (apply (if flag 'max 'min) (mapcar 'car lDat))) '(0 0)))))) (while (not (zerop (sslength ss))) (setq tCirc (ssname ss 0)) (if (setq subSs (ssget "_c" pt1 pt2 (list (cons 0 "CIRCLE") (cons -4 (if flag ">=,=,*" "<=,=,*")) (cons 10 (append (list (apply (if flag 'max 'min) (mapcar 'car lDat))) (cddr (assoc 10 (entget tCirc)))))))) (progn (setq total 0.0) (foreach ent (setq subSs_lst (vl-remove-if 'listp (mapcar 'cadr (ssnamex subSs)))) (setq total (+ total (vla-get-Area (vlax-ename->vla-object ent))))) (setq cLst (car (vl-sort (mapcar '(lambda (x) (cdr (assoc 10 (entget x)))) subSs_lst) '(lambda (x1 x2) (< (car x1) (car x2))))) Rad (car (vl-sort (mapcar '(lambda (x) (cdr (assoc 40 (entget x)))) subSs_lst) '(lambda (r1 r2) (> r1 r2))))) (setq LenExtrusion 800) ;test length of extrusion (if flag (progn (setq TempPtRt (polar cLst 0 3000)) ;temp pt to right (command "_.pline" cLst TempPtRt "") (setq en3R (entlast)) (setq IntPointRt (safearray-value (variant-value (vla-intersectwith (vlax-ename->vla-object enaPline) (vlax-ename->vla-object en3R) acExtendNone))) ) ;setq (setq ExtPtR (polar IntPointRt 0 LenExtrusion)) (setq ExtPtTopR (polar ExtPtR (* 0.5 pi) rad)) (setq ExtPtBotR (polar ExtPtR (* 1.5 pi) rad)) (setq CircTopR (polar cLst (* 0.5 pi) rad)) (setq CircBotR (polar cLst (* 1.5 pi) rad)) (command "_.pline" CircTopR ExtPtTopR "") (setq en4R (entlast)) (setq IntPointTopR (safearray-value (variant-value (vla-intersectwith (vlax-ename->vla-object enaPline) (vlax-ename->vla-object en4R) acExtendNone))) ) ;setq (command "_.pline" CircBotR ExtPtBotR "") ;temp bottom pline (setq en5R (entlast)) (setq IntPointBotR (safearray-value (variant-value (vla-intersectwith (vlax-ename->vla-object enaPline) (vlax-ename->vla-object en5R) acExtendNone))) ) ;setq (command "_.pline" IntPointBotR ExtPtBotR "") (setq en6R (entlast)) (command "_.pline" IntPointTopR ExtPtTopR "") (setq en7R (entlast)) (command "_.pline" ExtPtTopR ExtPtBotR "") (setq en8R (entlast)) (entdel en4R) (entdel en5R) (entdel en3R) (command "BREAK" enaPline IntPointBotR IntPointTopR) (command "_.PEDIT" enaPline "_JOIN" en6R en7R en8R "" "") ) ;progn ) ;if (mapcar '(lambda (x) (ssdel x ss)) subSs_lst) ) ;progn ) ;if (ssdel tCirc ss) (setq test (1+ test)))) (and (not flag)) (setq flag T)) ) ;progn ) ;if ;(setq FinalOutline (entlast)) ;capture new polyline entity (command "_.REGION" enaPline "") ;make region (princ) ) ;defun Quote
Small Fish Posted May 12, 2009 Author Posted May 12, 2009 Yee-hah! Lee mac you have come to my rescue I thought I tried that option. It's good when you get a fresh pair of eyes. I feel a little bit stupid now..... many thanks Small fish Quote
Lee Mac Posted May 12, 2009 Posted May 12, 2009 Yee-hah! Lee mac you have come to my rescue I thought I tried that option. It's good when you get a fresh pair of eyes. I feel a little bit stupid now..... many thanks Small fish No problems Small Fish -- glad it worked Quote
Commandobill Posted May 13, 2009 Posted May 13, 2009 hahahaha lee you tried so hard not to just hand out the answer... but in the end u couldn't resist Quote
Lee Mac Posted May 13, 2009 Posted May 13, 2009 hahahaha lee you tried so hard not to just hand out the answer... but in the end u couldn't resist Well, now I try to get people to work out their own answers a bit more (with a few pointers of course) instead of jus handing out the solution. But sometimes its easier just to give the correct way. Quote
Recommended Posts
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.