Jump to content

Edit attribute tag X, Y position


sivapathasunderam

Recommended Posts

Say my attribute block name is MYDWGFRAME & it has 10 TAGs or more, over there I wanted to move positions of the 2 tags or more (I will add/modify TAGs into the lisps as per my requirement)

Say Tag name REVISION wanted to move position to X1,Y1 (I will modify the coordinate value in the lisp as per my requirement)

Say Tag name DATE wanted to move position to X2,Y2 (I will modify the coordinate value in the lisp as per my requirement)

then  (command "_attsync" "_n" "*")

 

Thanks

 

Link to comment
Share on other sites

Really Sir need code, Bedit command is manual & I was tried with searching the google for Attribute blocks

slightly I have doubt on one link have a look . . .   https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-insert-block-change-attribute-values-and-position-angle/td-p/9936772

I have to modify Attribute blocks on many drawings using script - this will be useful for many Colleagues

Link to comment
Share on other sites

  • 5 months later...

Expanding what BigAl said, without testing and trying this, if you do this will it work, open the block editor and edit it using a LISP as if it was just normal model space

 

(command "bedit" <MYDWGFRAME)
                                     
.... do your commands here
                                     
(command "bsave")
(command "bclose")

 

I am sure there is plenty out there about locating a named attribute and moving it, perhaps using ssget, going through the list of entities in the block if it is the correct one move it to the new coordinates

Not forgetting an attsync at the end to update it. 

Link to comment
Share on other sites

@Steven P

Hi.

1. there isn't that much examples about it. I was looking recently for this issue and struggled to find clear examples. if you could help him with clear code I belive it will help not only him.

2. in my routine I didn't used attsync. mybe because I neede to move one attribute at a time to a specific location it was not requiered, but bottom line - it worked. 

 

here is a summery of what I did:


(vl-load-com) 

(if (setq ensel (entsel "\nSelect Block: ")) ;select the block object to edit its attributes
       (setq bname (cdr (assoc 2 (entget (car ensel)))))
     )

   (setq obj (car ensel)) ;set the block object to varaible
   (setq obj2 (vlax-ename->vla-object obj)) ;; set the block object to a VLAX object for the attribute function
.
.
   (setq base1 (getpropertyvalue (car ensel) "Position" 1 "X")) ;get the source block base point 
.
.
   (setq pAtt (polar base1 ang2 42)) ;;set the new attribute insertion point based on the block insertion point. base1 is the block insertion point,
                                     ;; 42 is the distance from base1 and ang2 is angle of that distance.it will put the attribute at 42 distance units                                      ;;at an angle of ang2 (in radians)
.
.
           ( ;; move the object attributes
              foreach att (vlax-invoke Obj2 'GetAttributes) ;;loop through al the attributes of the selected block
                (
                  if (= "ORDER" (strcase (vla-get-tagstring att))) ;; if the attribute tag name is "ORDER" then move it
                     (vlax-put att 'insertionpoint pAtt)
                )
           )

 

hope it will give some guide lines.

regards,

Ari.

Edited by aridzv
Link to comment
Share on other sites

Did Bedit and then looked at a attribute.

((-1 . <Entity name: 68df4da0>) (0 . "ATTDEF") (5 . "11C55") (330 . <Entity name: 3db030f0>) (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "DRGTEXT") (62 . 4) (370 . -1) (100 . "AcDbText") (10 612.293348792386 3.78122019187447 0.0) (40 . 5.0) (1 . "") (50 . 0.0) (41 . 1.0) (51 . 0.0) (7 . "Standard") (71 . 0) (72 . 0) (11 0.0 0.0 0.0) (210 0.0 0.0 1.0) (100 . "AcDbAttributeDefinition") (3 . "DRAWING DESCRIPTION") (2 . "DRAWING_DESCRIPTION") (70 . 0) (73 . 0) (74 . 0) (280 . 0))

 

Using a ssget with filter 0 . attdef & 2 . attname so could get insertion point (assoc 10 use that as a base point then move the entity to new pt.

 

 

Link to comment
Share on other sites

@aridzv use nentsel (nested entity select) instead of entsel will get you the attribute itself.

 

(defun C:MoveATT (/ att base pt)
  (vl-load-com) 
  (while (setq (car att (nentsel "\nSelect Atribute to Move: ")))
    (if (= (setq base (cdr (assoc 10 (entget att)))) '(0.0 0.0 0.0)) 
      (setq base (cdr (assoc 11 (entget att)))) ;text will have diffrent points if not left Justification
    )
    (setq att (vlax-ename->vla-object e))    
    (vla-move att base (getpoint)) ;replace getpoint with x1 y1
  )
)

 

 

Link to comment
Share on other sites

Nice idea Mhupp but going back a few steps

 

"modify Attribute blocks on many drawings using script"

 

So entsel or nentsel can not be used if its to be automated but ssget works.

Edited by BIGAL
Link to comment
Share on other sites

41 minutes ago, BIGAL said:

So entsel or nentsel can not be used if its to be automated but ssget works.

 

Would nentselp work and specify the points within the LISP?

 

However if you are automatng this with a lot of drawings, I also think you need to do ssget from within the block editor to make the LISP more generic and versetile. If the OP is just modifying the drawing frame / border it is more likely that it is inserted consistently at the same insertion point, maybe nentselp would work then.. so long as no one else has modified the dwgframeblock in that drawing

Link to comment
Share on other sites

10 hours ago, mhupp said:

@aridzv use nentsel (nested entity select) instead of entsel will get you the attribute itself.

 

(defun C:MoveATT (/ att base pt)
  (vl-load-com) 
  (while (setq (car att (nentsel "\nSelect Atribute to Move: ")))
    (if (= (setq base (cdr (assoc 10 (entget att)))) '(0.0 0.0 0.0)) 
      (setq base (cdr (assoc 11 (entget att)))) ;text will have diffrent points if not left Justification
    )
    (setq att (vlax-ename->vla-object e))    
    (vla-move att base (getpoint)) ;replace getpoint with x1 y1
  )
)

 

 

@mhupp thanks for the advise - I will defentaly chek it.

@Steven P I use this lisp (with entsel) to change atrribute in one selected block so probably it is not good for a selection of many blocks.

here is a lisp that I use to change attributes rotation in a seleced group of blocks,and there the lisp use the ss method to create a list of blocks, fish a specipic tag and change its rotation:

 

(defun c:chatht15 ( / ta an bent bent2 pt lay tagname ss bname x att temp YN )

  (setq tagname "ORDER")
  (setq ss (ssget (list (cons 0 "INSERT"))))

  (setq ht (getreal "\nEnter text height<24>: "))
  (if (= ht nil)
    (setq ht 24)
  )

  (setq an (getreal "\nEnter Rotation<0>: "))
    (if (= an nil)
    (setq an 0)
  )

  (setq tagname (strcase (getstring "\nAttribute tag specification<ORDER>: ")))
   (if (= tagname "")
     (setq tagname "ORDER")
   )

(initget "Yes No")
(if (null (setq YN (getkword "\nClear Attribute Value? [Yes/No] <No>: ")))
    (setq YN "No")
)

  (setq an (/ (* an pi) 180))

  (repeat (setq x (sslength ss))
    (setq obj (vlax-ename->vla-object (ssname SS (setq x (- x 1) ))))
    (if  (= (vla-get-hasattributes obj) :vlax-true)
      (foreach att (vlax-invoke obj 'getattributes)
        (if (= tagname (strcase (vla-get-tagstring att)))
          (progn
            (vla-put-Rotation att an)
            (vla-put-height att ht)
            (if (= (vlax-get-property att 'Backward) :vlax-true)
             (vlax-put-property att 'Backward :vlax-false)
            )
            (if (= (vlax-get-property att 'UpsideDown) :vlax-true)
              (vlax-put-property att 'UpsideDown :vlax-false)
            )

           (if (= YN "Yes")
            (vla-put-textstring att "")
           )

          )
        )
      )
    )
  )

  (princ)
)

 

I belive it is possible to use this structure and add a code segment that will change the attribute insertion point as well, or instead...

Regards,

Ari.

 

Edited by aridzv
Link to comment
Share on other sites

  • 3 months later...

Can't use "Move with specific distance" because the position of the TAG is different in some drawings (can be different block names but i know how to rename the blocks to default by lisp route, this is because of it is done by many cad persons)

I wanted to bring the specific one or more TAG(s) position to default

 

I hope we have to use setpropertyvalue (AutoLISP)

 

I hope far better to attach a cad drawing example - if you request me.

 

Attribute Tag move to set default position.png

 

I have attached Example (3 dwgs), The revision Tag position is different in each dwg.

Drawing2.dwg Drawing3.dwg Drawing1.dwg

Edited by sivapathasunderam
Link to comment
Share on other sites

Using nentsel can move attribute, simple for say 1 block.

 

(setq obj (vlax-ename->vla-object (car  (nentsel "Pick attribute"))))
(vla-put-textAlignmentPoint obj '(800 100 0.0))

inside bedit
(setq ss (ssget "X" (list (cons 0  "ATTDEF")   (cons 2  "YOUR TAG NAME") (cons 410 "Model"))))
(setq ent (entget (ssname ss 0)))
then use entmod and change dxf 10

 

If you want to edit all blocks can call BEDIT and move attribute, then attsync.

 

 

 

 

Link to comment
Share on other sites

16 hours ago, BIGAL said:

Using nentsel can move attribute, simple for say 1 block.

 

(setq obj (vlax-ename->vla-object (car  (nentsel "Pick attribute"))))
(vla-put-textAlignmentPoint obj '(800 100 0.0))

inside bedit
(setq ss (ssget "X" (list (cons 0  "ATTDEF")   (cons 2  "YOUR TAG NAME") (cons 410 "Model"))))
(setq ent (entget (ssname ss 0)))
then use entmod and change dxf 10

 

If you want to edit all blocks can call BEDIT and move attribute, then attsync.

 

 

 

 

Thanks a lot BIGAL . . .  This is by inside block edit

(setq ent (subst (cons 11 '(my default coordinate)) (assoc 11 ent) ent))
(entmod ent)
(command "_.bsave") (command "_.bclose")
(command "_attsync" "_N" "My block name") (princ))

 

Edited by sivapathasunderam
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...