Results 1 to 1 of 1

Thread: AutoLisp to pass block attribute ID name and block count of a specific row to “Putcell” command for the GetExcel routine

  1. #1
    Woo! Hoo! my 1st post
    Join Date
    2021-08
    Posts
    1
    Login to Give a bone
    0

    Default AutoLisp to pass block attribute ID name and block count of a specific row to “Putcell” command for the GetExcel routine

    I’m creating a pricing sheet by pulling attribute IDs and their duplicate block count (block instances) from a CAD drawing and putting them into an existing excel file. I think I have most of the separate parts needed but can’t figure out how to put it all together so looking for some help.

    These are the Steps I believe are needed in my routine:

    Load the GetExcel.lsp functions needed to put info from CAD into existing Excel.
    Open Excel to write.
    Get attribute ID name from a block. Associate name with a row. EX: ID name “A006” = row 10.
    Get duplicate count of that block. Ex: “3”.
    Create a loop (foreach?) to add ID name and count into corresponding “Putcell” commands (know by its row number). I can have a putcell command with a row for all 200 ID names.
    Save and close Excel.
    Here is a mockup image of the end result when blocks with IDs “A002”, “A006”, “A009”, “A012” are found in the attached drawing.
    MyBlocks_att_Test_Example.JPG

    What I know:

    a) I have a set number of attribute ID names (1 through 200) that I will ever encounter so I know all the possible names and the rows it need to go to. (Ex: ID “A006” goes in row 10).

    b) I can make a Putcell command ready for each of those ID names to cover all (1 through 200).


    What I don’t know:

    c) How to associate block ID name with a row.

    d) How to find duplicate block count and associate it with block ID name/row.

    e) How to add ID name and count to a putcell command associated by row like this: (PutCell "B10" '("A006" 3)). "A006" will always go with row 10. What Attribute ID names found and the count is the variable that changes for each drawing.


    Routine from Getexcel: Credit Terry Miller




    Unfortunately there is not enough room to post the "Getexcel.lsp" Code here. Hopefully someone can grab it for reference. The complete code contains the "Putcell" function...





    Here are some routines I was looking at in order to grab the block info needed.

    Block attribute ID name:

    Here is one from Lee Mac that finds Attribute IDs and saves to variable “data”. I took out the excel export part since that can be handled by Getexcel.lsp routine.


    Code:
    ;; Text 2 CSV  -  Lee Mac
    ;; Writes all Text, MText & Attribute content from all layouts and within
    ;; all blocks and nested blocks to a selected CSV file.
    
    (defun c:txt2csv ( / data file )
        (cond
            (   (not
                    (progn
                        (vlax-for block (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
                            (if (eq :vlax-false (vla-get-isxref block))
                                (vlax-for obj block
                                    (cond
                                        (   (wcmatch (vla-get-objectname obj) "AcDb*Text")
                                            (setq data (cons (vla-get-textstring obj) data))
                                        )
                                        (   (and
                                                (eq "AcDbBlockReference" (vla-get-objectname obj))
                                                (eq :vlax-true (vla-get-hasattributes obj))
                                            )
                                            (foreach att (vlax-invoke obj 'getattributes)
                                                (setq data (cons (vla-get-textstring att) data))
                                            )
                                        )
                                    )
                                )
                            )
                        )
                        data
                    )
                )
                (princ "\nNo Text, MText or Attributes found.")
            )
            (   (not (setq file (getfiled "Create CSV file" "" "csv" 1)))
                (princ "\n*Cancel*")
            )
            (   (setq file (open file "w"))
                (foreach x data (write-line x file))
                (setq file (close file))
                (princ (strcat "\n" (itoa (length data)) " strings written to file."))
            )
            (   (princ "\nUnable to open CSV file for writing."))
        )
        (princ)
    )
    (vl-load-com) (princ)



    Block count.


    Code:
    (defun c:myblockcounter ( / blk idx itm lst sel )
        (if (setq sel (ssget '((0 . "INSERT"))))
            (repeat (setq idx (sslength sel))
                (setq blk (cdr (assoc 2 (entget (ssname sel (setq idx (1- idx)))))))
                (if (setq itm (assoc blk lst))
                    (setq lst (subst (cons blk (1+ (cdr itm))) itm lst))
                    (setq lst (cons  (cons blk 1) lst))
                )
            )
        )
        (foreach itm lst (princ (strcat "\n" (car itm) ": " (itoa (cdr itm)))))
        (princ)
    )
    Any help is greatly appreciated!
    Attached Files Attached Files

Similar Threads

  1. GetExcel.lsp
    By jimmy_goodall in forum AutoLISP
    Replies: 8
    Last Post: 2022-04-15, 03:20 AM
  2. Copy row in schedule to another row in the same schedule in revit
    By hanycd82747545 in forum BIM Management - General
    Replies: 5
    Last Post: 2017-10-30, 05:50 PM
  3. Replies: 1
    Last Post: 2017-01-15, 12:22 AM
  4. Count Specific Attribute Values
    By antistar in forum AutoLISP
    Replies: 15
    Last Post: 2014-01-23, 11:40 AM
  5. Replies: 13
    Last Post: 2007-03-19, 11:37 AM

Tags for this Thread

Posting Permissions

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