Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Generating Tool Image for Block Reference (C# .NET)

Tom_Fuller
Contributor

Generating Tool Image for Block Reference (C# .NET)

Tom_Fuller
Contributor
Contributor

been developing a tool to generate new tool palettes that contain block references. The tool palettes generate and are populated with the block references, however the tool images show as plain white. Is there a way I can generate these images through any available API?Screenshot 2021-04-29 174515.jpg

0 Likes
Reply
1,794 Views
6 Replies
Replies (6)

norman.yuan
Mentor
Mentor

You can use Autodesk.AutoCAD.Internal.Utils.GetBlockImage() method to acquire an image by passing a block definition's ObjectId (not a BlockReference!). The block definition can be from a opened document, or a side database (that is, you do not have to open the drawing into AutoCAD editor in order to do it).

 

See one of my recent articles on this topic:

https://drive-cad-with-code.blogspot.com/2020/12/obtaining-blocks-image.html 

 

 

Norman Yuan

Drive CAD With Code

EESignature

Tom_Fuller
Contributor
Contributor

 oops

0 Likes

Tom_Fuller
Contributor
Contributor

That looks like the sort of thing I'm after! My only concern is how this will affect the attributes of the block. Some of the blocks use the same block definition and have their block attributes modified based on a dynamic property and a block properties table. Because of this, whenever that specific version of the block is added into the drawing, it has an anonymous block... so if I wanted to capture the image with the correct attributes set, would I want to use the AnonymousBlockTableRecord found on the BlockReference object? I've attatched a couple of screenshots showing a 2 of the tools in the palette updated for reference, as well as the information for one of those inserted tools.   4.jpg2.jpg 

0 Likes

norman.yuan
Mentor
Mentor

Yes, you would also need to use the relevant anonymous block definitions in your described case.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes

Tom_Fuller
Contributor
Contributor
Awesome, I'll give it a go now and see how it goes 😊
0 Likes

Tom_Fuller
Contributor
Contributor

Ok, so it worked... kind of.  it produced images, but the attributes didn't show up, or they show up as the attribute names in some cases. This might be because I need to sync the attribute definitions with the attributes references, or the attributes are being clipped by the size of the image (64x64). Is it possible to produce an image with a transparent background? 

0 Likes