Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LOCK ALL ATTRIBUTE POSITIONS

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
Designer_1E
1301 Views, 3 Replies

LOCK ALL ATTRIBUTE POSITIONS

Hello,

 

Does anyone have an AUTOLISP kicking around that can change all the attribute definitions in all my blocks to "lock position" = yes?

 

Elise

3 REPLIES 3
Message 2 of 4
marko_ribar
in reply to: Designer_1E

For locking all attribute positions :

 

(defun c:lockpositionsallattribs ( / ss i attd )

  (vl-load-com)

  (setq ss (ssget "_X" '((0 . "ATTDEF"))))
  (if ss
    (repeat (setq i (sslength ss))
      (setq attd (ssname ss (setq i (1- i))))
      (vla-put-lockposition (vlax-ename->vla-object attd) :vlax-true)
    )
  )
  (vlax-for blk (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
    (vlax-for obj blk
      (if (= (vla-get-objectname obj) "AcDbAttributeDefinition")
        (vla-put-lockposition obj :vlax-true)
      )
    )
  )
  (princ)
)

You must use ATTSYNC after locking positions of definitions to reflect changes to visible ATTRIB sub entities of block references :

 

(defun c:attsync-all ( / unique ss i l b f )

  (vl-load-com)

  (defun unique ( l )
    (if l (cons (car l) (unique (vl-remove (car l) l))))
  )

  (setq ss (ssget "_X" '((0 . "INSERT") (66 . 1))))
  (if ss
    (repeat (setq i (sslength ss))
      (setq l (cons (cdr (assoc 2 (entget (ssname ss (setq i (1- i)))))) l))
    )
  )
  (if l
    (foreach n (unique l)
      (setq b (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) n))
      (vlax-for x b
        (if (= (vla-get-objectname x) "AcDbAttributeDefinition")
          (setq f t)
        )
      )
      (if f
        (vl-cmdf "_.ATTSYNC" "_N" n)
      )
      (setq f nil)
    )
  )
  (princ)
)

HTH., M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 3 of 4
Moshe-A
in reply to: Designer_1E

@Designer_1E hi,

 

why doing it on all blocks, isn't it enough to run it on blocks you know\want?

here is my version and it also works with dynamic blocks.

 

enjoy

moshe

 

(vl-load-com)

; Attribute Lock Position
(defun c:AttLP (/ pick_block ; local function
		  bname blocks AcDbBlockTableRecord)

 (defun pick_block (/ pick AcDbBlockReference)

  (initget "Name") 
  (setq pick (entsel "\n<Pick block>/Name: "))
   
  (cond 
   ((eq pick "Name")
    (getstring "\nBlock name: ")
   ); case 
   ((eq (type pick) 'LIST)
    (setq AcDbBlockReference (vlax-ename->vla-object (car pick)))
    (vla-get-effectivename AcDbBlockReference)
   ); case
  ); cond
 ); pick_block

  
 (setvar "cmdecho" 0)
 (command "._undo" "_begin")

 (setq bname (pick_block))
  
 (cond
  ((or (not bname) (eq bname ""))
   nil
  ); case 
  ((not (snvalid bname 0))
   (vlr-beep-reaction)
   (prompt "\ninvalid block name.")
  ); case
  ((null (tblsearch "block" bname))
   (vlr-beep-reaction)
   (prompt "\nBlock is not exist.")
  ); case
  (t
   (setq blocks (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))
   (setq AcDbBlockTableRecord (vla-item blocks bname))
   (vlax-for AcDbEntity AcDbBlockTableRecord
    (if (eq (vla-get-objectName AcDbEntity) "AcDbAttributeDefinition")
     (vla-put-lockPosition AcDbEntity :vlax-true)
    )
    (vlax-release-object AcDbEntity) 
   ); vlax-for  

   (vlax-release-object AcDbBlockTableRecord)
   (vlax-release-object blocks)

   (vl-cmdf "._attsync" "_name" bname) ; update all inserts
  ); case
 ); cond

 (command "._undo" "_end")
 (setvar "cmdecho" 0)
  
 (princ)
)
Message 4 of 4
Designer_1E
in reply to: Moshe-A

Hi Moshe-A


I'm using a library of blocks that I don't have control over.  There are thousands of invisible attributes that are not locked.  Which means we are accidentally snapping to invisible text quite often, and the grips are in the way.

 

I would like to just do all the blocks at once, instead of picking through one at a time.  I know that I don't need to move their attributes.

 

E

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report