Dormant Posted February 24, 2012 Posted February 24, 2012 Hey, Is it possible to move blocks based on an attribute inside that block. I.e. I have 600 blocks that are correct in the x axis, however i need to move each block to a y-coordinate based on the attribute inside that block. Cheers. Quote
BlackBox Posted February 24, 2012 Posted February 24, 2012 Yes. Iterate a valid selection set, drilling down into each Object until the desired, nested attribute tag is identified, then extract said attribute's TextString Property, then move the Block Object accordingly. Quote
Dormant Posted February 24, 2012 Author Posted February 24, 2012 ok, not sure if i explained myself enough, I would like the blocks the move automatically? Not me move one at a time. Quote
pBe Posted February 24, 2012 Posted February 24, 2012 ok, not sure if i explained myself enough, I would like the blocks the move automatically? Not me move one at a time. Renderman understood what you're trying to say, so he gave you: Pseudo code of some sort.... A starting point... Hints.... Quote
pBe Posted February 25, 2012 Posted February 25, 2012 Its easy really.. post a screenshot of what it lloks like now and what you want it be after Quote
pBe Posted February 25, 2012 Posted February 25, 2012 Ok i'm bored.. so here's a sample: (defun c:PlaceBlockTest () (while (setq pt (getpoint "\nPick Point for test block:")) (setq xc (rtos (Car pt) 2 4) yc (rtos (cadr pt) 2 4)) (command "_insert" "coord" pt "" "" xc yc) ) ) (defun c:btcrd (/ ss i e) (if (setq ss (ssget "_X" '((2 . "coord")))) (repeat (setq i (sslength ss)) (command "_.move" (setq e (ssname ss (setq i (1- i)))) "" "_non" (trans (cdr (assoc 10 (entget e))) 0 1) "_non" (trans (car (list (mapcar '(lambda (j) (distof (vla-get-textstring j)) ) (vlax-invoke (vlax-ename->vla-object e) 'GetAttributes)))) 0 1) ) ) ) ) HTH Coord.dwg Quote
Dormant Posted February 26, 2012 Author Posted February 26, 2012 thanks for your time pBe. Thats a nice lsp that i can use for the future labelling eastings and northings. The file attached is an example of what im trying to achieve. I have 100's of trusses all correct for there x co-ordinate however the y co-ordinate changes all the time, and i have to manually click on each truss and move it accordinaly. I would like to move the truss to the the y co-ordinate based on the attribute value, which i import from a spreadsheet ( which the boss changes all the time:x). cheers, hope u are bored again:P exampletruss.dwg Quote
Tharwat Posted February 26, 2012 Posted February 26, 2012 Try this Dormant ,and hope it would work for you . (defun c:TesT (/ selectionset intger selectionsetname nextentity entlst p)(vl-load-com) ;;; Tharwat 26. Feb. 2012 ;;; (if (setq selectionset (ssget "_:L" '((0 . "INSERT") (66 . 1)))) (repeat (setq intger (sslength selectionset)) (setq selectionsetname (ssname selectionset (setq intger (1- intger))) ) (setq nextentity (entnext selectionsetname)) (while (not (eq (cdr (assoc 0 (setq entlst (entget nextentity)))) "SEQEND" ) ) (if (eq (cdr (assoc 2 entlst)) "RL") (vla-move (vlax-ename->vla-object selectionsetname) (vlax-3d-point (setq p (cdr (assoc 10 entlst)))) (vlax-3d-point (list (car p) (+ (cadr p) (read (cdr (assoc 1 entlst))))) ) ) ) (setq nextentity (entnext nextentity)) ) ) (princ) ) (princ) ) Quote
Dormant Posted February 27, 2012 Author Posted February 27, 2012 many thanks Tharwat, that will work great, i can take the next few days off work thanks to pBe for his time also. problem solved Quote
Tharwat Posted February 27, 2012 Posted February 27, 2012 many thanks Tharwat, that will work great, i can take the next few days off work You're welcome . Glad that my code worked for you . Enjoy Quote
Dormant Posted February 27, 2012 Author Posted February 27, 2012 just a quick one, where in the code would I change so that they move in the "negative y direction". When the RL's get changed I will have to move them back to a 0 Datum, then use your lisp to move them all again. Regards Quote
pBe Posted February 27, 2012 Posted February 27, 2012 thanks for your time pBe.I have 100's of trusses all correct for there x co-ordinate however the y co-ordinate changes all the time, and i have to manually click on each truss and move it accordinaly. I would like to move the truss to the the y co-ordinate based on the attribute value, which i import from a spreadsheet ( which the boss changes all the time:x). Cheers, hope u are bored again:P You do have a routine to read the spreadsheet to update the y-coordinate attribute on the block prior ro moving those blocks? each block Y position will will depend on adjacent block but not necesarily "the" coordinate system? Anyhoo.. it appears that Tharwats code works to your liking. So no need for me to write one then Cheers Quote
Tharwat Posted February 27, 2012 Posted February 27, 2012 just a quick one, where in the code would I change so that they move in the "negative y direction". Just add minus mark (-) like this .... (list (car p) (+ (cadr p) [color=red][b](-[/b][/color] (read (cdr (assoc 1 entlst)))))[color=red][b])[/b][/color] Quote
pBe Posted February 27, 2012 Posted February 27, 2012 Tharwat/Dormant, I maybe mistaken but I dont get it. i thought the idea was to place the blocks based on the value of the attribute. the cdoe that tharwat psoted moves everything in a particualr direction and i cant see the correlation between the values of the attribute and the Y position. Quote
Dormant Posted February 27, 2012 Author Posted February 27, 2012 I dont have a routine. But when I have to change them, ill move them all back to a 0 datum using lisp for negative y, then export the block attribute data, open in excel, paste in new RLs, then import them back in. Then use the lisp to move them into correct location. I suppose you could do things slightly neater and faster, but im happy using this method. Quote
Tharwat Posted February 27, 2012 Posted February 27, 2012 I think the issue is between saying ( place / move ) and your point is logic pBe . Quote
pBe Posted February 27, 2012 Posted February 27, 2012 (edited) I dont have a routine. But when I have to change them, ill move them all back to a 0 datum using lisp for negative y, then export the block attribute data, open in excel, paste in new RLs, then import them back in. Then use the lisp to move them into correct location. I suppose you could do things slightly neater and faster, but im happy using this method. Well, its "end justities the means" then. As long as you're happy with it then go for it. Im more inclined to code it this way. (Not caring about the X position) (defun c:MoveY ( / ss i e atb r e) (vl-load-com) (if (setq ss (ssget "_:L" '((0 . "INSERT") (66 . 1)))) (repeat (setq i (sslength ss)) (setq e (vlax-ename->vla-object (ssname ss (setq i (1- i))))) (cond (and (setq atb (assoc "RL" (mapcar '(lambda (j) (list (vla-get-tagstring j) (distof (vla-get-textstring j)))) (vlax-invoke e 'Getattributes)))) (setq r (cdr (assoc 10 (entget (ssname ss i))))) (vla-put-insertionpoint e (vlax-3d-point (list (car r) (+ (cadr atb) )))))) ) )(princ) ) Ideally the block insertion point should be the datum point. it wouldnt be that hard to include "X" value if the blocks are created the way i suggested. At any rate... study the code and feel free to modify to your liking. Cheers Edited February 27, 2012 by pBe add another sample code 1 Quote
Dormant Posted February 27, 2012 Author Posted February 27, 2012 ok cool...ill have a look tomorrow at work. cheers:) Quote
Orbitek Posted July 12, 2021 Posted July 12, 2021 On 2/27/2012 at 8:02 AM, pBe said: Well, its "end justities the means" then. As long as you're happy with it then go for it. Im more inclined to code it this way. (Not caring about the X position) (defun c:MoveY ( / ss i e atb r e) (vl-load-com) (if (setq ss (ssget "_:L" '((0 . "INSERT") (66 . 1)))) (repeat (setq i (sslength ss)) (setq e (vlax-ename->vla-object (ssname ss (setq i (1- i))))) (cond (and (setq atb (assoc "RL" (mapcar '(lambda (j) (list (vla-get-tagstring j) (distof (vla-get-textstring j)))) (vlax-invoke e 'Getattributes)))) (setq r (cdr (assoc 10 (entget (ssname ss i))))) (vla-put-insertionpoint e (vlax-3d-point (list (car r) (+ (cadr atb) )))))) ) )(princ) ) Ideally the block insertion point should be the datum point. it wouldnt be that hard to include "X" value if the blocks are created the way i suggested. At any rate... study the code and feel free to modify to your liking. Cheers Hi! Can it be modified to include both X and Y value? I have block with mutliple atributes, and two has X Y data. TIA 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.