Jef! Posted April 18, 2014 Posted April 18, 2014 Thanks to LM's site I know that the error is caused by "program attempting to use item method of a vla collection object to access an item not present in that collection." 1rst thing: its part of long program (ive manage to find the exact point where I get the error). 2nd thing: all my files are on (the same) stb plot style table 3rd thing: in all files offendinglayerlist is correct (list of all layers that are not on black returned by my dcl ie ("0" "Defpoints" "BOLT"), and so is (layers) (that contains #) 4th thing: in red is the vla function that generate the error (defun ApplyBlackPS ( $offendinglayerlistfromdcl$ / l) (vlax-for l (layers) (if (and (not (equal (vlax-get-property l 'PlotStyleName) "Black"));case sensitive! (member (vla-get-name l) $offendinglayerlistfromdcl$) ) [color=red](vlax-put-property l 'PlotStyleName "Black")[/color] ) ) ) using (applyblackps offendinglayerlist) ... on 1 of my my file (out of 3) it works as intended and change the plot style to Black. On other 2 (out of 3) files, I get "; error: Automation Error. Key not found" Maybe I have to "refresh" the properties? I tried to seek out without finding. I inspected the dxf lists of the layers in all files, there was no differences. I'm clueless and could use some guidance. Thanks. edit: if I manually change the plot style table and put it on anything else than black, the result is the same for the faulty files. BUT if I change it manually to black, then to something else, then it works as intended... so I'd have to "programmatically refresh" the properties of the the layers? how? Quote
Jef! Posted April 21, 2014 Author Posted April 21, 2014 I found the reason why the vlax-put-property fails, but I'm not sure what I did wrong to achieve the result I get. Lemme explain the big lines. I programmatically convert from ctb to stb, then I apply our standard.stb file to every layouts. The thing is, after doing that, on the "faulty files", even if "black" plot style is available in the layer properties manager, I found out that the plotstylename dictionary is not up to date. (dictsearch (namedobjdict) "ACAD_PLOTSTYLENAME") (... (281 . 1) (3 . "Normal") (350 . <Entity name: 7ffffb118f0>) (3 . "Style_1") (350 . <Entity name: 7ffffb13080>) (100 . "AcDbDictionaryWithDefault") (340 . <Entity name: 7ffffb118f0>)) If I go change any layer plot style to black into the layer properties manager, then look into the dictionary, it is still not totally up to date but black have been added. (dictsearch (namedobjdict) "ACAD_PLOTSTYLENAME") (... (281 . 1) (3 . "Black") (350 . <Entity name: 7ffffb13200>) (3 . "Normal") (350 . <Entity name: 7ffffb118f0>) (3 . "Style_1") (350 . <Entity name: 7ffffb13080>) (100 . "AcDbDictionaryWithDefault") (340 . <Entity name: 7ffffb118f0>)) So, the dictionary need to be updated somehow... and my feeling tells me that if I try to manually update a dictionary, it can (will) lead to a disaster. I'll do what I'll have to do, but I'd prefer to avoid walking into a mine field.. =) What are my options? More than ever, comments, suggestions and advices are more than welcome. Quote
Jef! Posted April 22, 2014 Author Posted April 22, 2014 Even if I got no replies, since I got more than a hundred views I think some might be interested to know the workaround I found.. I used an if statement in my action tiles. If black is in the dictionary, I process as originally designed. If black is not in the dictionary, instead of feeding the list of layers to process to the function that change them to black, I store the list into a forceblackintodictflag variable. I then close the dialog. After unloading the dialog, if the variable exists I transfer it to another function: (if (not(null forceblackintodictflag)) (forceblackintodict forceblackintodictflag) ) and that function... (defun forceblackintodict (forceblackintodictflag / activelayer prevpsname) (setq activelayer (vla-get-ActiveLayer (vla-get-ActiveDocument (vlax-get-acad-object)))) (setq prevpsname (vlax-get-property activelayer 'PlotStyleName)) (command "_-layer" "PStyle" "Black" "" "") (command "_-layer" "PStyle" prevpsname "" "") (ApplyBlackPS forceblackintodictflag) (setq forceblackintodictflag nil) (watch) ) I'm not 100% sure where the available plot styles are retrieve in the "?" of the -layer command, but like in the layer properties manager, every plot style of a table are listed (even if not in the dictionary). Changing he active layer to black then changing it back add the entry in the dictionary. After that, I forward the list to the ApplyBlackPS function and voila! I don't use many commands in lisp nowadays but on that one I did not find any other way of achieving what I needed using only lisp/vlisp/activeX.... (yet). Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.