SCaldeira Posted April 20, 2012 Posted April 20, 2012 I urgently needed a lisp routine that performs the following: I have many closed polylines, each one with an name. I needed a lisp routine that asks the name of this area and quickly runs a "Zoom To" for that area. Like a Zoom extends on the polyline limits. Someone could help me? Thank you. Quote
SCaldeira Posted April 20, 2012 Author Posted April 20, 2012 Here is a simple example file. Example.dwg Quote
Tharwat Posted April 20, 2012 Posted April 20, 2012 I think you will search for the location of a polyline by the text string only and not by Polylines . right ? Quote
SCaldeira Posted April 20, 2012 Author Posted April 20, 2012 I want to identify the text within an area bounded by a closed polyline and zoom extend this same area. ???. Greetings. Quote
Lt Dan's legs Posted April 20, 2012 Posted April 20, 2012 Hope this helps get you started.. (defun c:test ( / p ) (if (and (setq p (car (entsel "\nSpecify polyline: "))) (eq "LWPOLYLINE" (cdr (assoc 0 (entget p)))) (setq p (vlax-ename->vla-object p)) ) (apply (function vla-zoomwindow) (cons (vlax-get-acad-object) ( (lambda ( / ll ur ) (vla-getboundingbox p 'll 'ur ) (list ll ur) ) ) ) ) )(princ) ) Quote
Lee Mac Posted April 20, 2012 Posted April 20, 2012 Maybe try something like this: [color=GREEN];; Zoom to Polyline - Lee Mac 2012[/color] [color=GREEN];; Prompts for the 'name' of a Polyline, that is, the contents of text[/color] [color=GREEN];; residing within the Polyline Boundary, and zooms to the Polyline.[/color] ([color=BLUE]defun[/color] c:zoomto ( [color=BLUE]/[/color] cmd ent pt1 pt2 sel str ) ([color=BLUE]while[/color] ([color=BLUE]not[/color] ([color=BLUE]or[/color] ([color=BLUE]zerop[/color] ([color=BLUE]strlen[/color] ([color=BLUE]setq[/color] str ([color=BLUE]getstring[/color] [color=BLUE]t[/color] [color=MAROON]"\nSpecify Polyline Name: "[/color])))) ([color=BLUE]setq[/color] sel ([color=BLUE]ssget[/color] [color=MAROON]"_X"[/color] ([color=BLUE]list[/color] '(0 . [color=MAROON]"TEXT,MTEXT"[/color]) ([color=BLUE]cons[/color] 1 ([color=BLUE]vl-list->string[/color] ([color=BLUE]apply[/color] '[color=BLUE]append[/color] ([color=BLUE]mapcar[/color] ([color=BLUE]function[/color] ([color=BLUE]lambda[/color] ( a b ) ([color=BLUE]cond[/color] ( ([color=BLUE]member[/color] a '(35 64 46 42 63 126 91 93 45 44)) ([color=BLUE]list[/color] 96 a) ) ( ([color=BLUE]<[/color] 47 a 58) ([color=BLUE]list[/color] a) ) ( ([color=BLUE]list[/color] 91 a b 93)) ) ) ) ([color=BLUE]vl-string->list[/color] ([color=BLUE]strcase[/color] str)) ([color=BLUE]vl-string->list[/color] ([color=BLUE]strcase[/color] str [color=BLUE]t[/color])) ) ) ) ) ) ) ) ) ) ([color=BLUE]princ[/color] [color=MAROON]"\nPolyline not found."[/color]) ) ([color=BLUE]if[/color] sel ([color=BLUE]progn[/color] ([color=BLUE]setq[/color] cmd ([color=BLUE]getvar[/color] 'cmdecho) ent ([color=BLUE]entlast[/color]) ) ([color=BLUE]setvar[/color] 'cmdecho 0) ([color=BLUE]vl-catch-all-apply[/color] '([color=BLUE]lambda[/color] [color=BLUE]nil[/color] ([color=BLUE]vl-cmdf[/color] [color=MAROON]"_.-boundary"[/color] [color=MAROON]"_A"[/color] [color=MAROON]"_I"[/color] [color=MAROON]"_N"[/color] [color=MAROON]""[/color] [color=MAROON]"_O"[/color] [color=MAROON]"_P"[/color] [color=MAROON]""[/color] [color=MAROON]"_non"[/color] ([color=BLUE]trans[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 10 ([color=BLUE]entget[/color] ([color=BLUE]ssname[/color] sel 0)))) 0 1) [color=MAROON]""[/color] ) ) ) ([color=BLUE]setvar[/color] 'cmdecho cmd) ([color=BLUE]if[/color] ([color=BLUE]equal[/color] ent ([color=BLUE]setq[/color] ent ([color=BLUE]entlast[/color]))) ([color=BLUE]princ[/color] [color=MAROON]"\nUnable to Zoom to Polyline."[/color]) ([color=BLUE]progn[/color] ([color=BLUE]vla-getboundingbox[/color] ([color=BLUE]vlax-ename->vla-object[/color] ent) 'pt1 'pt2) ([color=BLUE]vla-zoomwindow[/color] ([color=BLUE]vlax-get-acad-object[/color]) pt1 pt2) ([color=BLUE]entdel[/color] ent) ) ) ) ) ([color=BLUE]princ[/color]) ) ([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color]) Quote
SCaldeira Posted April 20, 2012 Author Posted April 20, 2012 You are extraordinary. Thank you both. Best regards. Quote
Lee Mac Posted April 20, 2012 Posted April 20, 2012 You're welcome SCaldeira, it was a fun one to write Quote
pBe Posted April 21, 2012 Posted April 21, 2012 (edited) Maybe try something like this: ....(< 47 a 58) I didnt know " (vl-list->string (apply 'append (mapcar ...... (vl-string->list (strcase str)) (vl-string->list (strcase str t)) ) ) ) Clever utilizing range for a non case sensitive selection. Never cease to amaze me my friend Edited April 21, 2012 by pBe Quote
Lee Mac Posted April 21, 2012 Posted April 21, 2012 Thank you pBe, I'm delighted that I am able to inspire you Quote
SCaldeira Posted April 21, 2012 Author Posted April 21, 2012 A term used in my country: Many years to turn the steaks on the grill. Congratulations, LeeMac. Quote
ketxu Posted April 22, 2012 Posted April 22, 2012 I think it still working without check condition number, Wildcard... Sth like this : [color=#000000][color=#007700]([/color][color=#0000BB]vl[/color][color=#007700]-list->[/color][color=#0000BB]string [/color][color=#007700]([/color][color=#0000BB]apply [/color][color=#DD0000]'append (mapcar '[/color][color=#007700]([/color][color=#0000BB]lambda [/color][color=#007700]( [/color][color=#0000BB]a b [/color][color=#007700])(list [/color][color=#0000BB]91 a b 93[/color][color=#007700])) ([/color][color=#0000BB]vl[/color][color=#007700]-[/color][color=#0000BB]string[/color][color=#007700]->[/color][color=#0000BB]list [/color][color=#007700]([/color][color=#0000BB]xstrcase str[/color][color=#007700])) ([/color][color=#0000BB]vl[/color][color=#007700]-[/color][color=#0000BB]string[/color][color=#007700]->[/color][color=#0000BB]list [/color][color=#007700]([/color][color=#0000BB]strcase str t[/color][color=#007700])) ) ) ) [/color][/color] Quote
Lee Mac Posted April 22, 2012 Posted April 22, 2012 I think it still working without check condition number, Wildcard...Sth like this : Consider the case in which the name contains wildcard operators, e.g. "a*b" Concerning the numbers, I saw no reason to duplicate them in the wildcard filter... Quote
ketxu Posted April 23, 2012 Posted April 23, 2012 That right Lee. I just found that it still work even we want to find str "a*b" (with * is a normal character) , it means "[**]" = "'*" in ssget filter. Quote
Lee Mac Posted April 23, 2012 Posted April 23, 2012 I think it's 6 of one and half a dozen of the other, but personally, I think: "[Aa]`*[bb]" is more readable than: "[Aa][**][bb]" Quote
SCaldeira Posted April 24, 2012 Author Posted April 24, 2012 Lee, this code is very good and I'm trying to understand line by line all the steps. I would like to learn autolisp with all yours cooperation, and I believe it is a good way to learn. Taking this same code, and according to the attached file that we have areas that begin with "AA", "AB" and "AC", how would the code be changed so that it was possible to make a ZoomTo, for example, all names areas starting with "AB"? Best regards. Example2.dwg 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.