cagorskij Posted April 23 Share Posted April 23 Hi, I'm sort of stumped on how to retrieve an object ID from a block so I can create a tool that allows a user to click on a block to create a field referencing an object within that block. Specifically, click on the border of a sheet (which is a block containing other objects like scale, paper size, sheet number) and then place a field of the sheet number. I'm able to create a tool that clicks directly on the sheet number, but when trying to create something that clicks anywhere on the block, I was unable to get that working. I thought this would work as under the properties of the block reference, SHEETNUM appears under a subheading Attributes, but it seems (vlax-invoke-method blk 'GetAttributes) just returns #<variant 8201 ...> So maybe I'm going about this the complete incorrect way. I have no idea and just assumed something like the code below would work to get me something from which I'd be able to further retrieve the object im actually looking for. (vlax-ename->vla-object (car (entsel "\nSelect SHEET"))) I've attached a dwg with the block reference that I'm trying to extract info to create a field from. Thanks for any help. sheetnum test.dwg Quote Link to comment Share on other sites More sharing options...
exceed Posted April 23 Share Posted April 23 (edited) you can get list of attributes by add these 2 words (vlax-safearray->list (vlax-variant-value ~~~~~~~)) like this (vlax-safearray->list (vlax-variant-value (vlax-invoke-method (vlax-ename->vla-object (car (entsel "\nSelect SHEET"))) 'GetAttributes))) and dump it first one like this (vlax-dump-object (car (vlax-safearray->list (vlax-variant-value (vlax-invoke-method (vlax-ename->vla-object (car (entsel "\nSelect SHEET"))) 'GetAttributes))))) Edited April 23 by exceed 1 Quote Link to comment Share on other sites More sharing options...
Jonathan Handojo Posted April 23 Share Posted April 23 The other way you can do it is by using nentselp. This allows you to access any entity within that block, no matter how nested they are. The catch is, you will need to click on the exact object within that block that you want to extract. 1 Quote Link to comment Share on other sites More sharing options...
cagorskij Posted April 23 Author Share Posted April 23 I think my confusion is that the object is listed as an attribute in the properties window, but is not actually an attribute at all. Maybe it's a tagstring? I can see TagString = "SHEETSIZE" when using the dump, but cannot see any of the other listed values such as SHEETNUM or SHEETSCALE? I'm not really familiar with how block references work >_< Quote Link to comment Share on other sites More sharing options...
exceed Posted April 23 Share Posted April 23 (edited) 43 minutes ago, cagorskij said: I think my confusion is that the object is listed as an attribute in the properties window, but is not actually an attribute at all. Maybe it's a tagstring? I can see TagString = "SHEETSIZE" when using the dump, but cannot see any of the other listed values such as SHEETNUM or SHEETSCALE? I'm not really familiar with how block references work >_< because it's (car) https://help.autodesk.com/view/ACDLT/2024/ENU/?guid=GUID-2DD1AF33-415C-4C1A-9631-DA958134C53A get first one for the sample. you want to loop all attribute , like this below (repeat (length (setq alist (vlax-safearray->list (vlax-variant-value (vlax-invoke-method (vlax-ename->vla-object (car (entsel "\nSelect SHEET"))) 'GetAttributes))))) (setq 1a (car alist)) (princ (strcat "\n" (vlax-get-property 1a 'tagstring) " - " (vlax-get-property 1a 'textstring))) (setq alist (cdr alist)))(princ) you can paste this 1 line to the command prompt. and can test it. Edited April 23 by exceed 1 Quote Link to comment Share on other sites More sharing options...
BIGAL Posted April 23 Share Posted April 23 Another example (defun wow ( / obj atts att) (setq obj (vlax-ename->vla-object (car (entsel "\nSelect a block object ")))) (setq atts (vlax-invoke obj 'Getattributes)) (foreach att atts (princ (strcat "\nTag name " (vlax-get att 'Tagstring) " Att value " (vlax-get att 'Textstring) )) ) (princ) ) (wow) If you know a tag string you can check for a single attribute. 1 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.