Jack_O'neill Posted June 26, 2011 Share Posted June 26, 2011 Hey guys... You know how when using the measure command to place objects along a line, it starts at whatever interval you've asked for and goes down the line till it runs out of room. You always have a bit left over at the end. Does anybody have a bit of code that will take that bit left over at the end, divide it in 2 and move the nodes (or blocks or whatever) over to center them up on the line? In other words, if there is 24" left over at the end, I want it to move everything over so that there is 12" at each end instead of 24" at one end. anybody got a bit of code that will do that? There was a time when I could have come up with this myself, but i have forgotten too much to know where to start. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 26, 2011 Share Posted June 26, 2011 It might be easier to just write your own 'measure' command. The following should behave identical to the in-built Measure command (in 2010 at least), however, will create a 'centered measure': ([color=BLUE]defun[/color] c:cmeasure ( [color=BLUE]/[/color] *error* _StartUndo _EndUndo _SelectIf _IsCurveObject acdoc al bl d0 di en mx nm pt ) [color=GREEN];; Centered Measure - © Lee Mac 2011 - www.lee-mac.com[/color] ([color=BLUE]defun[/color] *error* ( msg ) ([color=BLUE]if[/color] acdoc (_EndUndo acdoc)) ([color=BLUE]or[/color] ([color=BLUE]wcmatch[/color] ([color=BLUE]strcase[/color] msg) [color=MAROON]"*BREAK,*CANCEL*,*EXIT*"[/color]) ([color=BLUE]princ[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\n** Error: "[/color] msg [color=MAROON]" **"[/color]))) ([color=BLUE]princ[/color]) ) ([color=BLUE]defun[/color] _StartUndo ( doc ) (_EndUndo doc) ([color=BLUE]vla-StartUndoMark[/color] doc) ) ([color=BLUE]defun[/color] _EndUndo ( doc ) ([color=BLUE]if[/color] ([color=BLUE]=[/color] 8 ([color=BLUE]logand[/color] 8 ([color=BLUE]getvar[/color] 'UNDOCTL))) ([color=BLUE]vla-EndUndoMark[/color] doc) ) ) ([color=BLUE]defun[/color] _SelectIf ( msg pred func [color=BLUE]/[/color] sel ) ([color=BLUE]setq[/color] pred ([color=BLUE]eval[/color] pred)) ([color=BLUE]while[/color] ([color=BLUE]progn[/color] ([color=BLUE]setvar[/color] 'ERRNO 0) ([color=BLUE]setq[/color] sel ([color=BLUE]car[/color] (func msg))) ([color=BLUE]cond[/color] ( ([color=BLUE]=[/color] 7 ([color=BLUE]getvar[/color] 'ERRNO)) ([color=BLUE]princ[/color] [color=MAROON]"\nMissed, Try again."[/color]) ) ( ([color=BLUE]eq[/color] 'ENAME ([color=BLUE]type[/color] sel)) ([color=BLUE]if[/color] ([color=BLUE]and[/color] pred ([color=BLUE]not[/color] (pred sel))) ([color=BLUE]princ[/color] [color=MAROON]"\nInvalid Object Selected."[/color]) ) ) ) ) ) sel ) ([color=BLUE]defun[/color] _IsCurveObject ( entity [color=BLUE]/[/color] param ) ([color=BLUE]and[/color] ([color=BLUE]not[/color] ([color=BLUE]vl-catch-all-error-p[/color] ([color=BLUE]setq[/color] param ([color=BLUE]vl-catch-all-apply[/color] '[color=BLUE]vlax-curve-getendparam[/color] ([color=BLUE]list[/color] entity)) ) ) ) param ) ) ([color=BLUE]setq[/color] acdoc ([color=BLUE]vla-get-activedocument[/color] ([color=BLUE]vlax-get-acad-object[/color])) nm ([color=BLUE]trans[/color] '(0. 0. 1.) 1 0 [color=BLUE]t[/color]) ) ([color=BLUE]if[/color] ([color=BLUE]setq[/color] en (_SelectIf [color=MAROON]"\nSelect Object to Measure: "[/color] '_isCurveObject [color=BLUE]entsel[/color])) ([color=BLUE]progn[/color] ([color=BLUE]initget[/color] 7 [color=MAROON]"Block"[/color]) ([color=BLUE]setq[/color] di ([color=BLUE]getdist[/color] [color=MAROON]"\nSpecify length of segment or [block]: "[/color])) ([color=BLUE]if[/color] ([color=BLUE]eq[/color] [color=MAROON]"Block"[/color] di) ([color=BLUE]progn[/color] ([color=BLUE]while[/color] ([color=BLUE]progn[/color] ([color=BLUE]setq[/color] bl ([color=BLUE]getstring[/color] [color=BLUE]t[/color] [color=MAROON]"\nEnter name of block to insert: "[/color])) ([color=BLUE]cond[/color] ( ([color=BLUE]not[/color] ([color=BLUE]snvalid[/color] bl)) ([color=BLUE]princ[/color] [color=MAROON]"\nInvalid block name."[/color]) ) ( ([color=BLUE]not[/color] ([color=BLUE]tblsearch[/color] [color=MAROON]"BLOCK"[/color] bl)) ([color=BLUE]princ[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\nCannot find block \""[/color] bl [color=MAROON]"\"."[/color])) ) ) ) ) ([color=BLUE]initget[/color] [color=MAROON]"Yes No"[/color]) ([color=BLUE]setq[/color] al ([color=BLUE]not[/color] ([color=BLUE]eq[/color] [color=MAROON]"No"[/color] ([color=BLUE]getkword[/color] [color=MAROON]"\nAlign block with object? [Yes/No] <Y>: "[/color])))) ([color=BLUE]initget[/color] 7) ([color=BLUE]setq[/color] di ([color=BLUE]getdist[/color] [color=MAROON]"\nSpecify length of segment: "[/color])) ) ) ([color=BLUE]setq[/color] mx ([color=BLUE]vlax-curve-getdistatparam[/color] en ([color=BLUE]vlax-curve-getendparam[/color] en)) d0 ([color=BLUE]-[/color] ([color=BLUE]/[/color] ([color=BLUE]-[/color] mx ([color=BLUE]*[/color] di ([color=BLUE]fix[/color] ([color=BLUE]/[/color] mx di)))) 2.) di) ) (_StartUndo acdoc) ([color=BLUE]while[/color] ([color=BLUE]and[/color] ([color=BLUE]<=[/color] ([color=BLUE]setq[/color] d0 ([color=BLUE]+[/color] d0 di)) mx) ([color=BLUE]setq[/color] pt ([color=BLUE]vlax-curve-getpointatdist[/color] en d0))) ([color=BLUE]if[/color] bl ([color=BLUE]entmakex[/color] ([color=BLUE]list[/color] ([color=BLUE]cons[/color] 0 [color=MAROON]"INSERT"[/color]) ([color=BLUE]cons[/color] 2 bl) ([color=BLUE]cons[/color] 10 ([color=BLUE]trans[/color] pt 0 nm)) ([color=BLUE]cons[/color] 50 ([color=BLUE]if[/color] al ([color=BLUE]angle[/color] '(0. 0. 0.) ([color=BLUE]trans[/color] ([color=BLUE]vlax-curve-getfirstderiv[/color] en ([color=BLUE]vlax-curve-getparamatpoint[/color] en pt)) 0 nm ) ) 0. ) ) ([color=BLUE]cons[/color] 210 nm) ) ) ([color=BLUE]entmakex[/color] ([color=BLUE]list[/color] ([color=BLUE]cons[/color] 0 [color=MAROON]"POINT"[/color]) ([color=BLUE]cons[/color] 10 pt))) ) ) (_EndUndo acdoc) ) ([color=BLUE]princ[/color] [color=MAROON]"\n*Cancel*"[/color]) ) ([color=BLUE]princ[/color]) ) ([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color]) Quote Link to comment Share on other sites More sharing options...
Jack_O'neill Posted June 26, 2011 Author Share Posted June 26, 2011 Thanks Lee...that is exactly what I wanted it to do. I gotta get a book or two, and bone up on this stuff again. I used to write a little code now and again, but the last time I did anything was back in the 80's. There's alot more to this program than I thought there'd be. I appreciate the help! been doing that manually for stuff like parking spaces and such. This will be much quicker. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 26, 2011 Share Posted June 26, 2011 Thanks Lee...that is exactly what I wanted it to do. I gotta get a book or two' date=' and bone up on this stuff again. I used to write a little code now and again, but the last time I did anything was back in the 80's. There's alot more to this program than I thought there'd be.[/quote'] You're welcome Jack The program could probably be made a lot shorter, but I wanted to emulate the behaviour of the standard Measure command as much as possible with all its options and prompts; and furthermore add a bit more error trapping, which required a little extra code. I appreciate the help! been doing that manually for stuff like parking spaces and such. This will be much quicker. You're very welcome Jack, I'm glad it will save you some time. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted June 26, 2011 Share Posted June 26, 2011 Thanks Lee...that is exactly what I wanted it to do. I gotta get a book or two' date=' and bone up on this stuff again. I used to write a little code now and again, but the last time I did anything was back in the 80's. There's alot more to this program than I thought there'd be. I appreciate the help! been doing that manually for stuff like parking spaces and such. This will be much quicker.[/quote'] Jack, In addition to Lee's excellent site, I've found David Stein's books to be very helpful. Quote Link to comment Share on other sites More sharing options...
Jack_O'neill Posted June 26, 2011 Author Share Posted June 26, 2011 Jack, In addition to Lee's excellent site, I've found David Stein's books to be very helpful. Thanks! I'll take a look. Been looking round on Lee's site...very impressive. --edit--the Visual Lisp Developers Bible is available as an ebook! --edit--if you search Amazon for Davd Stein and you have delicate sensibilities, be warned, there's an author by the same name that writes erotic fiction, so don't think you've been had if you run across this. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 26, 2011 Share Posted June 26, 2011 Cheers guys Quote Link to comment Share on other sites More sharing options...
BlackBox Posted June 26, 2011 Share Posted June 26, 2011 @ Lee - you're welcome; it's well deserved. @ Jack - David Stein's Most exit (e)book is the second book of his I now have. Unfortunately it is relegated to being an ebook only until he's made enough $$$ to release the PDF & Hardcopy. The only thing that made having it difficult (as I purchased the 2011 version a few months ago, was the kindle app / site not being permitted on my work computer. - thanks IT. LoL Quote Link to comment Share on other sites More sharing options...
Jack_O'neill Posted June 27, 2011 Author Share Posted June 27, 2011 When the projects get scarce around here, I sometimes get to thinking that I should go find a job in the corporate world, then I get reminded of some nonsense like this. I am my IT dept, so restrictions such as this are not a problem. Quote Link to comment Share on other sites More sharing options...
Tyke Posted June 27, 2011 Share Posted June 27, 2011 @ Lee - you're welcome; it's well deserved. @ Jack - David Stein's Most exit (e)book is the second book of his I now have. Unfortunately it is relegated to being an ebook only until he's made enough $$$ to release the PDF & Hardcopy. The only thing that made having it difficult (as I purchased the 2011 version a few months ago, was the kindle app / site not being permitted on my work computer. - thanks IT. LoL RenderMan buy a Kindle. I bought the big one and have all my ebooks and PDF books on it. It's a super piece of kit and very handy to have with you when you are on the road. I can save various documents as PDF and show them to clients on the Kindle rather than having to take the laptop with me. It takes up a lot less room than a laptop and the battery goes for weeks without recharging. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted June 27, 2011 Share Posted June 27, 2011 RenderMan buy a Kindle. I bought the big one and have all my ebooks and PDF books on it. It's a super piece of kit and very handy to have with you when you are on the road. I can save various documents as PDF and show them to clients on the Kindle rather than having to take the laptop with me. It takes up a lot less room than a laptop and the battery goes for weeks without recharging. It's funny you mentioned purchasing a tablet device, as we're in the process of evaluating iPads as they would allow us to use AutoCAD WS to make plan notations, etc. and take pictures, meeting notes and email while doing site walk throughs. While IT presently does not allow me to have the Kindle reader installed on my work laptop, I do use the Kidle App on my iPhone. This works very well (jus a small screen), and would work better on an iPad (plus all the extras noted above). :wink: Quote Link to comment Share on other sites More sharing options...
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.