+ Reply to Thread
Page 2 of 2 FirstFirst 1 2
Results 11 to 16 of 16
  1. #11
    Junior Member
    Using
    AutoCAD 2013
    Join Date
    Jan 2013
    Posts
    16

    Default

    Registered forum members do not see this ad.

    I found below lisp by SMadsen which is what I close except it changes tag in all block

    Credit: SMadsen
    https://www.theswamp.org/index.php?topic=5917.0

    (defun changeAttribValue (ent atttag oldval newval / entl)
    (while (and ent (/= "SEQEND" (cdr (assoc 0 (setq entl (entget ent))))))
    (and (= atttag (cdr (assoc 2 entl)))
    (= oldval (cdr (assoc 1 entl))) ;<- could use WCMATCH instead
    (entmod (subst (cons 1 newval) (assoc 1 entl) entl))
    (entupd ent)
    (mapcar 'princ (list "\n" oldval " -> " newval))
    )
    (setq ent (entnext ent))
    )
    )

    (defun C:CHATTRIB (/ ss a attag bname oldval newval)
    (and (/= "" (setq bname (getstring "\nBlock name: ")))
    (/= "" (setq attag (getstring T "\nTag: ")))
    (/= "" (setq oldval (getstring T "\nOld value: ")))
    (/= "" (setq newval (getstring T "\nNew value: ")))
    (setq a 0
    ss (ssget "X" (list '(0 . "INSERT") '(66 . 1) (cons 2 bname)))
    )
    (repeat (sslength ss)
    (changeAttribValue (ssname ss a) attag oldval newval)
    (setq a (1+ a))
    )
    )
    )

  2. #12
    Senior Member
    Discipline
    Civil
    Aftertouch's Discipline Details
    Discipline
    Civil
    Details
    Engineer
    Using
    AutoCAD 2017
    Join Date
    Jul 2016
    Location
    Netherlands
    Posts
    222

    Default

    Do you want to set the values before or after you place the block?
    If you want to set the values before you place the blocks the code could look like...

    Code:
    (command "_insert" "<BLOCKNAME>" l "1" "1" "" <ATTRIBUTE1> <ATTRIBUTE2>)
    And you could define the attributes before you place the block.
    set attribute1 with your Kword method.
    set attribute with a cond function, wich evaluates the first attribute...

    If you want to be able to change the attributes when the block is already placed, you might be able to use Lee Mac's functions below...
    Code:
    ;; Set Attribute Value  -  Lee Mac
    ;; Sets the value of the first attribute with the given tag found within the block, if present.
    ;; blk - [ent] Block (Insert) Entity Name
    ;; tag - [str] Attribute TagString
    ;; val - [str] Attribute Value
    ;; Returns: [str] Attribute value if successful, else nil.
    
    (defun LM:setattributevalue ( blk tag val / enx )
        (if (and (setq blk (entnext blk)) (= "ATTRIB" (cdr (assoc 0 (setq enx (entget blk))))))
            (if (= (strcase tag) (strcase (cdr (assoc 2 enx))))
                (if (entmod (subst (cons 1 val) (assoc 1 (reverse enx)) enx))
                    (progn
                        (entupd blk)
                        val
                    )
                )
                (LM:setattributevalue blk tag val)
            )
        )
    )
    First click the block,
    Ask KWORD for first value
    COND the KWORD for the second value.
    Use above function twice to set the values?

  3. #13
    Super Moderator SLW210's Avatar
    Computer Details
    SLW210's Computer Details
    Operating System:
    Windows 7 PRO 64-bit
    Computer:
    IBM Lenovo
    Motherboard:
    ACPI x64
    CPU:
    Pentium(R) i5 4570 @ 3.2GHz
    RAM:
    8 GB RAM
    Graphics:
    Nvidia Quadro 600 1GB
    Primary Storage:
    300 GB
    Secondary Storage:
    650GB
    Monitor:
    2x ThinkVision 24"
    Discipline
    Multi-disciplinary
    SLW210's Discipline Details
    Occupation
    Design Draftsman
    Discipline
    Multi-disciplinary
    Details
    Mostly do drafting related to manufacturing. From doing site layouts with proposed updates, additions and renovations to be budgeted and submitted for bid, to updating and changing existing drawings to reflect maintenance and repair/revision work done on site.
    Using
    AutoCAD 2011
    Join Date
    May 2007
    Location
    South Florida, USA
    Posts
    11,795

    Default

    Please read the Code Posting Guidelines and edit your Code to be included in Code Tags.[CODE]Your Code Here[/CODE] =
    Code:
    Your Code Here
    “A narrow mind and a fat head invariably come on the same person” Zig Zigler



  4. #14
    Super Member hanhphuc's Avatar
    Using
    AutoCAD 2007
    Join Date
    Apr 2013
    Location
    Happy Garden
    Posts
    565

    Default

    my suggestion if you have many options to select, activate the dynamic input

    Code:
    (setvar 'dynmode 1)
    then you are able to click the value (acts like a radio button in dcl)
    but remember restore it at the end of the code.

    if you insert more than 1 block, just call the defun
    see update in post#3

    example:
    Code:
    (if
    (and
    (setq Mat1Num1 (MatNum))
    (setq Mat2Num2 (MatNum))
    (setq p1 (getpoint "\nSpecify point1 : "))
    (setq p2 (getpoint "\nSpecify point2 : "))
          )
    
    (progn
    
    (command "-insert" Mat1Num1 p1 1 1 0 ) ; do something
    (command "-insert" Mat2Num2 p2 1 1 0 ) ; do something else
    
    
    )
    
    )

    p/s: please don't ignore the moderator's advice to edit your previous post with code tags
    lambda not optimized.. ( apply '= "hp" "happy" "hạnh phúc" "ハッピー" "幸福" "행복" ) ; error: too many arguments

  5. #15
    Junior Member
    Using
    AutoCAD 2013
    Join Date
    Jan 2013
    Posts
    16

    Default

    Hi Hanhphnc,

    Thanks for helping me to get this far, I have merge together and the lisp seems almost working .

    Below lisp is my attempt of using command "-Attedit" to change the attribute block tags value, it works fine when only 1 and the last tag is change by using "L" to select the tag.

    However it fails when I specify the block names & tag value

    Any idea? Is it because I cannot use "last" after specifying block name?

    Code:
      (command "-attedit" "y" "LT_FIN" "TAG1" "MATERIALCODE" "L" "value" "Replace" MAT1NUM1 "") ; <--fail
      (command "-attedit" "y" "LT_FIN" "TAG2" "MATERIAL" "L" "value" "Replace" MAT1NUM1 "") ; <--fail
      (command "-attedit" "y" "" "" "" "L" "value" "Replace" MAT1NUM1 "") ; works, but it only allows to change the last tag
    Last edited by leong1221; 14th Nov 2017 at 10:13 am. Reason: Clarify

  6. #16
    Super Member hanhphuc's Avatar
    Using
    AutoCAD 2007
    Join Date
    Apr 2013
    Location
    Happy Garden
    Posts
    565

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by leong1221 View Post
    Code:
      (command "-attedit" "y" "LT_FIN" "TAG1" "MATERIALCODE" "L" "value" "Replace" MAT1NUM1 "") ; <--fail
      (command "-attedit" "y" "LT_FIN" "TAG2" "MATERIAL" "L" "value" "Replace" MAT1NUM1 "") ; <--fail
      (command "-attedit" "y" "" "" "" "L" "value" "Replace" MAT1NUM1 "") ; works, but it only allows to change the last tag
    Did you try Lee's function by supplying valid arguments? read the header of his code
    ;; Set Attribute Value - Lee Mac
    ;; Sets the value of the first attribute with the given tag found within the block, if present.
    ;; blk - [ent] Block (Insert) Entity Name
    ;; tag - [str] Attribute TagString
    ;; val - [str] Attribute Value
    ;; Returns: [str] Attribute value if successful, else nil.

    Code:
    (if 
    (setq en (car(entsel "\nSelect an attributed block entity.. "))) 
    (LM:setattributevalue en "TAG1" MAT1NUM1);whatever TAGs associated 
    )
    ;This is an activeX method to populate the attributes list
    Code:
    (defun c:test2 (/ lst s obj)
    
    ;we assume you have MAT1NUM1 global variable or set default "ML01"
    (setq MAT1NUM1 (cond (MAT1NUM1)("ML01")))
    
      (prompt "\nSelect an attributed block entity.. ")
      (if (and (setq s (ssget "_+.:S:E:L" '((0 . "INSERT") (66 . 1))))
    	   (setq obj (vlax-ename->vla-object (ssname s 0)))
    	   )
        (progn
     	
     	;documented 
    	;(setq lst (vlax-safearray->list(variant-value(vla-getattributes obj)))) ; conversion is required
          
     	;undocumented 
          (setq lst (vlax-invoke obj 'getattributes)) ; commonly practiced by Lee Mac, Tharwat etc.. credits to both 
          (mapcar ''((x o) (vla-put-TextString o x)) ;or vlax-put
    	      (list MATNUM1 "SECOND" "" "FOURTH" "ETC") ; <-- This is just an example, you can edit any replacement TextString associated to attribute positions 
    	      lst
    	      )
          )
        (princ "\nInvalid selection")
        )
      (princ)
      )
    (vl-load-com)
    lambda not optimized.. ( apply '= "hp" "happy" "hạnh phúc" "ハッピー" "幸福" "행복" ) ; error: too many arguments

Similar Threads

  1. Need some help with getstring
    By pmxcad in forum AutoLISP, Visual LISP & DCL
    Replies: 4
    Last Post: 1st Nov 2017, 08:21 pm
  2. Getstring Question
    By harrison-matt in forum AutoLISP, Visual LISP & DCL
    Replies: 31
    Last Post: 19th Oct 2010, 10:57 pm
  3. problem with strcat
    By Sweety in forum AutoLISP, Visual LISP & DCL
    Replies: 36
    Last Post: 25th Aug 2010, 08:39 pm
  4. getstring
    By jay3791 in forum AutoLISP, Visual LISP & DCL
    Replies: 4
    Last Post: 29th Sep 2009, 07:21 pm
  5. strcat help sought
    By diarmuid in forum AutoLISP, Visual LISP & DCL
    Replies: 3
    Last Post: 23rd Aug 2006, 08:44 am

Bookmarks

Posting Permissions

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