<?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: Update Custom Property - Duplicate Key Error in Visual LISP, AutoLISP and General Customization Forum</title>
    <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/update-custom-property-duplicate-key-error/m-p/9670363#M71553</link>
    <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/5054769"&gt;@jlaidle1&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why delete the property then create it again? Just set its value.&lt;/P&gt;&lt;P&gt;Here's the 2 functions I use to access my custom dwg props...&lt;/P&gt;&lt;P&gt;I created them so they're similar to the "getpropertyvalue" and&amp;nbsp;"setpropertyvalue" functions..&lt;/P&gt;&lt;PRE&gt;(defun GetCustomDwgProp (key / docProps return num keyVal propVal)
&lt;FONT color="#FF6600"&gt;  ;key - string, representing key value of custom dwgprop to search for
  ;returns string of dwgprop value if found, or nil&lt;/FONT&gt;
  (setq docProps (vla-get-SummaryInfo (vla-get-ActiveDocument (vlax-get-acad-object))))
  (setq return nil num 0)
  (if (and (&amp;gt;= (setq total (vla-NumCustomInfo docProps)) 1)
	   (eq 'STR (type key)))
    (while (and (&amp;lt; num total) (not return))
      (vla-GetCustomByIndex docProps num 'keyVal 'propVal)
      (if (eq (strcase key) (strcase keyVal)) (setq return propVal))
      (setq num (1+ num))
    );while
  );if
  return
);defun

(defun SetCustomDwgProp (key val / docProps return num keyVal propVal)
&lt;FONT color="#FF6600"&gt;  ;key - string, representing key value of custom dwgprop to search for
  ;val - string, representing custom value to be used for the "key" custom dwgprop
  ;returns t if successful, or nil&lt;/FONT&gt;
  (setq docProps (vla-get-SummaryInfo (vla-get-ActiveDocument (vlax-get-acad-object))))
  (setq return nil num 0)
  (if (and (&amp;gt;= (setq total (vla-NumCustomInfo docProps)) 1)
	   (eq 'STR (type key))
	   (eq 'STR (type val)))
    (while (and (&amp;lt; num total) (not return))
      (vla-GetCustomByIndex docProps num 'keyVal 'propVal)
      (if (eq (strcase key) (strcase keyVal))
        (progn
	  (vla-SetCustomByIndex docProps num keyVal val)
	  (setq return t)
        );progn
      );if
      (setq num (1+ num))
    );while
  );if
  return
);defun&lt;/PRE&gt;&lt;P&gt;Hope they help.&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;~DD&lt;/P&gt;</description>
    <pubDate>Mon, 03 Aug 2020 17:28:33 GMT</pubDate>
    <dc:creator>CodeDing</dc:creator>
    <dc:date>2020-08-03T17:28:33Z</dc:date>
    <item>
      <title>Update Custom Property - Duplicate Key Error</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/update-custom-property-duplicate-key-error/m-p/9670275#M71552</link>
      <description>&lt;P&gt;I have the below LISP, but gives a duplicate key error if the property already exists.&lt;/P&gt;
&lt;P&gt;How can I delete this property before updating the value again?&amp;nbsp;&lt;EM&gt; (DWG_Units is created by another LISP routine)&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV style="color: #d4d4d4; background-color: #1e1e1e; font-family: Consolas, 'Courier New', monospace; font-weight: normal; font-size: 14px; line-height: 19px; white-space: pre;"&gt;
&lt;DIV&gt;&lt;SPAN style="color: #d4d4d4;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #569cd6;"&gt;vl-load-com&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN style="color: #d4d4d4;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #569cd6;"&gt;setq&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;acadObject&amp;nbsp;(&lt;/SPAN&gt;&lt;SPAN style="color: #569cd6;"&gt;vlax-get-acad-object&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;))&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN style="color: #d4d4d4;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #569cd6;"&gt;setq&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;acadDocument&amp;nbsp;(&lt;/SPAN&gt;&lt;SPAN style="color: #569cd6;"&gt;vla-get-ActiveDocument&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;acadObject))&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN style="color: #d4d4d4;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #569cd6;"&gt;setq&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;dProps&amp;nbsp;(&lt;/SPAN&gt;&lt;SPAN style="color: #569cd6;"&gt;vlax-get-Property&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;acadDocument&amp;nbsp;'SummaryInfo))&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN style="color: #d4d4d4;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #569cd6;"&gt;vla-delete&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;dProps&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #ce9178;"&gt;"DWG&amp;nbsp;Units"&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN style="color: #d4d4d4;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #569cd6;"&gt;vla-addcustominfo&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;dProps&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #ce9178;"&gt;"DWG&amp;nbsp;Units"&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;DWG_UNITS)&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Aug 2020 16:38:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/update-custom-property-duplicate-key-error/m-p/9670275#M71552</guid>
      <dc:creator>jlaidle1</dc:creator>
      <dc:date>2020-08-03T16:38:45Z</dc:date>
    </item>
    <item>
      <title>Re: Update Custom Property - Duplicate Key Error</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/update-custom-property-duplicate-key-error/m-p/9670363#M71553</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/5054769"&gt;@jlaidle1&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why delete the property then create it again? Just set its value.&lt;/P&gt;&lt;P&gt;Here's the 2 functions I use to access my custom dwg props...&lt;/P&gt;&lt;P&gt;I created them so they're similar to the "getpropertyvalue" and&amp;nbsp;"setpropertyvalue" functions..&lt;/P&gt;&lt;PRE&gt;(defun GetCustomDwgProp (key / docProps return num keyVal propVal)
&lt;FONT color="#FF6600"&gt;  ;key - string, representing key value of custom dwgprop to search for
  ;returns string of dwgprop value if found, or nil&lt;/FONT&gt;
  (setq docProps (vla-get-SummaryInfo (vla-get-ActiveDocument (vlax-get-acad-object))))
  (setq return nil num 0)
  (if (and (&amp;gt;= (setq total (vla-NumCustomInfo docProps)) 1)
	   (eq 'STR (type key)))
    (while (and (&amp;lt; num total) (not return))
      (vla-GetCustomByIndex docProps num 'keyVal 'propVal)
      (if (eq (strcase key) (strcase keyVal)) (setq return propVal))
      (setq num (1+ num))
    );while
  );if
  return
);defun

(defun SetCustomDwgProp (key val / docProps return num keyVal propVal)
&lt;FONT color="#FF6600"&gt;  ;key - string, representing key value of custom dwgprop to search for
  ;val - string, representing custom value to be used for the "key" custom dwgprop
  ;returns t if successful, or nil&lt;/FONT&gt;
  (setq docProps (vla-get-SummaryInfo (vla-get-ActiveDocument (vlax-get-acad-object))))
  (setq return nil num 0)
  (if (and (&amp;gt;= (setq total (vla-NumCustomInfo docProps)) 1)
	   (eq 'STR (type key))
	   (eq 'STR (type val)))
    (while (and (&amp;lt; num total) (not return))
      (vla-GetCustomByIndex docProps num 'keyVal 'propVal)
      (if (eq (strcase key) (strcase keyVal))
        (progn
	  (vla-SetCustomByIndex docProps num keyVal val)
	  (setq return t)
        );progn
      );if
      (setq num (1+ num))
    );while
  );if
  return
);defun&lt;/PRE&gt;&lt;P&gt;Hope they help.&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;~DD&lt;/P&gt;</description>
      <pubDate>Mon, 03 Aug 2020 17:28:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/update-custom-property-duplicate-key-error/m-p/9670363#M71553</guid>
      <dc:creator>CodeDing</dc:creator>
      <dc:date>2020-08-03T17:28:33Z</dc:date>
    </item>
    <item>
      <title>Re: Update Custom Property - Duplicate Key Error</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/update-custom-property-duplicate-key-error/m-p/9670396#M71554</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You do not need to delete the entry.&lt;/P&gt;
&lt;P&gt;Check if it already exists, if so, update the value; else, add a new entry.&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;(setq acadObject (vlax-get-acad-object))
(setq acadDocument (vla-get-ActiveDocument acadObject))
(setq dProps (vla-get-SummaryInfo acadDocument))
(if (vl-catch-all-error-p
      (vl-catch-all-apply 'vla-GetCustomByKey (list dProps "DWG Units" 'value))
    )
  (vla-AddCustomInfo dProps "DWG Units" DWG_UNITS)
  (if (/= DWG_UNITS value)
    (vla-SetCustomByKey dProps "DWG Units" DWG_UNITS)
  )
)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Aug 2020 17:38:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/update-custom-property-duplicate-key-error/m-p/9670396#M71554</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2020-08-03T17:38:07Z</dc:date>
    </item>
  </channel>
</rss>

