Lisp gives duplicated key error while no duplicates are present

Lisp gives duplicated key error while no duplicates are present

DGRL
Advisor Advisor
1,356 Views
2 Replies
Message 1 of 3

Lisp gives duplicated key error while no duplicates are present

DGRL
Advisor
Advisor

Dear forum members

Thanks to @_gile for the time and afford helping me


I added 1 line to add custom props as well but the routine keeps giving back a automation error

; error: Automation Error. Duplicate key

 

 

The list that is use looks like this is only way longer
(("ISO_PIPESPEC" "n.v.t.1" "A" "b") ("ISO_MEDIUM" "n.v.t.2" "A" "b") ("ISO_DESIGN_PRESS" "n.v.t.3" "A" "b"))

The variable that holds the list is vier

 

This is the script I use.
Below script I have more info

 

  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (setq dwgprop (vla-get-summaryinfo(vla-get-activedocument(Vlax-get-acad-object))))
 
  (vla-endundomark doc)
  (vla-startundomark doc)
  ;; iterate the block table
  (vlax-for blk (vla-get-blocks doc)
    (if (= :vlax-false (vla-get-isxref blk))
      (progn
        (vlax-for obj blk
          (if (and (= "AcDbAttributeDefinition" (vla-get-objectname obj))
                   (setq new (assoc (vla-get-tagstring obj) vier))
              )
            (progn
              ;; rename the tag and prompt of the ATTDEF
              ;(vla-put-tagstring obj (cadr new)) ;(princ new)
              ;(vla-put-textstring obj (cadddr new)) ;(princ new)
              ;(vla-put-promptstring obj (caddr new)) ;(princ new)
             ;(vla-addcustominfo obj (cadr new)(cadddr new))
     (vla-addcustominfo dwgprop (cadr new)(cadddr new))
             ;(vla-addcustominfo(vla-get-summaryinfo(vla-get-activedocument(Vlax-get-acad-object)))(cadr new)(cadddr new))
              (setq name (vla-get-Name blk))
            )
          )
        )
        ;; ATTSYNC the inserted references
        (if (= name (vla-get-Name blk))
          (command "_.ATTSYNC" "_Name" name)
        )
      )
    )
  );end vlax-for blk
  (vla-endundomark doc)
  (princ)
 

 

The  TAG / TEXT and PROMPSTRING are working fine

The addcustominfo gives back the error

 

What am I doing wrong here?

 

 

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
1,357 Views
2 Replies
Replies (2)
Message 2 of 3

cadffm
Consultant
Consultant

vla-addcustominfo CREATE a new custominfo

 

If you create "ABC" and you try to create a new custominfo with the same name you get an error,

because customInfo Tag have to unique.

 

What you have to do is:

1. Check if your customInfo still exist,

2. if not existing create a new custominfo -> vla-addcustominfo 

3. if your wanted custimInfo allready exist, change only the value of this custominfo -> vla-setCustomByKey

 

https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2016/ENU/AutoCAD-ActiveX/files...

 

Sebastian

0 Likes
Message 3 of 3

DGRL
Advisor
Advisor

HI @cadffm

 

Thanks for the info will read it

 

I just added this after the end of vlax-for blk and before (vla-endundomark doc) and works perfect

 

(foreach att vier (vla-addcustominfo dwgprop (cadr att)(caddr att)))

 

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes