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

Thread: Help with Handles!

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Member
    Join Date
    2013-02
    Posts
    6
    Login to Give a bone
    0

    Default Help with Handles!

    I have multiple instances of a block(same attributes) in a drawing and want to put different information in each attributes. I was told to use attout/attin. I used attout to get all of the handles on the drawing and wrote them down. Let's say we have handle 472A2 and 472A3 - 2 blocks that are same and they have an Attribute 'TAG1'.
    I have this section of code that used to handle this by having the user select which block and then puts the info from cell 0 into TAG1:
    Code:
    (if vl
        (progn
    
    
          (setq en (entsel "\nSelect Block: "))
          (setq blkobj (vlax-ename->vla-object (car en)))
          ;; change attributes
          (setq attribs (vlax-invoke blkobj 'getattributes))
          (foreach attref attribs
            (cond ;;DYNAMIC DATA FROM EXCEL SPREADSHEET;;
                  ((eq (vla-get-tagstring attref) "TAG1")
                   (vla-put-textstring attref (nth 0 vl)));A2 TO "TAG1" (LANE #)
    Can someone help me so the user doesn't pick blocks, it automatically searches for the 2 handles (and other blocks on the drawing) I used above and puts the info from cell 0 into each block instance. I also need a conditional that if the cell is blank (nil) do nothing but if there is info, for example, in cell (nth 10 vl) change DESCX to info in cell (nth 10 vl), change DESCY to a text constant "METER" and DESCZ to "PRESET". I do this so I can set up the DWG template showing all spares. All of the blocks aren't the same but some are and I don't know how to "handle" that - pun intended.
    If need be, I can supply sample XLS, the rest of the code, and a sample DWG
    Last edited by Opie; 2013-02-28 at 03:42 PM. Reason: [CODE] tags added

  2. #2
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,100
    Login to Give a bone
    0

    Default Re: Help with Handles!

    You need to replace this portion of your code
    Code:
          (setq en (entsel "\nSelect Block: "))
    with maybe this
    Code:
    (setq en (handent string variable containing the handle))
    Of course, the portion in red above will need to be replaced with a variable containing the handle string.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  3. #3
    Member
    Join Date
    2013-02
    Posts
    6
    Login to Give a bone
    0

    Default Re: Help with Handles!

    Thanks, I will try that.

  4. #4
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Help with Handles!

    Perhaps this example from another thread will be useful?

    Quote Originally Posted by RenderMan View Post
    Is this what you're after? *not sure*

    Code:
    (defun c:FOO (/ handle eName ss)
      (if (and (setq handle (getstring "\nEnter object handle to select: "))
               (setq eName (handent handle))
               (setq ss (ssadd))
          )
        (progn
          (sssetfirst nil (setq ss (ssadd eName ss)))
          (prompt "\n** Object selected ** ")
        )
        (prompt "\n** Object handle not found ** ")
      )
      (princ)
    )
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  5. #5
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Help with Handles!

    I am curious why you do not just iterate the Block Table/Collection to perform your update(s)?
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  6. #6
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Help with Handles!

    Quote Originally Posted by RenderMan View Post
    I am curious why you do not just iterate the Block Table/Collection to perform your update(s)?
    Quickly written example, iterating a selection set of attributed blocks:

    Code:
    (vl-load-com)
    
    (defun c:FOO (/ handles ss acDoc tagString)
    
      ;; hard-coded handles
      (setq handles '("handle1" "handle2"))
    
      ;; main code
      (if (setq ss (ssget "_x" '((0 . "INSERT") (66 . 1))))
        (progn
          (vlax-for oBlock (vla-get-activeselectionset
                             (setq acDoc (vla-get-activedocument
                                           (vlax-get-acad-object)
                                         )
                             )
                           )
            (foreach oAttrib (vlax-invoke oBlock 'GetAttributes)
              (cond
                ((= "TAG1" (setq tagString (vla-get-tagstring oAttrib)))
                 ;; <-- your code here
                )
                ((= "TAG2" tagString)
                 ;; <-- your code here
                )
              )
            )
          )
          (vla-delete ss)
        )
        (prompt "\n** No attributed blocks found ** ")
      )
      (princ)
    )
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  7. #7
    Member
    Join Date
    2013-02
    Posts
    6
    Login to Give a bone
    0

    Default Re: Help with Handles!

    On your last code it looks like you are assigning 'handle1' and 'handle2' to a list called 'handles' but I don't see where that list is used anywhere in the rest of the program? Or does it use the (0 . "INSERT") (66 . 1) to only look at attributes of those 2 handles?

    I have 2 blocks that are the same(have same attributes), but get different information from the .xls. I have other blocks (that are different) that share the same info. I have attributes (name-wise) that are the same on different blocks but don't get the same information. It's complicated and very conditional. Sorry if my questions sound dumb, but I'm very new to this and I'm jumping right into it.

    My work day is over soon, so I'll have to look at this more tomorrow. Maybe I should just share the .dwg, .xls, and all of the code and go over exactly what I'm trying to do?

    Thanks for the help so far!

  8. #8
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Help with Handles!

    Quote Originally Posted by dupuy77362646 View Post
    On your last code it looks like you are assigning 'handle1' and 'handle2' to a list called 'handles' but I don't see where that list is used anywhere in the rest of the program? Or does it use the (0 . "INSERT") (66 . 1) to only look at attributes of those 2 handles?
    That's where you were supposed to pick up from the ";;<-- your code here" comment. thumbsup.gif

    Originally, I presumed that you'd test the Object's Handle depending on the TagString of the Attribute, but after reading your last post, perhaps it would be better to first test for the hard-coded Handle, then step into the Attributes (less processing time, methinks). Code revised.

    Code:
    (vl-load-com)
    
    (defun c:FOO (/ handle1 handle2 handles _UpdateAtt ss acDoc oHandle
                  tagString
                 )
    
      ;; hard-coded handles
      (setq handles
             (list
               (setq handle1 "handle1")
               (setq handle2 "handle2")
             )
      )
    
      ;; update attribute sub-function
      (defun _UpdateAtt (oBlock tagString textString)
        (foreach oAttrib (vlax-invoke oBlock 'GetAttributes)
          (if (= tagString (vla-get-tagstring oAttrib))
            (vla-put-textstring oAttrib textString)
          )
        )
      )
    
      ;; main code
      (if (setq ss (ssget "_x" '((0 . "INSERT") (66 . 1))))
        (progn
          (vlax-for oBlock (vla-get-activeselectionset
                             (setq acDoc (vla-get-activedocument
                                           (vlax-get-acad-object)
                                         )
                             )
                           )
            (if
              (vl-position (setq oHandle (vla-get-handle oBlock)) handles)
               (_UpdateAtt
                 oBlock
                 "TAG1"
                 (cond
                   ((= handle1 oHandle) "Handle1 updated")
                   ((= handle2 oHandle) "Handle2 updated")
                   ;;<-- more handles?
                 )
               )
            )
          )
          (vla-delete ss)
        )
        (prompt "\n** No attributed blocks found ** ")
      )
      (princ)
    )
    Can't be certain this will be sufficient, as I do not have enough information about what your code does different for each entity's Handle.
    Last edited by RenderMan; 2013-02-28 at 09:24 PM.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  9. #9
    Member
    Join Date
    2013-02
    Posts
    6
    Login to Give a bone
    0

    Default Re: Help with Handles!

    Ok, I've attached the DWG of what it would look like (some stuff is wrong) after running the program; I've attached the .XLS and the .LSP.

    It grabs the info from 4 columns of cells (that the user selects) and puts them into a list.

    First things first, you will notice that the program has the user select the block. I don't want to select 1 block, I want the program to automatically just stick everything where it belongs on all blocks.

    The first cell (nth 0 vl) "LANE 1" will go to DESC1 of 3 different blocks - FCM_4ACOUT, RTD_ANALOG_RTD, AND FCM_4DCIN.

    Cell (nth 15 vl) "GENERIC" WILL GO TO DESCC2 (FCM_4ACOUT). This cell might be empty. The DWG will start off with everything labeled "SPARE" and I need a conditional that checks if the cell isn't blank then change DESCE3 TO "ADDITIVE" and DESCE4 TO "METER"; otherwise it won't do anything, leaving just the word "SPARE" there.

    Cell (nth 24 vl) "FE-112" will go to TAG1 of block FLOW_METER that is attached to Port 6.

    Cell (nth 18 vl) "SOV-111" will go to TAG1 of block HSV1 that is attached to Port 0 of block FCM_4ACOUT.

    Every place where the supplied DWG says "REGULAR" will be replaced with "PREMIUM". Notice DESCC3 of block FCM_4ACOUT will have the word "PREMIUM" added to the word "UPSTREAM"

    Wire numbers (WD_WNH) will be updated also from info in column 4 of the .XLS.

    Hopefully that helps and sorry if I'm overwhelming you with information. The reason I was trying to use the Handles was because that was recommended to me. I want the program to place the info in the cells to the appropriate tags. I can figure out the simple stuff, just not the IF statement (you can see it commented out in the lisp program because it wasn't working.) or dealing with multiple blocks with different and sometimes same attribute names.
    Attached Files Attached Files

  10. #10
    I could stop if I wanted to
    Join Date
    2005-06
    Location
    CORDOBA-ARGENTINA
    Posts
    275
    Login to Give a bone
    0

    Default Re: Help with Handles!

    Find attached the before and after DWG , in 2007 .
    Both lisp

    I would rather prefer the use of CSV file to get values , there is no user mistake allowed
    Attached Files Attached Files

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 0
    Last Post: 2014-12-27, 08:59 PM
  2. Stationary handles!
    By vgriffiths120838 in forum Dynamic Blocks - Technical
    Replies: 2
    Last Post: 2012-08-02, 09:24 AM
  3. Entity handles
    By MikeJarosz in forum VBA/COM Interop
    Replies: 1
    Last Post: 2007-11-01, 04:55 AM
  4. Knobs and Handles
    By checkpost100 in forum AutoCAD Gallery
    Replies: 10
    Last Post: 2005-10-12, 08: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
  •