Jump to content

Move block based on a attribute in the block


Recommended Posts

Posted

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.

Posted

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.

Posted

ok, not sure if i explained myself enough, I would like the blocks the move automatically? Not me move one at a time.

Posted
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....

Posted

Its easy really.. post a screenshot of what it lloks like now and what you want it be after

Posted

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

Posted

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

Posted

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)
)

Posted

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 :D

Posted
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

Posted

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

Posted
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 :lol:

 

Cheers

Posted
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]

Posted

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. :?

Posted

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.

Posted

I think the issue is between saying ( place / move ) and your point is logic pBe . :)

Posted (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 by pBe
add another sample code
  • Like 1
Posted

ok cool...ill have a look tomorrow at work. cheers:)

  • 9 years later...
Posted
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

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...