Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: Attribute Height/Width Modification

  1. #1
    I could stop if I wanted to
    Join Date
    2012-11
    Location
    Brisbane, Australia
    Posts
    239
    Login to Give a bone
    0

    Default Attribute Height/Width Modification

    Hey All

    Would anyone have a subfunction for changing the width or height or an attribute in a block?
    eg:
    (AttEdit Block Att H "2.5")
    (AttEdit Block Att W "0.8")

    AttEdit = function
    Block = block reference
    Att = Attribute Name
    H/W = Height/Width
    "value" = value to change

    If no one has anything like this, a point in the right direction for making one would be greatly appreciated.

    Cheers

  2. #2
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: Attribute Height/Width Modification

    Try this ...

    Code:
    (defun Edit_att (BlockName AttTag Property Value / sel i sn e)
      ;;	-------- 	Tharwat 06. May. 2013 	-------			;
      ; BlockName 	   = Name of the Attributed Block ( String )		;
      ; AttTag 	   = Tag of the Attribute ( String )			;
      ; Property	   = Property (Width / Height) ( String )		;
      ; Value 	   = Value of Width or Height (String )			;
      (if (and (tblsearch "BLOCK" BlockName)
               (setq
                 sel (ssget "_X"
                            (list '(0 . "INSERT") '(66 . 1) (cons 2 BlockName))
                     )
               )
          )
        (progn
          (repeat (setq i (sslength sel))
            (setq sn (ssname sel (setq i (1- i))))
            (while
              (/= (cdr (assoc 0 (setq e (entget (setq sn (entnext sn))))))
                  "SEQEND"
              )
               (if (and (eq (cdr (assoc 0 e)) "ATTRIB")
                        (eq (cdr (assoc 2 e)) AttTag)
                   )
                 (if (eq (strcase property) (strcase "Width"))
                   (entmod (subst (cons 41 (read Value)) (assoc 41 e) e))
                   (entmod (subst (cons 40 (read Value)) (assoc 40 e) e))
                 )
               )
            )
          )
        )
      )
      (princ)
    )
    e.g.

    Code:
    (edit_att "lol" "111" "Height" "2.0")
    or this for changing widths ..


    Code:
    (edit_att "lol" "111" "Width" "1.0")

  3. #3
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default Re: Attribute Height/Width Modification

    This code sample is just for the block reference and has no error handling
    so you might be able to squiggle it to your suit.

    Code:
    (defun AttEdit(BlockObj AttName Mode Factor / AttObj Tags)
    (setq Tags (mapcar '(lambda(x)
    		      (cons (vla-get-tagstring x) x ))
    		   (vlax-invoke BlockObj 'getattributes)
    		   )
          )
    (setq AttObj (cdr (assoc AttName tags)))
      (cond ((not (member AttName (mapcar 'car Tags)))
    	 (alert "Wrong attribute tag"))
    	 ((eq Mode "Width")
         (vla-put-scalefactor AttObj Factor))
    	((eq Mode "Height")
        (vla-put-height AttObj (* (vla-get-height AttObj) Factor)))
    	(T (alert "Invalid input")))
      )
        ;; Usage:
        (defun c:demo (/ adoc attname blkobj blockobj factor mode sset)
          (vl-load-com)
          (setq adoc (vla-get-activedocument (vlax-get-acad-object)))
          (vla-startundomark adoc)
          (if (setq sset (ssget "_+.:S:E:L" '((0 . "insert") (66 . 1))))
    	(progn
    	  (setq BlockObj (vlax-ename->vla-object (ssname sset 0)))
    	 ;; attribute for the test, hard coded input
    	 ;; (setq attname "SCALE")
    	(setq attname (strcase (getstring "\Enter attribute tag (case-nonsensitive): ")))		
    	  (initget "Height Width")
    	  (setq	mode
    		 (cond
    		   ((getkword
    		      "\nApply scale to attribute property of [Height/Width] <W>: "
    		    ) ;_ end of getkword
    		   )
    		   ("Width")
    		 ) ;_ end of cond
    	  ) ;_ end of setq
    	  (setq	factor
    		 (getreal
    		   (strcat "\nEnter new scale factor of " mode " :  ")
    		 ) ;_ end of getreal
    	  ) ;_ end of setq
    	  (AttEdit BlockObj AttName Mode Factor)
    	) ;_ end of progn
          ) ;_ end of if
          (vla-endundomark adoc)
          (princ)
        ) ;_ end of defun
    Easy way to use attribute editor, i.e.
    Code:
    (setvar "attdia" 1)
    (command "eattedit" )
    (while (eq 1 (logand 1 (getvar"cmdactive")))
      (command pause))
    Last edited by fixo; 2013-05-06 at 07:59 AM. Reason: code added

  4. #4
    I could stop if I wanted to
    Join Date
    2012-11
    Location
    Brisbane, Australia
    Posts
    239
    Login to Give a bone
    0

    Default Re: Attribute Height/Width Modification

    Cheers for the replies fellas

    Tharwat, I tried your code and it didnt seem to work for me, I am uncertain why and I attempted to tweak it but I am still newbie to visual lisp so it was a bit out of my range.

    Fixo, your code took some tweaking but I finally got it to work. The only thing I could fault was that if I tried to input a value into an attribute that didnt exist I would be given an error. I'll try and error check this so that it just skips when I get a chance.

    Thanks again for the help fellas.
    Im still learning so any relevant code that I can reverse engineer is greatly appreciated.

  5. #5
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: Attribute Height/Width Modification

    Quote Originally Posted by LSElite View Post

    Tharwat, I tried your code and it didnt seem to work for me, I am uncertain why and I attempted to tweak it but I am still newbie to visual lisp so it was a bit out of my range.
    Hi ,

    Can you upload a sample drawing containing that attributed block ?

  6. #6
    I could stop if I wanted to
    Join Date
    2012-11
    Location
    Brisbane, Australia
    Posts
    239
    Login to Give a bone
    0

    Default Re: Attribute Height/Width Modification

    Ive attached the drawing for you Tharwat

  7. #7
    All AUGI, all the time
    Join Date
    2010-10
    Posts
    535
    Login to Give a bone
    0

    Default Re: Attribute Height/Width Modification

    Quote Originally Posted by LSElite View Post
    Hey All

    Would anyone have a subfunction for changing the width or height or an attribute in a block?
    eg:
    "value" = value to change

    How's about Width AND Height?

    On another note: Are you wanting to change the width and/or height of an attribute tag on a block globally? then Battman will a better option or a routine that modifies the block definition thru the blocks collection.

    If individually [fudge/override], you may find that using attsync will revert the values to its original state.

    Which one do you prefer?
    Last edited by pbejse; 2013-05-15 at 05:49 AM.

  8. #8
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: Attribute Height/Width Modification

    Quote Originally Posted by LSElite View Post
    Ive attached the drawing for you Tharwat
    Check this out now .

    Code:
    (defun Edit_att (BlockName Property Value / sel i sn e)
      ;;	-------- 	Tharwat 06. May. 2013 	-------			;
      ; BlockName 	   = Name of the Attributed Block ( String )		;
      ; AttTag 	   = Tag of the Attribute ( String )			;
      ; Property	   = Property (Width / Height) ( String )		;
      ; Value 	   = Value of Width or Height (String )			;
      (if (and (tblsearch "BLOCK" BlockName)
               (setq
                 sel (ssget "_X"
                            (list '(0 . "INSERT") '(66 . 1) (cons 2 BlockName))
                     )
               )
          )
        (progn
          (repeat (setq i (sslength sel))
            (setq sn (ssname sel (setq i (1- i))))
            (while
              (/= (cdr (assoc 0 (setq e (entget (setq sn (entnext sn))))))
                  "SEQEND"
              )
               (if (eq (cdr (assoc 0 e)) "ATTRIB")
                 (if (eq (strcase property) (strcase "Width"))
                   (entmod (subst (cons 41 (read Value)) (assoc 41 e) e))
                   (entmod (subst (cons 40 (read Value)) (assoc 40 e) e))
                 )
               )
            )
          )
        )
      )
      (princ)
    )
    To try the code for height ...

    Code:
    (edit_att "Fields_A1_H" "Height" "1.5")
    And this is width ...

    Code:
    (edit_att "Fields_A1_H"  "Width" "0.8")

  9. #9
    I could stop if I wanted to
    Join Date
    2012-11
    Location
    Brisbane, Australia
    Posts
    239
    Login to Give a bone
    0

    Default Re: Attribute Height/Width Modification

    Thanks Tharwat

    It worked perfectly
    I apologies for the lateness of my reply.
    I am a full time designer for this company so the only time I get to look at these programs is either after hours or when things are quiet.
    The exception to this rule is when programs break then its red alert, thus my other post.
    I am sorry if you feel as if I am wasting your time.
    I am doing my best with the juggling act that is my workload.

    Cheers mate

  10. #10
    All AUGI, all the time
    Join Date
    2010-10
    Posts
    535
    Login to Give a bone
    0

    Default Re: Attribute Height/Width Modification

    I would've approached it differently, but what the hey. you're already happy with the solution. so good for you.

Page 1 of 2 12 LastLast

Similar Threads

  1. paper width and height
    By Bryan Thatcher in forum Revit Architecture - General
    Replies: 4
    Last Post: 2010-03-18, 02:29 PM
  2. Attribute Modification
    By dan.68314 in forum AutoLISP
    Replies: 13
    Last Post: 2009-07-10, 07:32 AM
  3. Combine parameters width and height
    By CADMama in forum Revit Architecture - General
    Replies: 2
    Last Post: 2009-02-05, 12:26 AM
  4. Door Tag with Width x Height Label
    By raddis in forum Revit Architecture - Families
    Replies: 6
    Last Post: 2006-01-27, 02:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •