automicro Posted April 23, 2009 Posted April 23, 2009 Perhaps i have to post this here? http://www.cadtutor.net/forum/showthread.php?p=231922#post231922 Can some one expert help me to develop a Lisp routine? I think is not easy to do that. /automicro Quote
CmdrDuh Posted April 23, 2009 Posted April 23, 2009 are we to assume that the polyline is in a roundish type shape? If not, how do you purpose to locate the center? What you want is actually pretty easy, make sure the polyline is closed, get the area, do some math to find a circle of the same area, use the centroid of the polyline area, and locate the circle. Quote
lpseifert Posted April 23, 2009 Posted April 23, 2009 I must have been bored... no error checking and not extensively tested, kinda slow Using CmdrDuh's idea... (defun c:test (/ ss1 num cnt ename obj rp ar rad) (vl-load-com) (setq ss1 (ssget '((0 . "*polyline"))) num (sslength ss1) cnt 0) (repeat num (setq ename (ssname ss1 cnt)) (setq obj (vlax-ename->vla-object ename)) (vlax-put-property obj 'Closed 1) (vl-cmdf "region" ename "") (setq obj (vlax-ename->vla-object (entlast))) (setq ar (vlax-get-property obj 'Area) rp (vlax-safearray->list (vlax-variant-value (vlax-get-property obj 'Centroid))) rad (sqrt (/ ar pi)) ) (entdel (entlast));remove this line if you want to keep original (vl-cmdf "circle" rp rad) (setq cnt (1+ cnt)) ) (princ) ) Quote
CmdrDuh Posted April 23, 2009 Posted April 23, 2009 I was just thinking out loud, HAHA, but thanks for making it a reality Quote
Lee Mac Posted April 23, 2009 Posted April 23, 2009 Great LISP for quickly typed one, - nice one Larry. Not to be critical, but I would only make a few aesthetic changes: [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:test [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] ss obj rp ar rad[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vl-load-com[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] ss [b][color=RED]([/color][/b][b][color=BLUE]ssget[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]list[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]0[/color][/b] [b][color=#ff00ff]"*POLYLINE"[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]getvar[/color][/b] [b][color=#ff00ff]"CTAB"[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]410[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]getvar[/color][/b] [b][color=#ff00ff]"CTAB"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]67[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]-[/color][/b] [b][color=#009900]1[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]getvar[/color][/b] [b][color=#ff00ff]"TILEMODE"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]foreach[/color][/b] x [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]vlax-ename->vla-object[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vl-remove-if[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]listp[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]cadr[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]ssnamex[/color][/b] ss[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vlax-put-property[/color][/b] x [b][color=DARKRED]'[/color][/b]Closed [b][color=#009900]1[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vl-cmdf[/color][/b] [b][color=#ff00ff]"_region"[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vlax-vla-object->ename[/color][/b] x[b][color=RED])[/color][/b] [b][color=#ff00ff]""[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] obj [b][color=RED]([/color][/b][b][color=BLUE]vlax-ename->vla-object[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]entlast[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] ar [b][color=RED]([/color][/b][b][color=BLUE]vlax-get-property[/color][/b] obj [b][color=DARKRED]'[/color][/b]Area[b][color=RED])[/color][/b] rp [b][color=RED]([/color][/b][b][color=BLUE]vlax-safearray->list[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vlax-variant-value[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vlax-get-property[/color][/b] obj [b][color=DARKRED]'[/color][/b]Centroid[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] rad [b][color=RED]([/color][/b][b][color=BLUE]sqrt[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] ar pi[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-delete[/color][/b] obj[b][color=RED])[/color][/b] [i][color=#990099]; -> Remove to Keep Original[/color][/i] [b][color=RED]([/color][/b][b][color=BLUE]vl-cmdf[/color][/b] [b][color=#ff00ff]"_circle"[/color][/b] rp rad[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=#ff00ff]"\n<!> Nothing Selected <!>"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] Quote
CmdrDuh Posted April 23, 2009 Posted April 23, 2009 Lee, how did you get your code to be color coded? Quote
Lee Mac Posted April 23, 2009 Posted April 23, 2009 I wrote a LISP to write a file with the [ color] tags in Quote
automicro Posted April 24, 2009 Author Posted April 24, 2009 Incredibly good, this savings me lots of jobs. Thanks to lpseifert and Lee Mac But he discovered that many of polylines is double stored above each other Is there a simple way to remove double elements stored? What a coincidence you both seem to enjoy motorcycles I myself drive BMW F800GS:) Quote
fuccaro Posted April 24, 2009 Posted April 24, 2009 But he discovered that many of polylines is double stored above each other Is there a simple way to remove double elements stored? Maybe OVERKILL? Quote
Lee Mac Posted April 24, 2009 Posted April 24, 2009 Incredibly good, this savings me lots of jobs. Thanks to lpseifert and Lee Mac But he discovered that many of polylines is double stored above each other Is there a simple way to remove double elements stored? I would recommend OVERKILL from Express Tools - that'll be a much better than anything I could write for you. What a coincidence you both seem to enjoy motorcycles I myself drive BMW F800GS:) Great looking bike - bit on the tall side, but a smooth ride. Quote
automicro Posted April 24, 2009 Author Posted April 24, 2009 I would recommend OVERKILL from Express Tools - that'll be a much better than anything I could write for you. Thanks for the tip. Your program works very well, thanks once again. Great looking bike - bit on the tall side, but a smooth ride. Is fun to drive even on gravel. Have gravel tires & GPS with very delaljerad map To investigate the small roads and terrain Quote
automicro Posted April 24, 2009 Author Posted April 24, 2009 Sorry did not understand that it was an AutoCAD commando, thought you meant something else But now I know, thanks for the tip Quote
Lee Mac Posted April 24, 2009 Posted April 24, 2009 OVERKILL isn't supplied with standard AutoCAD, but is in the Express Tools. Quote
CadTechJGC184 Posted April 24, 2009 Posted April 24, 2009 OK OK OK, does this lisp make a polyline out of a circle? I'm confused! I get this way alot! hahaha Thanks Quote
Lee Mac Posted April 24, 2009 Posted April 24, 2009 This LISP takes a Polyline, closes it, converts it to a region, finds the area and centroid of the region and creates a circle of radius (sqrt (/ pi)) and with the centroid as the centre. It then deletes the region. Quote
CadTechJGC184 Posted April 24, 2009 Posted April 24, 2009 WOW... that's a powerful lisp. can you then take that circle and turn it into a wipeout? I've never been able to turn a circle into a wipeout. I have so many ideas for lisp routines. i just have no clue how to create one. lol Quote
Lee Mac Posted April 24, 2009 Posted April 24, 2009 You need to select a closed polyline for a wipeout, so no, that LISP would not work... Quote
Lee Mac Posted April 24, 2009 Posted April 24, 2009 Maybe this though: [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:cwipe [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] vlst ovar seg i cEnt cObj iPt ptLst[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vl-load-com[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] vlst [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b][b][color=#ff00ff]"CMDECHO"[/color][/b] [b][color=#ff00ff]"OSMODE"[/color][/b][b][color=RED])[/color][/b] ovar [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]getvar[/color][/b] vlst[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]setvar[/color][/b] vlst [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b][b][color=#009900]0[/color][/b] [b][color=#009900]0[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] seg [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] pi [b][color=#009900]100[/color][/b][b][color=RED])[/color][/b] i [b][color=#009900]-1[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] cEnt [b][color=RED]([/color][/b][b][color=BLUE]car[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]entsel[/color][/b] [b][color=#ff00ff]"\nSelect Circle for Wipeout: "[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]eq[/color][/b] [b][color=#ff00ff]"AcDbCircle"[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-ObjectName[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] cObj [b][color=RED]([/color][/b][b][color=BLUE]vlax-ename->vla-object[/color][/b] cEnt[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]progn[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]while[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]<=[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] Par [b][color=RED]([/color][/b][b][color=BLUE]*[/color][/b] seg [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] i [b][color=RED]([/color][/b][b][color=BLUE]1+[/color][/b] i[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]*[/color][/b] [b][color=#009900]2[/color][/b] pi[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] iPt [b][color=RED]([/color][/b][b][color=BLUE]vlax-curve-getPointatParam[/color][/b] cObj Par[b][color=RED])[/color][/b] ptLst [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] iPt ptLst[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]command[/color][/b] [b][color=#ff00ff]"_pline"[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]command[/color][/b] ptLst[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]command[/color][/b] [b][color=#ff00ff]"_C"[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]command[/color][/b] [b][color=#ff00ff]"_wipeout"[/color][/b] [b][color=#ff00ff]"_P"[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]entlast[/color][/b][b][color=RED])[/color][/b] [b][color=#ff00ff]"_Y"[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]entdel[/color][/b] cEnt[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [i][color=#990099]; Remove to keep Circle[/color][/i] [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=#ff00ff]"\n<!> No Circle Selected <!>"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]setvar[/color][/b] vlst ovar[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] Quote
CadTechJGC184 Posted April 26, 2009 Posted April 26, 2009 thanks LeeMac, I will try this whe I get to work today. Quote
Lee Mac Posted April 26, 2009 Posted April 26, 2009 That code uses 200 segments, but you can increase/decrease this if necessary. 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.