Jump to content

Move multiple values in block to new tag line?


chris2x1

Recommended Posts

Hi All,

 

I am new here and looking for a bit of help.

 

I have a block with 10 rectangles in each with 3 lines of text

Each 3 lilnes of text is attributed to a tag

 

so the first line is IN-0 DESC1,

second line is IN-0 DESC2

third line is IN-0 DESC3

 

 

i have deleted the data from

 

IN-3 DESC1

IN-3 DESC2

IN-3 DESC3

 

and i want to move the data from

 

IN-4 DESC1

IN-4 DESC2

IN-4 DESC3 etc

 

up to the position of

 

IN-3 DESC1

IN-3 DESC2

IN-3 DESC3

 

 

can this be done?

 

other wise i will have to click on

 

IN-4 DESC1 cut the data then open up IN-3 DESC1 and paste it then repeat for

IN-4 DESC2 cut the data then open up IN-3 DESC2 and paste it then repeat for etc

Link to comment
Share on other sites

A couple of ways if you generated the block with the attributes as line1 line2 as they appear then its really easy with VBA as you can change attributes by there attribute created order. Heres a sample you can see the attributes Attrib(x) so you could say move line 5 to line 1 or some form of smarter move all up starting at line 4

 

If SS.Item(Cntr).Name = BLOCK_NAME Then
    attribs = SS.Item(Cntr).GetAttributes
     
    If attribs(0).TextString = blockname Then
      pt1 = ThisDrawing.Utility.GetPoint(, " pick first point")
      txtx1 = CStr(FormatNumber(pt1(0), 3))
      TXTY1 = CStr(FormatNumber(pt1(1), 3))
       
       attribs(1).TextString = txtx1
       attribs(2).TextString = TXTY1
       
       attribs(1).Update
       attribs(2).Update
'        ThisDrawing.Application.Updated

 

With Lisp you can do the same using the tag name again these may be as simple as Line1, line2, line3 basicly if you search here for any generic block attribute example you should be able to modify it to suit you needs, you may need a couple of functions move 1, move many, start with move 1. Also do delete line x.

 

A question any one a lisp version of the attribute order rather than by tag VBA above ?

Link to comment
Share on other sites

Thanks buddy, i am running ACAD ELEC 2013 so just installing VBA and ill give it bash.

 

A lisp program for it like LMAC's batch find and replace would be a great thing but i have sourced one yet.

Link to comment
Share on other sites

Welcome to the forum. :)

Does this LeeMac lisp work for you?

 

http://www.lee-mac.com/macatt.html

 

Perhaps the EDITOR part described at the bottom of the description?

Thanks Lee! :beer:

 

 

Excellent I will get this tested today, see if it does the job, if it does its going to save me a crazy amount of time.

 

Thanks very much

Link to comment
Share on other sites

Chris2x1 this may be usefull. For anyone interested solved the by order here is a example of updating the attribute by its creation order rather than using attribute tag name Just need a block with multiple attributes.

 

(vl-load-com)
(defun blkattnum ()
(setq y 1)
(setq bname "test")
(setq ss1 (ssget "x"  (list (cons 0 "INSERT") (cons 2 bname)))) ; this line for all blocks in dwg
;(setq ss1 (car (entsel)))  ; this line for pick 1 block
(foreach att (vlax-invoke (vlax-ename->vla-object (ssname SS1 0 )) 'getattributes) ; for all blocks
;(foreach att (vlax-invoke (vlax-ename->vla-object SS1) 'getattributes) ; for 1 block
   (if (= y x)
(vla-put-textstring att newstr)
)
(setq y (+ Y 1))
)
)


(setq bname "test")
(setq x 3) ; change this line in block
(setq newstr "wow")

(blkattnum)

 

Lee may be usefull please add to your site if you want.

Edited by BIGAL
moved block name
Link to comment
Share on other sites

Chris2x1 this may be usefull. For anyone interested solved the by order here is a example of updating the attribute by its creation order rather than using attribute tag name Just need a block with multiple attributes.

 

(vl-load-com)
(defun blkattnum ()
(setq y 1)
(setq bname "test")
(setq ss1 (ssget "x"  (list (cons 0 "INSERT") (cons 2 bname)))) ; this line for all blocks in dwg
;(setq ss1 (car (entsel)))  ; this line for pick 1 block
(foreach att (vlax-invoke (vlax-ename->vla-object (ssname SS1 0 )) 'getattributes) ; for all blocks
;(foreach att (vlax-invoke (vlax-ename->vla-object SS1) 'getattributes) ; for 1 block
   (if (= y x)
(vla-put-textstring att newstr)
)
(setq y (+ Y 1))
)
)


(setq x 3) ; change this line in block
(setq newstr "wow")

(blkattnum)

 

Lee may be usefull please add to your site if you want.

 

Cheers BIGAL,

 

I need get IT to allow me install VBA on Elec 2013 so i can try this out, but knowing IT it will never happen, but ill keep pushing and hopefully that will solve the problem.

 

Thanks Again

Link to comment
Share on other sites

The second post is lisp so its already installed if you are running electrical it should work No need for IT, I have made a subtle change to code ask for block name outside defun.

 

Regarding testing it just make a block called "Test" with say 4 attributes, copy and paste code to Notepad then save as say Attupbyrow.lsp. Use APPLOAD to LOAD, it will then run by its self. Change the newstr "wow" or the x 3 in the code to see how it works.

 

If you need more help please post a dwg with the block/s in it.

Link to comment
Share on other sites

The second post is lisp so its already installed if you are running electrical it should work No need for IT, I have made a subtle change to code ask for block name outside defun.

 

Regarding testing it just make a block called "Test" with say 4 attributes, copy and paste code to Notepad then save as say Attupbyrow.lsp. Use APPLOAD to LOAD, it will then run by its self. Change the newstr "wow" or the x 3 in the code to see how it works.

 

If you need more help please post a dwg with the block/s in it.

 

 

I have loaded the lisp successful but i get this message

 

Attupbyrow.lsp successfully loaded.

Command: ; error: bad argument type: lselsetp nil

 

plus i dont know what the comman is to launch the lisp.

Link to comment
Share on other sites

test.dwg

I have loaded the lisp successful but i get this message

 

Attupbyrow.lsp successfully loaded.

Command: ; error: bad argument type: lselsetp nil

 

plus i dont know what the comman is to launch the lisp.

 

I have added the block above you will see 3 empty boxes at top and basically i want to move the text from the boxes below the 3 empty ones into those three

Link to comment
Share on other sites

Have to go right now will come back with something soon if others dont beat me.

 

This will move a attribute line in a block to a new line. Had a look at your block not sure if your attributes are in a line order, anyway try 33 and 22.

 

(vl-load-com)
(setq y 1)
(setq ss1 (car (entsel)))
(setq bname (vla-get-name(vlax-ename->vla-object SS1))) 

(setq x (getint "\nEnter line no to pick")) ; change this line in block
(SETQ newstrblank ".")
(foreach att (vlax-invoke (vlax-ename->vla-object SS1) 'getattributes)
   (if (= y x)
   (progn
   (setq newstr (vla-get-textstring att ))
   (vla-put-textstring att newstrblank)
   )
   )
   (setq y (+ Y 1))
)
(setq y 1)
(setq x (getint "\nEnter line no to move to"))
(foreach att (vlax-invoke (vlax-ename->vla-object SS1) 'getattributes)
   (if (= y x)
   (vla-put-textstring att newstr)
   )
   (setq y (+ Y 1))
)
(princ) 

 

As for moving up would need to do a pretty advanced method of finding block attributes x,y and then move up in list, if attributes at time of making . block are created in a random order not looking at there visual appearance order. No idea how to find att x,y create lists and then update, last bit is above.

Edited by BIGAL
Link to comment
Share on other sites

A question is this block dynamically generated in some way like adding extra lines as required rather than a normal block with lots of attributes? Is this done via Acad Electrical when adding rows ?

 

If so any one a clue would need a dotted pair (linenum . strval) but the linenum has to come from a sorted list of the Y values of all the attribute co-ords. Consider scenario of insert 3 new attributes in middle of a column of existing attributes that already exist and create new/update block.

 

The code above pulls each attribute out but what is the code for vla-get-coords-of-attribute ?

Found a way

(vl-load-com)
(setq ss1 (car (entsel)))
(setq bname (vla-get-name(vlax-ename->vla-object SS1))) 
(foreach att (vlax-invoke (vlax-ename->vla-object SS1) 'getattributes)
   (setq newxyz (vla-get-textalignmentpoint att ))
 (princ (vlax-safearray->list (vlax-variant-value newxyz) ))
   ;(princ (cadr  (vlax-safearray->list (vlax-variant-value newxyz) )))
)

Edited by BIGAL
Link to comment
Share on other sites

Had a couple of minutes your block is all over the place in the way its created have a look at image, the only way this would work is pick block and window attributes to weed out those you dont want and then like before sort them into some form of order and update, maybe a window attributes then window where to place them. I am sure it can be done. You need to find a pick attribute off screen I am pretty sure there is code here to do that. Then you can cut and apply. You would need say a "." to see update line.

 

chrisx21.jpg

 

There is a current post find point inside another object you could use something like this to check that attibute is within window area. Like before it could be done but not an easy task.

http://www.cadtutor.net/forum/showthread.php?72815-Point-inside-or-outside-of-another-entity

Edited by BIGAL
Link to comment
Share on other sites

cheers BIGAL, I dont know if its an electrical block or the other cad draughter created it, i have only been in this job 3 weeks and hes off on holiday, so ill need to wait till he comes back to see where he got it from, ill look at your other link see if i can work it out

Link to comment
Share on other sites

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