Ohnoto Posted May 7, 2011 Share Posted May 7, 2011 (edited) I have some code from a guy that used to work for us where it inserts a block with the distance value at the midpoint between two points. I'd like to be able to adjust this to where it defaults to do the same thing, but where it puts the block between between each pole block from a grouped selection based on stationing values, similar to this thread where it adjusts numbers based on those values... http://www.cadtutor.net/forum/showthread.php?58422-Attribute-Renumber&p=395948&viewfull=1#post395948 ... Where the user doesn't have to click points at each pole. Attached is the LISP and DWG blocks. EXADO.dwg EXADO_Main - 0001.lsp Edited May 11, 2011 by Ohnoto Quote Link to comment Share on other sites More sharing options...
Ohnoto Posted May 11, 2011 Author Share Posted May 11, 2011 Can anyone assist with this? Quote Link to comment Share on other sites More sharing options...
Ohnoto Posted May 12, 2011 Author Share Posted May 12, 2011 Here is something I've tried doing with this, though it is wrong in some way. (defun c:STADO (/ adoc i SelSet StrValidate AttVal StaList) (vl-load-com) (setq adoc (vla-get-activedocument (vlax-get-acad-object)) i 0) (if (ssget ":L" '((0 . "INSERT")(2 . "`*U*,POLE-STA"))) (cond ( (vlax-for Sta (setq SelSet (vla-get-activeselectionset adoc)) (if (and (equal (vla-get-effectivename sta) "pole-sta") (/= (setq StrValidate (vla-get-textstring (car (setq AttVal (vlax-invoke Sta 'GetAttributes))))) "")) (setq StaList (cons (list StrValidate (nth 26 AttVal)) StaList)) ) ) (foreach Blk (vl-sort StaList (function (lambda (p1 p2) (< (car p1) (car p2))))) (setq p1 (vlax-get p1 'insertionpoint)) (setq p2 (vlax-get p2 'insertionpoint)) (setq adodist (distance p1 p2)) (setq adodist (rtos adodist 2 0)) (setq adomid (mapcar '+ p1 (mapcar '/ (mapcar '- p2 p1) '(2.0 2.0 2.0)))) (setq adoang (angle p1 p2)) (command "-insert" "aerial distance -dyn" adomid "" (angtos adoang) adodist "") (cadr Blk) (itoa (setq i (1+ i)))) ) ) (vla-delete SelSet) ) (princ) ) I get the error "bad argument type: VLA-OBJECT nil". Which I believe is at the bottom portion of the coding with the lambda and the p1 / p2 variables. Quote Link to comment Share on other sites More sharing options...
pBe Posted May 13, 2011 Share Posted May 13, 2011 (defun c:STADO (/ AddOffset adoc SelSet StrValidate AttVal StaList p1 p2 dblk) (vl-load-com) [color=blue](defun AddOffset (lst)[/color] [color=blue] (list (+ (car lst) 11.25) (- (cadr lst) 11.0135) 0.0)) [/color] (setq adoc (vla-get-activedocument (vlax-get-acad-object))) (if (ssget ":L" '((0 . "INSERT")(2 . "`*U*,POLE-STA"))) (cond ( (vlax-for Sta (setq SelSet (vla-get-activeselectionset adoc)) (if (and (equal (vla-get-effectivename sta) "pole-sta") (/= (setq StrValidate (vla-get-textstring (car (setq AttVal (vlax-invoke Sta 'GetAttributes))))) "")) (setq StaList (cons (list StrValidate (nth 26 AttVal)) StaList)) ) ) [color=blue](setq StaList[/color] (vl-sort StaList (function (lambda (p1 p2) (< (car p1) (car p2)))))[color=blue])[/color] [color=blue](while (and (setq p1 (car StaList))[/color] [color=blue] (setq p2 (cadr Stalist)))[/color] (setq p1 [color=blue](AddOffset (vlax-get (cadr p1) 'insertionpoint))[/color] p2 [color=blue](AddOffset (vlax-get (cadr p2) 'insertionpoint))[/color] adodist (distance p1 p2) adodist (rtos adodist 2 0) adomid [color=blue](mapcar (function (lambda (a b) (/ (+ a b) 2.)))[/color] p1 p2) adoang (angle p1 p2)) [color=blue] (setq dblk (vlax-invoke[/color] [color=blue] (vlax-get (vla-get-ActiveLayout adoc) 'Block)[/color] [color=blue] 'insertblock[/color] [color=blue] adomid[/color] [color=blue] "aerial distance -dyn"[/color] [color=blue] 1[/color] [color=blue] 1[/color] [color=blue] 1[/color] [color=blue] adoang)[/color] [color=blue] )[/color] [color=blue](vla-put-textstring[/color] [color=blue] (car (vlax-invoke dblk 'Getattributes))[/color] [color=blue] adodist)[/color] [color=blue] (setq Stalist (cdr StaList))[/color] ) ) ) (vla-delete Selset) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
Ohnoto Posted May 13, 2011 Author Share Posted May 13, 2011 Thanks pBe! Here is an image of a small error occuring. I rotated the blocks around and tested it using a pole line that isn't straight. The middle once came in at the wrong angle and value. The one in green below is correct. I then re-inserted the last pole on the end, which came in at the correct angle, but put in the value of 26' and the distance between is 25.0000. It appears that the code is taking from the original insertion point and not the current insertion point. Quote Link to comment Share on other sites More sharing options...
pBe Posted May 13, 2011 Share Posted May 13, 2011 cheese and rice ... it must be my browser, cant even see the image from both your posts, this thing started when the IT guys blocked this website a month ago. now that i found a way to somehow get around that . but the webpage doesnt come out the way it was before. BUMMER Quote Link to comment Share on other sites More sharing options...
Ohnoto Posted May 13, 2011 Author Share Posted May 13, 2011 It may be blocking photobucket. I've heard of some places doing that. Quote Link to comment Share on other sites More sharing options...
Ohnoto Posted May 13, 2011 Author Share Posted May 13, 2011 Ok, so I think it was just something wrong with that file, the insert and angle worked on a new drawing, just fine, as planned and requested. However, when I run the program from within a viewport on a page tab it inserts the blocks in paper space and not model space. Quote Link to comment Share on other sites More sharing options...
SLW210 Posted May 13, 2011 Share Posted May 13, 2011 It may be blocking photobucket. I've heard of some places doing that. Try posting the image directly on this site, many people that are having their work block sites like photobucket. This is reducing the amount of help that others can provide. Just "Go Advanced" "Manage Attachments" "Browse" "Upload". Quote Link to comment Share on other sites More sharing options...
Ohnoto Posted May 13, 2011 Author Share Posted May 13, 2011 Try posting the image directly on this site, many people that are having their work block sites like photobucket. This is reducing the amount of help that others can provide. Just "Go Advanced" "Manage Attachments" "Browse" "Upload". I had done that originally, but get the error "The following errors occurred: Line Up Text.bmp: Invalid File" What is the size limit of an image that can be uploaded through the site? Quote Link to comment Share on other sites More sharing options...
SLW210 Posted May 13, 2011 Share Posted May 13, 2011 You need to save as .jpg would be best.... Quote Link to comment Share on other sites More sharing options...
pBe Posted May 14, 2011 Share Posted May 14, 2011 when I run the program from within a viewport on a page tab it inserts the blocks in paper space and not model space. Change this: (setq dblk (vlax-invoke [color=blue](vlax-get (vla-get-ActiveLayout adoc) 'Block)[/color] 'insertblock adomid "aerial distance -dyn" 1 1 1 adoang) ) to: [color=black](setq dblk (vlax-invoke[/color] [color=blue](vla-get-modelspace aDoc)[/color] 'insertblock adomid "aerial distance -dyn" 1 1 1 adoang) ) Quote Link to comment Share on other sites More sharing options...
Ohnoto Posted May 14, 2011 Author Share Posted May 14, 2011 Awesome! Thanks, I had been on the right track, doing: (vlax-get (vla-get-modelspace aDoc) 'block) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 14, 2011 Share Posted May 14, 2011 Why the use of COND after obtaining the SelectionSet? You will get an error if the user fails to make a Selection since 'Selset' is nil. Quote Link to comment Share on other sites More sharing options...
Ohnoto Posted May 20, 2011 Author Share Posted May 20, 2011 Lee, I can't answer that question, but I do know it works as it should only work on our Pole block. I have found an issue though with vl-sort in general. It's sorting like: 0+00 1+00 10+00 2+00 20+00 3+00 ... 9+99 Where it should be: 1+00 2+00 3+00 ... 10+00 So what is happening, is that between these areas the wrong values are being inserted, and they are being inserted hundreds or thousands feet away. This is also doing the same thing for Attribute Renumber, but should be the same fix, if possible. Quote Link to comment Share on other sites More sharing options...
pBe Posted May 20, 2011 Share Posted May 20, 2011 change this (setq StaList (vl-sort StaList (function (lambda (p1 p2) (< (car p1) (car p2)))))) to this (setq StaList (vl-sort StaList (function (lambda (p1 p2) (< (distof (vl-string-subst "." "+" (car p1)) 2) (distof (vl-string-subst "." "+" (car p2)) 2)))))) Quote Link to comment Share on other sites More sharing options...
Ohnoto Posted May 20, 2011 Author Share Posted May 20, 2011 Awesome! Thanks pBe! Now I know in the future to include that vl-string-subst 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.