<?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 Re: AutoCAD Performance Issue When Inserting Large Number of Blocks via LISP in Visual LISP, AutoLISP and General Customization Forum</title>
    <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/autocad-performance-issue-when-inserting-large-number-of-blocks/m-p/14039513#M170297</link>
    <description>&lt;P&gt;Read Theswamp post for more suggestions.&lt;/P&gt;</description>
    <pubDate>Tue, 03 Mar 2026 03:04:02 GMT</pubDate>
    <dc:creator>Sea-Haven</dc:creator>
    <dc:date>2026-03-03T03:04:02Z</dc:date>
    <item>
      <title>AutoCAD Performance Issue When Inserting Large Number of Blocks via LISP</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/autocad-performance-issue-when-inserting-large-number-of-blocks/m-p/14037764#M170256</link>
      <description>&lt;P&gt;&lt;FONT size="4"&gt;I’m experiencing a performance issue when inserting a large number of blocks into AutoCAD using the script below.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="4"&gt;The script works perfectly — it correctly inserts the blocks, sets the insertion point, and adjusts the visibility state as expected. However, when I try to insert a large number of blocks (for example, using the attached CSV file), the process becomes extremely slow and can take several hours to complete.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="4"&gt;I have a few questions:&lt;/FONT&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;&lt;FONT size="4"&gt;Is there a way to improve performance and make the insertion process faster?&lt;/FONT&gt;&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;FONT size="4"&gt;I noticed that this method creates many anonymous blocks (*U22, *U23, *U123, etc.). Could this be the reason why performance degrades over time? It starts fast but becomes progressively slower.&lt;/FONT&gt;&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;FONT size="4"&gt;If the block definition is not already present in the drawing and exists only in an external file (e.g., C://example//PNT_IMPORT.dwg), what would be the best approach to handle this efficiently?&lt;/FONT&gt;&lt;/P&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;FONT size="4"&gt;I’ve attached a sample DWG and CSV file for reference.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="4"&gt;Thank you in advance for your help.&lt;BR /&gt;&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;LI-CODE lang="lisp"&gt;(defun c:DEMO ( )
  (setvar 'REGENMODE 0)
  (if
    (and
      (setq file (getfiled "Select CSV File" (getvar 'DWGPREFIX) "csv" 16))
      (setq data (LM:readcsv file))
    )
    (foreach line data
      (setq item line)
      (setq pnt (list (atof (nth 9 item)) (atof(nth 8 item)) 0.0 ))
      (import:BlkInsert-Short 
        (car item) 
        pnt  ;;ponto
        (nth 1 item) ;visibilidade
        (nth 2 item) ;info1
        (nth 3 item) ;info2
        (nth 4 item) ;info3
        (nth 5 item) ;info4
        (nth 6 item) ;info5
        (nth 7 item) ;info6
      )
    )
  )
  (setvar 'REGENMODE 1)
  (princ)
)

(defun import:BlkInsert-Short (nomebloco ponto visibility INFO1 INFO2 INFO3 INFO4 INFO5 INFO6 / block atts)
  (if (and nomebloco ponto)
    (progn
      (setq block 
        (vla-InsertBlock
          (if (= 1 (getvar 'cvport))
            (vla-get-paperspace (vla-get-activedocument (vlax-get-acad-object)))
            (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))
          )
          (vlax-3d-point (trans ponto 1 0))
          nomebloco 1 1 1 0
        )
      )      
      (LM:SetVisibilityState block visibility)      
      ;; Se você sabe a ordem exata dos atributos no bloco
      (if (vla-get-HasAttributes block)
        (progn
          (setq atts (vlax-safearray-&amp;gt;list (vlax-variant-value (vla-getAttributes block))))          
          ;; Atribui na ordem: ajuste os índices conforme seu bloco
          (if (&amp;gt;= (length atts) 4)
            (progn
              (vla-put-TextString (nth 0 atts) INFO1) 
              (vla-put-TextString (nth 1 atts) INFO2) 
              (vla-put-TextString (nth 2 atts) INFO3)
              (vla-put-TextString (nth 3 atts) INFO4)
              (vla-put-TextString (nth 4 atts) INFO5)
              (vla-put-TextString (nth 5 atts) INFO6)
            )
          )
        )
      )
    )
  )
  (princ)
)


;; Read CSV  -  Lee Mac
;; Parses a CSV file into a matrix list of cell values.
;; csv - [str] filename of CSV file to read
 
(defun LM:readcsv ( csv / des lst sep str )
    (if (setq des (open csv "r"))
        (progn
            (setq sep (cond ((vl-registry-read "HKEY_CURRENT_USER\\Control Panel\\International" "sList")) (",")))
            (while (setq str (read-line des))
                (setq lst (cons (LM:csv-&amp;gt;lst str sep 0) lst))
            )
            (close des)
        )
    )
    (reverse lst)
)

;; CSV -&amp;gt; List  -  Lee Mac
;; Parses a line from a CSV file into a list of cell values.
;; str - [str] string read from CSV file
;; sep - [str] CSV separator token
;; pos - [int] initial position index (always zero)
 
(defun LM:csv-&amp;gt;lst ( str sep pos / s )
    (cond
        (   (not (setq pos (vl-string-search sep str pos)))
            (if (wcmatch str "\"*\"")
                (list (LM:csv-replacequotes (substr str 2 (- (strlen str) 2))))
                (list str)
            )
        )
        (   (or (wcmatch (setq s (substr str 1 pos)) "\"*[~\"]")
                (and (wcmatch s "~*[~\"]*") (= 1 (logand 1 pos)))
            )
            (LM:csv-&amp;gt;lst str sep (+ pos 2))
        )
        (   (wcmatch s "\"*\"")
            (cons
                (LM:csv-replacequotes (substr str 2 (- pos 2)))
                (LM:csv-&amp;gt;lst (substr str (+ pos 2)) sep 0)
            )
        )
        (   (cons s (LM:csv-&amp;gt;lst (substr str (+ pos 2)) sep 0)))
    )
)

(defun LM:csv-replacequotes ( str / pos )
    (setq pos 0)
    (while (setq pos (vl-string-search  "\"\"" str pos))
        (setq str (vl-string-subst "\"" "\"\"" str pos)
              pos (1+ pos)
        )
    )
    str
)



;; Set Dynamic Block Visibility State  -  Lee Mac
;; Sets the Visibility Parameter of a Dynamic Block (if present) to a specific value (if allowed)
;; blk - [vla] VLA Dynamic Block Reference object
;; val - [str] Visibility State Parameter value
;; Returns: [str] New value of Visibility Parameter, else nil

(defun LM:SetVisibilityState ( blk val / vis )
  (if
    (and
      (setq vis (LM:getvisibilityparametername blk))
      (member (strcase val) (mapcar 'strcase (LM:getdynpropallowedvalues blk vis)))
    )
    (LM:setdynpropvalue blk vis val)
  )
)

;-------------------------------------------------------------------------------;
;; Get Visibility Parameter Name  -  Lee Mac
;; Returns the name of the Visibility Parameter of a Dynamic Block (if present)
;; blk - [vla] VLA Dynamic Block Reference object
;; Returns: [str] Name of Visibility Parameter, else nil

(defun LM:getvisibilityparametername ( blk / vis )  
    (if
        (and
            (vlax-property-available-p blk 'effectivename)
            (setq blk
                (vla-item
                    (vla-get-blocks (vla-get-document blk))
                    (vla-get-effectivename blk)
                )
            )
            (= :vlax-true (vla-get-isdynamicblock blk))
            (= :vlax-true (vla-get-hasextensiondictionary blk))
            (setq vis
                (vl-some
                   '(lambda ( pair )
                        (if
                            (and
                                (= 360 (car pair))
                                (= "BLOCKVISIBILITYPARAMETER" (cdr (assoc 0 (entget (cdr pair)))))
                            )
                            (cdr pair)
                        )
                    )
                    (dictsearch
                        (vlax-vla-object-&amp;gt;ename (vla-getextensiondictionary blk))
                        "ACAD_ENHANCEDBLOCK"
                    )
                )
            )
        )
        (cdr (assoc 301 (entget vis)))
    )
)

;-------------------------------------------------------------------------------;
;; Get Dynamic Block Property Allowed Values  -  Lee Mac
;; Returns the allowed values for a specific Dynamic Block property.
;; blk - [vla] VLA Dynamic Block Reference object
;; prp - [str] Dynamic Block property name (case-insensitive)
;; Returns: [lst] List of allowed values for property, else nil if no restrictions

(defun LM:getdynpropallowedvalues ( blk prp )
    (setq prp (strcase prp))
    (vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (vlax-get x 'allowedvalues)))
        (vlax-invoke blk 'getdynamicblockproperties)
    )
)

;-------------------------------------------------------------------------------;
;; Set Dynamic Block Property Value  -  Lee Mac
;; Modifies the value of a Dynamic Block property (if present)
;; blk - [vla] VLA Dynamic Block Reference object
;; prp - [str] Dynamic Block property name (case-insensitive)
;; val - [any] New value for property
;; Returns: [any] New value if successful, else nil

(defun LM:setdynpropvalue ( blk prp val )
    (setq prp (strcase prp))
    (vl-some
       '(lambda ( x )
            (if (= prp (strcase (vla-get-propertyname x))) 
                (progn
                    (vla-put-value x (vlax-make-variant val (vlax-variant-type (vla-get-value x))))
                    (cond (val) (t))
                )
            )
        )
        (vlax-invoke blk 'getdynamicblockproperties)
    )
)

(defun LM:getvisibilitystate ( blk / vis )
    (if (setq vis (LM:getvisibilityparametername blk))
        (LM:getdynpropvalue blk vis)
    )
)


;; Get Dynamic Block Property Value  -  Lee Mac
;; Returns the value of a Dynamic Block property (if present)
;; blk - [vla] VLA Dynamic Block Reference object
;; prp - [str] Dynamic Block property name (case-insensitive)

(defun LM:getdynpropvalue ( blk prp )
    (setq prp (strcase prp))
    (vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (vlax-get x 'value)))
        (vlax-invoke blk 'getdynamicblockproperties)
    )
)&lt;/LI-CODE&gt;&lt;P&gt;&lt;FONT size="4"&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Mar 2026 10:17:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/autocad-performance-issue-when-inserting-large-number-of-blocks/m-p/14037764#M170256</guid>
      <dc:creator>frjuniornogueira1</dc:creator>
      <dc:date>2026-03-02T10:17:32Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD Performance Issue When Inserting Large Number of Blocks via Script</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/autocad-performance-issue-when-inserting-large-number-of-blocks/m-p/14037782#M170257</link>
      <description>&lt;P&gt;Answering your last two questions&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="4"&gt;&lt;STRONG&gt;Q2.&lt;/STRONG&gt; I noticed that this method creates many anonymous blocks (*U22, *U23, *U123, etc.). Could this be the reason why performance degrades over time? It starts fast but becomes progressively slower.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="4"&gt;&lt;STRONG&gt;A2:&lt;/STRONG&gt; When dynamic blocks are used, AutoCAD stores the different visibility states using different block names&amp;nbsp;(*U22, *U23, *U123, etc.). But since they all do reference the same block definition, this should not be the reason for the slowness as more of them are inserted from the CSV.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="4"&gt;&lt;STRONG&gt;Q3.&lt;/STRONG&gt;If the block definition is not already present in the drawing and exists only in an external file (e.g., C://example//PNT_IMPORT.dwg), what would be the best approach to handle this efficiently?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="4"&gt;&lt;STRONG&gt;A3:&lt;/STRONG&gt;&lt;/FONT&gt; You can use AutoCAD 2021+'s built-in &lt;STRONG&gt;-INSERTCONTENT&lt;/STRONG&gt; command to bring a block in that's located inside another dwg such as &lt;STRONG&gt;PNT_IMPORT.dwg&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;AutoCAD documentation:&lt;/P&gt;&lt;P&gt;&lt;A href="https://help.autodesk.com/view/ACDLT/2022/ENU/?guid=GUID-B5D64510-561E-4FA9-8AD6-625445CCD81F" target="_blank"&gt;https://help.autodesk.com/view/ACDLT/2022/ENU/?guid=GUID-B5D64510-561E-4FA9-8AD6-625445CCD81F&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Thread demonstrating usage:&lt;/P&gt;&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/quot-insertcontent-quot-not-functioning-as-expected/td-p/12830382" target="_blank"&gt;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/quot-insertcontent-quot-not-functioning-as-expected/td-p/12830382&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 01 Mar 2026 22:27:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/autocad-performance-issue-when-inserting-large-number-of-blocks/m-p/14037782#M170257</guid>
      <dc:creator>paullimapa</dc:creator>
      <dc:date>2026-03-01T22:27:01Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD Performance Issue When Inserting Large Number of Blocks via Script</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/autocad-performance-issue-when-inserting-large-number-of-blocks/m-p/14037855#M170260</link>
      <description>&lt;P&gt;Also posted at &lt;A href="https://www.theswamp.org/index.php?topic=60553.msg626501#msg626501" target="_blank"&gt;AutoCAD Performance Issue When Inserting Large Number of Blocks via Script&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Made some suggestions to try, as&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1137264"&gt;@paullimapa&lt;/a&gt;&amp;nbsp;suggested no check for does block exist. If not maybe do a message or at end display all block names not found.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Mar 2026 00:34:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/autocad-performance-issue-when-inserting-large-number-of-blocks/m-p/14037855#M170260</guid>
      <dc:creator>Sea-Haven</dc:creator>
      <dc:date>2026-03-02T00:34:07Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD Performance Issue When Inserting Large Number of Blocks via Script</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/autocad-performance-issue-when-inserting-large-number-of-blocks/m-p/14038322#M170270</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1137264"&gt;@paullimapa&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;I'm already using something similar. Currently, I'm using the "_.insert" command and running the loop as shown in the attachment.&lt;/P&gt;&lt;P&gt;Even so, I'll test your suggestion to see if I can get any performance improvement.&lt;/P&gt;&lt;P&gt;Thank you for your contribution!&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/6254908"&gt;@Sea-Haven&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;I saw and tested your answer on the other forum, but unfortunately I didn't get any performance gain.&lt;/P&gt;&lt;P&gt;From what I observed, the main problem is really the insertion speed. When the volume is large, the process starts quickly, but as the number of blocks increases, it becomes progressively slower.&lt;/P&gt;&lt;P&gt;I'm considering splitting the CSV into parts (1/3, 2/3, 3/3...) and running it in stages as an alternative solution.&lt;/P&gt;&lt;P&gt;However, before doing that, I'd like to know if anyone has another suggestion or a more efficient approach.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Mar 2026 10:14:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/autocad-performance-issue-when-inserting-large-number-of-blocks/m-p/14038322#M170270</guid>
      <dc:creator>frjuniornogueira1</dc:creator>
      <dc:date>2026-03-02T10:14:14Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD Performance Issue When Inserting Large Number of Blocks via LISP</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/autocad-performance-issue-when-inserting-large-number-of-blocks/m-p/14039513#M170297</link>
      <description>&lt;P&gt;Read Theswamp post for more suggestions.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Mar 2026 03:04:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/autocad-performance-issue-when-inserting-large-number-of-blocks/m-p/14039513#M170297</guid>
      <dc:creator>Sea-Haven</dc:creator>
      <dc:date>2026-03-03T03:04:02Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD Performance Issue When Inserting Large Number of Blocks via LISP</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/autocad-performance-issue-when-inserting-large-number-of-blocks/m-p/14040991#M170312</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/18131778"&gt;@frjuniornogueira1&lt;/a&gt;&amp;nbsp; a écrit&amp;nbsp;:&lt;BR /&gt;&lt;P&gt;&lt;FONT size="4"&gt;I’m experiencing a performance issue when inserting a large number of blocks into AutoCAD using the script below.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="4"&gt;The script works perfectly — it correctly inserts the blocks, sets the insertion point, and adjusts the visibility state as expected. However, when I try to insert a large number of blocks (for example, using the attached CSV file), the process becomes extremely slow and can take several hours to complete.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="4"&gt;I have a few questions:&lt;/FONT&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;&lt;FONT size="4"&gt;Is there a way to improve performance and make the insertion process faster?&lt;/FONT&gt;&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;FONT size="4"&gt;I noticed that this method creates many anonymous blocks (*U22, *U23, *U123, etc.). Could this be the reason why performance degrades over time? It starts fast but becomes progressively slower.&lt;/FONT&gt;&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;FONT size="4"&gt;If the block definition is not already present in the drawing and exists only in an external file (e.g., C://example//PNT_IMPORT.dwg), what would be the best approach to handle this efficiently?&lt;/FONT&gt;&lt;/P&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;FONT size="4"&gt;I’ve attached a sample DWG and CSV file for reference.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="4"&gt;Thank you in advance for your help.&lt;/FONT&gt;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P class="lia-align-left"&gt;&lt;FONT size="4"&gt;Is there a way to improve performance and make the insertion process faster&lt;/FONT&gt;Hi,&lt;BR /&gt;I suggest another way.&lt;BR /&gt;I consider that the use of visibility on a block, in your case, is not really useful...&lt;BR /&gt;My way is to use standard blocks (4 blocks), but that's just my point of view.&lt;BR /&gt;Nevertheless, the use of blocks with a visibility option will greatly increase the weight of the file (and the implementation) and I don't think you will try to change the visibility on about 88000 blocks...&lt;BR /&gt;If you try my code in a new drawing, it will only take about 4 minutes to set up the blocks (in my case)&lt;BR /&gt;You just need to select your CSV file after running the IMPORT command.&lt;/P&gt;&lt;P class="lia-align-left"&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Mar 2026 21:35:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/autocad-performance-issue-when-inserting-large-number-of-blocks/m-p/14040991#M170312</guid>
      <dc:creator>CADaSchtroumpf</dc:creator>
      <dc:date>2026-03-03T21:35:24Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD Performance Issue When Inserting Large Number of Blocks via LISP</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/autocad-performance-issue-when-inserting-large-number-of-blocks/m-p/14041054#M170315</link>
      <description>&lt;P&gt;&lt;STRONG&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/524107"&gt;@CADaSchtroumpf&lt;/a&gt;&amp;nbsp;This approach — and especially the speed — is simply outstanding!&lt;BR /&gt;&lt;/STRONG&gt;&lt;BR /&gt;For me, the insertion time was under 4 minutes, which is an excellent result.&lt;/P&gt;&lt;P&gt;However, I need to insert &lt;STRONG&gt;dynamic blocks&lt;/STRONG&gt; (the attached block is just an example).&lt;/P&gt;&lt;P&gt;I’ve already tried a few different approaches, but the performance result remains practically the same.&lt;/P&gt;&lt;P&gt;Here’s what I’ve tested so far:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;Used a loop to insert the attributes (method below);&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Tried using vla-purgeall;&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Unfortunately, the performance difference was almost imperceptible.&lt;/P&gt;&lt;P&gt;My question is: is there any way to improve performance — even slightly — when working with dynamic blocks?&lt;BR /&gt;As it stands, the process ends up taking almost an entire day to complete the insertions.&lt;/P&gt;&lt;P&gt;I honestly believe there must be a more optimized way to handle this — perhaps a different approach that I’m not considering.&lt;/P&gt;&lt;LI-CODE lang="lisp"&gt;(defun imp:insertblock-fast (target-space nomebloco ponto atributos / blk atts i)
  ;; 1. Inserção direta no espaço já fornecido (evita checar CVPORT toda vez)
  (setq blk (vla-insertblock target-space (vlax-3d-point ponto) nomebloco 1.0 1.0 1.0 0.0))
  
  ;; 2. Visibility State - Só chama se houver mudança necessária
  ;; Nota: Se muitos blocos tiverem o mesmo estado, o AutoCAD tenta reaproveitar o bloco anônimo.
  (if (and LM:setvisibilitystate (car atributos)) 
    (LM:setvisibilitystate blk (car atributos))
  )

  ;; 3. Atributos - Otimização de loop (evita o uso exaustivo de 'nth')
  (if (and (= (vla-get-hasattributes blk) :vlax-true) (cdr atributos))
    (progn
      (setq atts (vlax-safearray-&amp;gt;list (vlax-variant-value (vla-getattributes blk))))
      (setq i 0)
      ;; Usamos um foreach nos valores para evitar percorrer a lista 'atts' com 'nth' 17 vezes por bloco
      (foreach val (cdr atributos)
        (if (and (&amp;lt; i (length atts)) val)
          (vla-put-textstring (nth i atts) (vl-princ-to-string val))
        )
        (setq i (1+ i))
      )
    )
  )
  blk
)&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 03 Mar 2026 23:07:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/autocad-performance-issue-when-inserting-large-number-of-blocks/m-p/14041054#M170315</guid>
      <dc:creator>frjuniornogueira1</dc:creator>
      <dc:date>2026-03-03T23:07:33Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD Performance Issue When Inserting Large Number of Blocks via LISP</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/autocad-performance-issue-when-inserting-large-number-of-blocks/m-p/14042696#M170334</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/18131778"&gt;@frjuniornogueira1&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I got my version to complete in under 2 minutes. Hopefully it works well for you also. See attached lsp file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But, honestly it could be MUCH faster if we could avoid one block with multiple visibilities like&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/524107"&gt;@CADaSchtroumpf&lt;/a&gt;&amp;nbsp;suggested.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;~DD&lt;/P&gt;</description>
      <pubDate>Wed, 04 Mar 2026 20:42:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/autocad-performance-issue-when-inserting-large-number-of-blocks/m-p/14042696#M170334</guid>
      <dc:creator>CodeDing</dc:creator>
      <dc:date>2026-03-04T20:42:36Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD Performance Issue When Inserting Large Number of Blocks via LISP</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/autocad-performance-issue-when-inserting-large-number-of-blocks/m-p/14042747#M170335</link>
      <description>&lt;P&gt;It turned out very well, &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/5680873"&gt;@CodeDing&lt;/a&gt;&amp;nbsp;. In the end, I managed to solve it another way.&lt;/P&gt;&lt;P&gt;What I did was create a &lt;STRONG&gt;“Master Block” (template)&lt;/STRONG&gt; for each visibility state and then use the &lt;STRONG&gt;vla-copy&lt;/STRONG&gt; command. Since the object is already fully configured, copying it is practically instantaneous because AutoCAD doesn’t need to recalculate or reapply the visibility parameters.&lt;/P&gt;&lt;P&gt;With this approach, the total processing time dropped to &lt;STRONG&gt;around three minutes&lt;/STRONG&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Mar 2026 21:17:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/autocad-performance-issue-when-inserting-large-number-of-blocks/m-p/14042747#M170335</guid>
      <dc:creator>frjuniornogueira1</dc:creator>
      <dc:date>2026-03-04T21:17:05Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD Performance Issue When Inserting Large Number of Blocks via LISP</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/autocad-performance-issue-when-inserting-large-number-of-blocks/m-p/14042796#M170336</link>
      <description>&lt;P&gt;While there are 2 replies have been accepted as solution, I think things are quite clear: it is not the code that inserting the block (regardless of that the block definition already exists in the drawing, or the block definition has to be inserted into the drawing from a block dwg file), be the code as LISP/VBA/.NET API..., that causes the performance issue/the slowness. It is DEFINITELY BECAUSE OF the block being dynamic block with properties that could have different property values, especially in your case that the block has visibility parameter with many visibility states. If the drawing contains large number of this type of dynamic block,&amp;nbsp; inserting the block or setting its dynamic property or properties is bound to be really slow. My guess the slowness while setting the dynamic property value (visibility state, in your case) is that AutoCAD does things like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When a dynamic property (visibility state, in your case) is set to a newly inserted block, instead of creating an anonymous block definition, AutoCAD would first search all the anonymous block definition created based on the block definition to found a match. If no match found, then AutoCAD create a new anonymous block definition, than assign the newly inserted block reference to the matched (existing, or newly created) anonymous block definition. The reason for AutoCAD doing this, again, it is my guess, is to try to create anonymous block definition as less as possible, in order to prevent bloated drawing file size, in comparison to always create anonymous block definition every time a dynamic property value is set, even a suitable anonymous block definition already exist.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, the rule of thumb is that that while dynamic block offers great flexibility of block design, one should avoid using large number of block references of the same dynamic block with many property values options for performance reason.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Mar 2026 21:59:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/autocad-performance-issue-when-inserting-large-number-of-blocks/m-p/14042796#M170336</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2026-03-04T21:59:59Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD Performance Issue When Inserting Large Number of Blocks via LISP</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/autocad-performance-issue-when-inserting-large-number-of-blocks/m-p/14044586#M170352</link>
      <description>&lt;P&gt;By taking up the excellent idea of &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/5680873"&gt;@CodeDing&lt;/a&gt;&amp;nbsp;&amp;nbsp;(copy the block), I can offer this version adapted only to your CSV file.&lt;BR /&gt;To do this, the block must be defined in the insertion drawing for a good execution.&lt;BR /&gt;The processing time is equivalent to my first proposal.&lt;/P&gt;&lt;LI-CODE lang="general"&gt;(defun make_blk_u (vis_blk / block val atts)
  (setq block
    (vla-insertblock
      Space
      (vlax-3D-point (trans'(0 0 0) 1 0))
      "PNT_IMPORT"
      1.0 1.0 1.0 0.0
    )
  )
  (vl-some
    '(lambda (x)
      (and
        (= (vla-get-propertyname x) "Visibility1")
        (setq val (vlax-get x 'Value))
        (or
          (vlax-put x 'Value vis_blk)
          t
        )
      )
     )
    (vlax-invoke block 'getdynamicBlockproperties)
  )
  (setq atts (vlax-safearray-&amp;gt;list (vlax-variant-value (vla-getAttributes block))))
  (mapcar
    '(lambda (a v)
      (vla-put-TextString a v)
    )
    atts
    (list "" "" "" "" "" "")
  )
  block
)
(defun import:BlkInsert-Short (nam_blk pt_ins vis_blk info1 info2 info3 info4 info5 info6 / blk_cp val atts)
  (mapcar '(lambda (x y) (if (= vis_blk x) (setq blk_cp (vla-copy (eval (read y)))))) '("PNT" "PNTTR" "PNTCH" "OCULTO") '("blk1" "blk2" "blk3" "blk4"))
  (vla-Move blk_cp (vlax-3D-point (trans'(0 0 0) 1 0)) (vlax-3D-point (trans pt_ins 1 0)))
  (setq atts (vlax-safearray-&amp;gt;list (vlax-variant-value (vla-getAttributes blk_cp))))
  (mapcar
    '(lambda (a v)
      (vla-put-TextString a v)
    )
    atts
    (list info1 info2 info3 info4 info5 info6)
  )
)
(defun get_dyn_property_by_name (dyn_property_name insert_object / dyn_property_found)
  (if (vl-some '(lambda (dyn_property) (= dyn_property_name (vla-get-propertyname (setq dyn_property_found dyn_property))))
          (vlax-invoke insert_object 'getdynamicblockproperties)
    )
    dyn_property_found
    nil
  )
)
(defun set_dyn_property (dyn_property_name value obj / stamp_property)
  (if (setq stamp_property (get_dyn_property_by_name dyn_property_name obj)) 
    (vla-put-value stamp_property value)
  )
)
(defun c:my_demo ( / AcObj AcDoc Space input f_open block first l_read nam_blk visib info1 info2 info3 info4 info5 info6 x_data y_data new_pt blk1 blk2 blk3 blk4)
    (setq
    AcObj (vlax-get-acad-object)
    AcDoc (vla-get-ActiveDocument AcObj)
    Space
    (if (= 1 (getvar "CVPORT"))
      (vla-get-PaperSpace AcDoc)
      (vla-get-ModelSpace AcDoc)
    )
  )
  (setq
    input (getfiled "Select CSV file" "" "csv" 2)
    f_open (open input "r")
  )
  (read-line f_open)
;(command "_.zoom" "_c" '(7651892.1534 209550.3199 0.0000) 31157.4340)
  (mapcar '(lambda (x y) (set (read (strcat "blk" x)) (make_blk_u y))) '("1" "2" "3" "4") '("PNT" "PNTTR" "PNTCH" "OCULTO"))
  (while (setq l_read (read-line f_open))
    (setq
      nam_blk (substr l_read 1 (vl-string-position 59 l_read))
      l_read (substr l_read (+ 2 (vl-string-position 59 l_read)))
      visib (substr l_read 1 (vl-string-position 59 l_read))
      l_read (substr l_read (+ 2 (vl-string-position 59 l_read)))
      info1 (substr l_read 1 (vl-string-position 59 l_read))
      l_read (substr l_read (+ 2 (vl-string-position 59 l_read)))
      info2 (substr l_read 1 (vl-string-position 59 l_read))
      l_read (substr l_read (+ 2 (vl-string-position 59 l_read)))
      info3 (substr l_read 1 (vl-string-position 59 l_read))
      l_read (substr l_read (+ 2 (vl-string-position 59 l_read)))
      info4 (substr l_read 1 (vl-string-position 59 l_read))
      l_read (substr l_read (+ 2 (vl-string-position 59 l_read)))
      info5 (substr l_read 1 (vl-string-position 59 l_read))
      l_read (substr l_read (+ 2 (vl-string-position 59 l_read)))
      info6 (substr l_read 1 (vl-string-position 59 l_read))
      l_read (substr l_read (+ 2 (vl-string-position 59 l_read)))
      x_data (atof (substr l_read 1 (vl-string-position 59 l_read)))
      l_read (substr l_read (+ 2 (vl-string-position 59 l_read)))
      y_data (atof (substr l_read 1 (vl-string-position 59 l_read)))
      new_pt (list x_data y_data 0.0)
    )
    (import:BlkInsert-Short 
      "PNT"
      new_pt
      visib
      info1
      info2
      info3
      info4
      info5
      info6
    )
  )
  (close f_open)
  (mapcar 'vla-delete (mapcar 'eval '(blk1 blk2 blk3 blk4)))
  (prin1)
)&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 05 Mar 2026 22:01:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/autocad-performance-issue-when-inserting-large-number-of-blocks/m-p/14044586#M170352</guid>
      <dc:creator>CADaSchtroumpf</dc:creator>
      <dc:date>2026-03-05T22:01:41Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD Performance Issue When Inserting Large Number of Blocks via LISP</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/autocad-performance-issue-when-inserting-large-number-of-blocks/m-p/14044685#M170357</link>
      <description>&lt;P&gt;Just a comment you can read Excel direct no need to write a CSV, given large row number not sure if it will slow down process.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just read a row here&amp;nbsp;(read-line f_open) (readcell myxl "AX") where X is row number. You can auto get the max row of an Excel via lisp.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Will give it a try when have time.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Mar 2026 00:32:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/autocad-performance-issue-when-inserting-large-number-of-blocks/m-p/14044685#M170357</guid>
      <dc:creator>Sea-Haven</dc:creator>
      <dc:date>2026-03-06T00:32:33Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD Performance Issue When Inserting Large Number of Blocks via LISP</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/autocad-performance-issue-when-inserting-large-number-of-blocks/m-p/14051515#M170429</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/524107"&gt;@CADaSchtroumpf&lt;/a&gt;&amp;nbsp;Not sure if this will improve speed but may be worth trying. Not tested. Using a defun can sometimes speed up things and it is not recalculating l_read.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;(while (setq l_read (read-line f_open))
    (setq
      nam_blk (substr l_read 1 (vl-string-position 59 l_read))
      l_read (substr l_read (+ 2 (vl-string-position 59 l_read)))
      visib (substr l_read 1 (vl-string-position 59 l_read))
      l_read (substr l_read (+ 2 (vl-string-position 59 l_read)))
      info1 (substr l_read 1 (vl-string-position 59 l_read))
      l_read (substr l_read (+ 2 (vl-string-position 59 l_read)))
      info2 (substr l_read 1 (vl-string-position 59 l_read))
      l_read (substr l_read (+ 2 (vl-string-position 59 l_read)))
      info3 (substr l_read 1 (vl-string-position 59 l_read))
      l_read (substr l_read (+ 2 (vl-string-position 59 l_read)))
      info4 (substr l_read 1 (vl-string-position 59 l_read))
      l_read (substr l_read (+ 2 (vl-string-position 59 l_read)))
      info5 (substr l_read 1 (vl-string-position 59 l_read))
      l_read (substr l_read (+ 2 (vl-string-position 59 l_read)))
      info6 (substr l_read 1 (vl-string-position 59 l_read))
      l_read (substr l_read (+ 2 (vl-string-position 59 l_read)))
      x_data (atof (substr l_read 1 (vl-string-position 59 l_read)))
      l_read (substr l_read (+ 2 (vl-string-position 59 l_read)))
      y_data (atof (substr l_read 1 (vl-string-position 59 l_read)))
      new_pt (list x_data y_data 0.0)
    )
    (import:BlkInsert-Short 
      "PNT"
      new_pt
      visib
      info1
      info2
      info3
      info4
      info5
      info6
    )
  )
  (close f_open)

replace with
(while (setq l_read (read-line f_open))
    (setq lst (csv-&amp;gt;lst l_read 59))
    (import:BlkInsert-Short  (nth 0 lst)(list (nth 8 lst)(nth 9 lst))(nth 1 lst)(nth 2 lst)(nth 3 lst)(nth 4 lst)(nth 5 lst)(nth 6 lst)(nth 7 lst))
    )
)
(close f_open)

Put this at start
; thanks to Lee-mac for this defun
(defun csv-&amp;gt;lst (str ans / pos )
(if (setq pos (vl-string-position ans str))
    (cons (substr str 1 pos) (csv-&amp;gt;lst (substr str (+ pos 2)) ans))
    (list str)
    )
)
&lt;/LI-CODE&gt;&lt;P&gt;@c&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Mar 2026 23:41:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/autocad-performance-issue-when-inserting-large-number-of-blocks/m-p/14051515#M170429</guid>
      <dc:creator>Sea-Haven</dc:creator>
      <dc:date>2026-03-11T23:41:04Z</dc:date>
    </item>
  </channel>
</rss>

