Jump to content

Recommended Posts

Posted

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

Posted (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 by exceed
  • Like 1
Posted

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.

  • Like 1
Posted

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 >_<

2024-04-23 15_55_27-BricsCAD Lite - [sheetnum test.dwg].png

Posted (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 by exceed
  • Like 1
Posted

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.

  • Like 1

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...