Lee Mac Posted June 1, 2009 Share Posted June 1, 2009 A lot of questions all come at once it seems... I am not entirely confident in using this function, but I want to master it. Currently, when extracting an item from a collection, I am using vlax-for to cycle through the collection, and using some kind of conditional within the loop to get the required object, like: (vlax-for lay (vla-get-layers (vla-get-ActiveDocument (vlax-get-acad-object))) (if (eq "LayerName" (vla-get-Name lay)) (setq layer lay))) But is there a way to get at this item directly? I thought perhaps vla-item, but I may be mistaken. Quote Link to comment Share on other sites More sharing options...
ronjonp Posted June 1, 2009 Share Posted June 1, 2009 I think you answered your own question . Personally I'd use the tblobjname approach like so: (defun getlayer (name / olyr) (if (and (setq olyr (tblobjname "layer" name)) (setq olyr (vlax-ename->vla-object olyr)) ) olyr ) ) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 1, 2009 Author Share Posted June 1, 2009 I think you answered your own question . Personally I'd use the tblobjname approach like so: (defun getlayer (name / olyr) (if (and (setq olyr (tblobjname "layer" name)) (setq olyr (vlax-ename->vla-object olyr)) ) olyr ) ) I suppose that is "cleaner", but I am still intrigued by this "vla-item", how is it used? Quote Link to comment Share on other sites More sharing options...
ronjonp Posted June 1, 2009 Share Posted June 1, 2009 You want something like this Lee? (vla-item (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) "0" ) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 1, 2009 Author Share Posted June 1, 2009 You want something like this Lee? (vla-item (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) "0" ) Ahh, I see thanks Ron - you have been a great help. I read the article in the ACAD help on VLA-Item, and it mentions the index location of the object in the collection - which I did not know how to specify. But you have demonstrated that specifying the layer name will pull it out too. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 1, 2009 Author Share Posted June 1, 2009 Thanks for your help - this is really useful, just experimenting, you can cycle through block sub-entities pretty quick: (defun test (/ lst) (vlax-for Obj (vla-item (vla-get-blocks (vla-get-ActiveDocument (vlax-get-acad-object))) "blockname") (setq lst (cons Obj lst))) lst) Cheers Ron Lee Quote Link to comment Share on other sites More sharing options...
ronjonp Posted June 1, 2009 Share Posted June 1, 2009 Glad to help . Quote Link to comment Share on other sites More sharing options...
DineshPawar Posted March 22, 2018 Share Posted March 22, 2018 (edited) Thanks for your help - this is really useful, just experimenting, you can cycle through block sub-entities pretty quick: (defun test (/ lst) (vlax-for Obj (vla-item (vla-get-blocks (vla-get-ActiveDocument (vlax-get-acad-object))) "blockname") (setq lst (cons Obj lst))) lst) Cheers Ron Lee Can this code work for ObjectDBX method I tried on your ObjectDBX Wrapper function as below but it show error. code is as below (defun LM:DBXAttChange ( dwg lst BlkName / doc flg val ) (if (setq doc (LM:GetDocumentObject dwg)) (progn (get-item (vla-get-block (vla-get-modelspace doc)) blkname) (vlax-for lyt (vla-get-layouts doc) (vlax-for (vla-item obj (vla-get-block lyt) blkname) (if (and (= "AcDbBlockReference" (vla-get-objectname obj)) (= :vlax-true (vla-get-hasattributes obj)) ).................................. Edited March 23, 2018 by SLW210 Added Code Tags Quote Link to comment Share on other sites More sharing options...
zixuan203344 Posted March 22, 2018 Share Posted March 22, 2018 When you use vla-item, you need to specify the name of the specific element Quote Link to comment Share on other sites More sharing options...
Roy_043 Posted March 22, 2018 Share Posted March 22, 2018 @DineshPawar: You need to get better acquainted with the object model. (defun Test (dwg blkName / doc) (setq blkName (strcase blkName)) (if (setq doc (LM:GetDocumentObject dwg)) (vlax-for lyt (vla-get-layouts doc) (vlax-for obj (vla-get-block lyt) (if (and (= "AcDbBlockReference" (vla-get-objectname obj)) (= blkName (strcase (vla-get-effectivename obj))) (= :vlax-true (vla-get-hasattributes obj)) ) (progn ... ) ) ) ) ) ) Quote Link to comment Share on other sites More sharing options...
DineshPawar Posted March 23, 2018 Share Posted March 23, 2018 @Roy_143, @zixuan203344 Thank you for your help I am tring to implement your suggestion in my code. Quote Link to comment Share on other sites More sharing options...
SLW210 Posted March 23, 2018 Share Posted March 23, 2018 In the future, please read the Code Posting Guidelines and have your Code to be included in Code Tags.[NOPARSE] Your Code Here[/NOPARSE] = Your Code Here Quote Link to comment Share on other sites More sharing options...
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.