AutoCAD Electrical Forum
Welcome to Autodesk’s AutoCAD Electrical Forums. Share your knowledge, ask questions, and explore popular AutoCAD Electrical topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

API c:wd_getattrval to copy a block attribute to titleblock attribute

4 REPLIES 4
Reply
Message 1 of 5
garet79
464 Views, 4 Replies

API c:wd_getattrval to copy a block attribute to titleblock attribute

I've been referencing post "Replace certain attribute value script?"  I want to scan a drawing for three custom blocks , if found, then transfer their "INST" value (ex. 123456) to their respective custom attribute on the titleblock(dwg1, dwg2, dwg3).  So far...

 

(defun c:bl()    
    (setq gt (ssget "_X" '((2 . "HDV1_GENERIC_BLOCK_LEFT"))))
    (setq ik 0)
    (if (< ik (sslength gt))
        (progn
        (setq ent (ssname gt ik))
        (setq rtrn (c:wd_getattrval ent "INST"))
        (princ rtrn)
        )
     )
(princ)
)

 

I'm using Group Code 2, as you can see, but my block HDV1_GENERIC_BLOCK_LEFT is dynamic so when it changes from its inserted version the Group Code also changes.  I tried adding the new Code description (*U10) to my list but still get ; error: bad argument type: lselsetp nil.  Are dynamic blocks out of the question when working with entities or is their a way around this problem?

4 REPLIES 4
Message 2 of 5
vladop
in reply to: garet79

To find real block name use (vlax-get-property object 'EffectiveName).

Also, change "if" to "while" loop with ik incrementation.

Following code should work:

 

(defun c:bl()

  (setq gt (ssget "_X" '((0 . "INSERT"))))

  (setq ik 0)

  (while (< ik (sslength gt))

    (setq ent (ssname gt ik))

    (setq object (vlax-ename->vla-object ent))

    (setq block_name (vlax-get-property object 'EffectiveName))

    (if (= block_name "HDV1_GENERIC_BLOCK_LEFT")

      (progn

        (setq rtrn (c:wd_getattrval ent "INST"))

        (princ rtrn)

      )

    )

    (setq ik (1+ ik))

  )

  (princ)
)

 

Vladimir

Message 3 of 5
vladop
in reply to: vladop

Added one more line (vl-load-com) just in case.

 

(defun c:bl()

  (vl-load-com)

  (setq gt (ssget "_X" '((0 . "INSERT"))))
  (setq ik 0)
  (while (< ik (sslength gt))
    (setq ent (ssname gt ik))    
    (setq object (vlax-ename->vla-object ent))
    (setq block_name (vlax-get-property object 'EffectiveName))
    (if (= block_name "HDV1_GENERIC_BLOCK_LEFT")
      (progn
        (setq rtrn (c:wd_getattrval ent "INST"))
        (princ rtrn)
      )
    )
    (setq ik (1+ ik))
  )
  (princ)
)

Message 4 of 5
garet79
in reply to: vladop

Thanks for the help. Could you give a brief explanation of what those lines do?  As is, the code will only work for the last block inserted.  Inserted HDV1_GENERIC_BLOCK_LEFT and it put the INST value in the correct title block attribute(DWG1).  However, if I insert HDV1_GENERIC_BLOCK_RIGHT it will do the same but then HDV1_GENERIC_BLOCK_LEFT won't work.  I want it to update all three at the same time not based on the last block inserted.(As you can see HDV1_GENERIC_BLOCK_MIDDLE is my third block.)  Since their will only be one instance of each of the three blocks do I need the While loop?  Also if I run the code it updates attribute DWG1 to 111222 for example.  If I change the block INST value to 333666 and run it again I get 111222333666.  If it has a number already there I would like it to erase that number and update based on the current value of INST.  To solve this problem I was thinking using similar code to get the value of the three attributes(dwg1, dwg2, dwg3) and compare to the block INST values and correct accordingly.  What do ya think?

 

(defun c:bl()
    (vl-load-com)    
    (setq gt (ssget "_X" '((0 . "INSERT"))))
    (setq ik 0)
    (while (< ik (sslength gt))
        (setq ent (ssname gt ik))
        (setq object (vlax-ename->vla-object ent))
        (setq block_name (vlax-get-property object 'EffectiveName))
        (cond ((= block_name "HDV1_GENERIC_BLOCK_LEFT")
            (setq dg1 (c:wd_getattrval ent "INST"))
            (command "-attedit" "n" "n" "ele_d2b" "dwg1" "" "" dg1)
                )
          ((= block_name "HDV1_GENERIC_BLOCK_MIDDLE")
            (setq dg2 (c:wd_getattrval ent "INST"))
            (command "-attedit" "n" "n" "ele_d2b" "dwg2" "" "" dg2)
                )
          ((= block_name "HDV1_GENERIC_BLOCK_RIGHT")
            (setq dg3 (c:wd_getattrval ent "INST"))
            (command "-attedit" "n" "n" "ele_d2b" "dwg3" "" "" dg3)
                )
    )
    (setq ik (1+ik))
    )
(princ)
)       

Message 5 of 5
vladop
in reply to: garet79

With this line:

(setq gt (ssget "_X" '((0 . "INSERT"))))

all blocks in the drawing are selected, so while loop is used to check them all and find HDV1_GENERIC_BLOCK_... blocks.

 

I have no idea why other things described happen.

 

Did you try to find error using Visual LISP debugging menu?

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

Post to forums  

Autodesk Design & Make Report

”Boost