<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Help making attributed blocks from csv file in Visual LISP, AutoLISP and General Customization Forum</title>
    <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/help-making-attributed-blocks-from-csv-file/m-p/12257635#M23828</link>
    <description>&lt;P&gt;I've bitten off more then I can chew and I'm hoping someone here can help/take over/teach me.&amp;nbsp; I need to update a block library with new features and turn many generic blocks (blocks with same name but different values) into unique blocks for wblocking.&amp;nbsp; My thought is to make a generic dynamic block that I can then run this lisp on to add attributes and a few polylines.&amp;nbsp; I was hoping to get the attributes from a csv file formatted as you would get from running attout.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code and drawing should help answer questions that arise.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;I have all the attributes being made and placed where I want. (with the exception of multiple inputs/outputs)&lt;/LI&gt;&lt;LI&gt;started code to open and read csv&lt;OL&gt;&lt;LI&gt;put into safearray???? to match header row to attributes&lt;/LI&gt;&lt;LI&gt;loop if input to make enough input attributes based on csv&lt;/LI&gt;&lt;LI&gt;loop if output to make enough output attributes based on csv&lt;/LI&gt;&lt;LI&gt;make rectangle as shown in example and add tick marks next to I/O attributes&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;LI&gt;butchered and got frustrated with vla-addlightweigthpolyline&lt;/LI&gt;&lt;LI&gt;Rename block with new attributes from csv "Prefix-Manufacturer-PartNum"&lt;/LI&gt;&lt;LI&gt;Everything else I forgot or didn't think of because I'm clearly still learning.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;--And a quick thanks to&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/5644077"&gt;@dlanorh&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/593837"&gt;@ronjonp&lt;/a&gt;&amp;nbsp;for helping others and consequently me in getting attributes to be located where you want them to be and justified correctly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 21 Sep 2023 22:25:22 GMT</pubDate>
    <dc:creator>Village_Idiot</dc:creator>
    <dc:date>2023-09-21T22:25:22Z</dc:date>
    <item>
      <title>Help making attributed blocks from csv file</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/help-making-attributed-blocks-from-csv-file/m-p/12257635#M23828</link>
      <description>&lt;P&gt;I've bitten off more then I can chew and I'm hoping someone here can help/take over/teach me.&amp;nbsp; I need to update a block library with new features and turn many generic blocks (blocks with same name but different values) into unique blocks for wblocking.&amp;nbsp; My thought is to make a generic dynamic block that I can then run this lisp on to add attributes and a few polylines.&amp;nbsp; I was hoping to get the attributes from a csv file formatted as you would get from running attout.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code and drawing should help answer questions that arise.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;I have all the attributes being made and placed where I want. (with the exception of multiple inputs/outputs)&lt;/LI&gt;&lt;LI&gt;started code to open and read csv&lt;OL&gt;&lt;LI&gt;put into safearray???? to match header row to attributes&lt;/LI&gt;&lt;LI&gt;loop if input to make enough input attributes based on csv&lt;/LI&gt;&lt;LI&gt;loop if output to make enough output attributes based on csv&lt;/LI&gt;&lt;LI&gt;make rectangle as shown in example and add tick marks next to I/O attributes&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;LI&gt;butchered and got frustrated with vla-addlightweigthpolyline&lt;/LI&gt;&lt;LI&gt;Rename block with new attributes from csv "Prefix-Manufacturer-PartNum"&lt;/LI&gt;&lt;LI&gt;Everything else I forgot or didn't think of because I'm clearly still learning.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;--And a quick thanks to&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/5644077"&gt;@dlanorh&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/593837"&gt;@ronjonp&lt;/a&gt;&amp;nbsp;for helping others and consequently me in getting attributes to be located where you want them to be and justified correctly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2023 22:25:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/help-making-attributed-blocks-from-csv-file/m-p/12257635#M23828</guid>
      <dc:creator>Village_Idiot</dc:creator>
      <dc:date>2023-09-21T22:25:22Z</dc:date>
    </item>
    <item>
      <title>Re: Help making attributed blocks from csv file</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/help-making-attributed-blocks-from-csv-file/m-p/12265820#M23829</link>
      <description>&lt;P&gt;I managed to get a little further.&amp;nbsp; I could really use a hand.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;;	Add Attributes to selected blocks , copy block and save with new name based on attributes "prefix""Manufacturer""PartNum"


;#region Function : Copy Block Definition-----&amp;lt;&amp;lt;{{[[NOT INCORPERATED YET]]
;;vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
;; Copy Block Definition  -  Lee Mac
;; Duplicates a block definition, with the copied definition assigned the name provided.
;; blk - [str] name of block definition to be duplicated
;; new - [str] name to be assigned to copied block definition
;; Returns the copied VLA Block Definition Object, else nil

(defun LM:CopyBlockDefinition ( blk new / abc app dbc dbx def doc rtn vrs )
    (setq dbx
        (vl-catch-all-apply 'vla-getinterfaceobject
            (list (setq app (vlax-get-acad-object))
                (if (&amp;lt; (setq vrs (atoi (getvar 'acadver))) 16)
                    "objectdbx.axdbdocument" (strcat "objectdbx.axdbdocument." (itoa vrs))
                )
            )
        )
    )
    (cond
        (   (or (null dbx) (vl-catch-all-error-p dbx))
            (prompt "\nUnable to interface with ObjectDBX.")
        )
        (   (and
                (setq doc (vla-get-activedocument app)
                      abc (vla-get-blocks doc)
                      dbc (vla-get-blocks dbx)
                      def (LM:getitem abc blk)
                )
                (not (LM:getitem abc new))
            )
            (vlax-invoke doc 'copyobjects (list def) dbc)
            (vla-put-name (setq def (LM:getitem dbc  blk)) new)
            (vlax-invoke dbx 'copyobjects (list def) abc)
            (setq rtn (LM:getitem abc new))
        )
    )
    (if (= 'vla-object (type dbx))
        (vlax-release-object dbx)
    )
    rtn
)

;; VLA-Collection: Get Item  -  Lee Mac
;; Retrieves the item with index 'idx' if present in the supplied collection
;; col - [vla]     VLA Collection Object
;; idx - [str/int] Index of the item to be retrieved

(defun LM:getitem ( col idx / obj )
    (if (not (vl-catch-all-error-p (setq obj (vl-catch-all-apply 'vla-item (list col idx)))))
        obj
    )
)

;#endregion
;;--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(defun c:addattribute ( / ss i blk blks def AttObj InsrtPnt InsrtPnt2)
  (setq cntI 5)
  (setq cntO 6)
  ;--------------&amp;lt;{{[[ add LM:readcsv and figure out how to tie into attributes below
  
  
  ;-------------Start of working code to add attributes
    (and
       (setq ss (ssget '((0 . "INSERT"))))
       (setq i (sslength ss))
       (while (&amp;gt; i 0)
          (setq blk (cdr (assoc 2 (entget (ssname ss (setq i (1- i)))))))
          (if (not (vl-position blk blks))(setq blks (cons blk blks)))
       )
    )
    (foreach blk blks
         (setq def (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) blk))
        

;------------ATTRIBUT 01 --------------------------------------------------- 
      (setq InsrtPnt '(0 2.88 0))
      (setq AttObj
		(vla-addattribute def
                
              0.5                        ;----text hieght
             acAttributeModeLockPosition  ;--
             "Alias"                     ;----PROMPT
             (vlax-3d-point InsrtPnt)  ;---location in block --being overriden by acAlignmentxxx comand below --restate coordinates after
             "ALIAS"                     ;----TAG
             "Alias"                    ;----VALUE
         )
      )
        (vlax-put AttObj 'Alignment acAlignmentMiddleCenter) ; -----this does set the attribute value text justification, BUT it also negates the above entered vlax-3D-point coordinates during attribute creation
        (vlax-put-property AttObj 'textalignmentpoint (vlax-3d-point InsrtPnt))
        (vla-put-layer AttObj "TA-FUNC-ATTR-ALIAS")  
        (vla-put-stylename AttObj "BAH-MS-AV-StdrdBody-NARROW")
      
;------------ATTRIBUT 02 --------------------------------------------------- 
      (setq InsrtPnt '(0 2.13 0))
          (setq AttObj
		(vla-addattribute def
             
		          0.5
             acAttributeModeLockPosition
             "Manufacturer"
             (vlax-3d-point InsrtPnt)
             "MANUFACTURER"
             "xxxx2"
         )
      )
        (vlax-put AttObj 'Alignment acAlignmentmiddlecenter)
        (vlax-put-property AttObj 'textalignmentpoint (vlax-3d-point InsrtPnt))
        (vla-put-layer AttObj "TA-FUNC-ATTR")
        (vla-put-stylename AttObj "BAH-MS-AV-StdrdBody-NARROW")

;------------ATTRIBUT 03 ---------------------------------------------------  
      (setq InsrtPnt '(0 1.5 0))
          (setq AttObj
		(vla-addattribute def
             
		          0.5
             acAttributeModeLockPosition
             "Model"
             (vlax-3d-point InsrtPnt)
             "MODEL"
             "xxxx3"
         )
      )
        (vlax-put AttObj 'Alignment acAlignmentmiddlecenter)
        (vlax-put-property AttObj 'textalignmentpoint (vlax-3d-point InsrtPnt))
        (vla-put-layer AttObj "TA-FUNC-ATTR")
        (vla-put-stylename AttObj "BAH-MS-AV-StdrdBody-NARROW")

;------------ATTRIBUT 04 ---------------------------------------------------  
      (setq InsrtPnt '(0 0.88 0))
         (setq AttObj
		(vla-addattribute def
             
		          0.5
             acAttributeModeLockPosition
             "PartNum"
             (vlax-3d-point InsrtPnt)
             "PART_NUM"
             "xxxx4"
         )
      )
        (vlax-put AttObj 'Alignment acAlignmentmiddlecenter)
        (vlax-put-property AttObj 'textalignmentpoint (vlax-3d-point InsrtPnt))
        (vla-put-layer AttObj "TA-FUNC-ATTR")
        (vla-put-stylename AttObj "BAH-MS-AV-StdrdBody-NARROW")

;------------ATTRIBUT 05 ---------------------------------------------------  
      (setq InsrtPnt '(-2.75 0 0))
      (setq MvDist 0.75)
          (while (&amp;gt; cntI 0)
            (setq AttObj5;------------------&amp;lt;&amp;lt;&amp;lt;{{{Need to loop for multiple inputs placeing each .75 below the last----basics working but...
        
          (vla-addattribute def
              
                  0.4
                acAttributeModeLockPosition
                (strcat "Input" (itoa cntI))
                (vlax-3d-point InsrtPnt)
                (strcat "INPUT_" (itoa cntI))
                (strcat "IN-" (itoa cntI))
            )
            )
          (vlax-put AttObj5 'Alignment acAlignmentmiddleleft)
          (vlax-put-property AttObj5 'textalignmentpoint (vlax-3d-point InsrtPnt))
          (vla-put-layer AttObj5 "TA-FUNC-ATTR-IO")
          (vla-put-stylename AttObj5 "BAH-MS-AV-StdrdBody-NARROW")
          (setq InsrtPnt2 (cons (- (car InsrtPnt) 0.25) (cdr InsrtPnt)))
          (vla-addline def (vlax-3d-point InsrtPnt) (vlax-3d-point InsrtPnt2))
        (setq cntI (1- cntI))
          (setq InsrtPnt (list (car InsrtPnt)(+ (cadr InsrtPnt) MvDist)(caddr InsrtPnt)))
      );while
          
;------------ATTRIBUT 06 ---------------------------------------------------  
      (setq InsrtPnt '(2.75 0 0))
      (Setq MvDist 0.75)
      (while (&amp;gt; cntO 0)
        (setq AttObj6;------------------&amp;lt;&amp;lt;&amp;lt;{{{Need to loop for multiple outputs placeing each .75 below the last
          (vla-addattribute def
              
                0.4
              acAttributeModeLockPosition
              (strcat "Output" (itoa cntO))
              (vlax-3d-point InsrtPnt)
              (strcat "OUTPUT_" (itoa cntO))
              (strcat "Out-" (itoa cntO))
          )
        )
          (vlax-put AttObj6 'Alignment acAlignmentmiddleright)
          (vlax-put-property AttObj6 'textalignmentpoint (vlax-3d-point InsrtPnt))
          (vla-put-layer AttObj6 "TA-FUNC-ATTR-IO")
          (vla-put-stylename AttObj6 "BAH-MS-AV-StdrdBody-NARROW")
          (setq InsrtPnt2 (cons (+ (car InsrtPnt) 0.25) (cdr InsrtPnt)))
          (vla-addline def (vlax-3d-point InsrtPnt) (vlax-3d-point InsrtPnt2) )
                (setq cntO (1- cntO))
            (setq InsrtPnt (list (car InsrtPnt)(+ (cadr InsrtPnt) MvDist)(caddr InsrtPnt)))
      )
;------------ATTRIBUT 07 ---------------------------------------------------  
      (setq InsrtPnt '(0 3.5 0))
      (setq AttObj
		(vla-addattribute def
             
		          0.5
             acAttributeModeLockPosition
             "IP"
             (vlax-3d-point InsrtPnt)
             "IP"
             "192.168.1.1"
         )
      )     
      (vlax-put AttObj 'Alignment acAlignmentmiddlecenter)
      (vlax-put-property AttObj 'textalignmentpoint (vlax-3d-point InsrtPnt))
      (vla-put-layer AttObj "TA-FUNC-ATTR-IT")
      (vla-put-stylename AttObj "BAH-MS-AV-StdrdBody-NARROW")

;------------ATTRIBUT 08 ---------------------------------------------------  
      (setq InsrtPnt '(0 4.13 0))
      (setq AttObj
		(vla-addattribute def
             
		          0.5
             acAttributeModeLockPosition
             "MAC"
             (vlax-3d-point InsrtPnt)
             "MAC"
             "XXX"
         )
      )
	    (vlax-put AttObj 'Alignment acAlignmentmiddlecenter)
      (vlax-put-property AttObj 'textalignmentpoint (vlax-3d-point InsrtPnt))
      (vla-put-layer AttObj "TA-FUNC-ATTR-IT")
      (vla-put-stylename AttObj "BAH-MS-AV-StdrdBody-NARROW")
      
 ;----------------------------------------------------------------------------  
      ;------------&amp;lt;&amp;lt;{{[[Make rectang (need to make resize based on the greater of the IO count)]]
      (setq pt1 (list -2.75 -0.5))
      (setq pt2 (list -2.75 (+ (* cntI MvDist) 2.5)))
      (setq pt3 (list 2.75 (+ 2.5 (* cntI MvDist))))
      (setq pt4 (list 2.75 -0.5))
      (setq pnts (append pt1 pt2 pt3 pt4))
      (setq recArray (vlax-make-safearray vlax-vbDouble '(0 . 7)))
      (vlax-safearray-fill recArray pnts)
      (setq Rect (vla-addlightweightpolyline def recArray))           
      (vla-put-closed Rect :vlax-true)
      (vla-put-layer Rect "0")
     
      )
      
         (command "_.attsync" "_N" blk)
     )
    (princ)

(vl-load-com) (princ)&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 25 Sep 2023 22:18:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/help-making-attributed-blocks-from-csv-file/m-p/12265820#M23829</guid>
      <dc:creator>Village_Idiot</dc:creator>
      <dc:date>2023-09-25T22:18:15Z</dc:date>
    </item>
  </channel>
</rss>

