How to create a text as a block

How to create a text as a block

m09366023695
Enthusiast Enthusiast
484 Views
2 Replies
Message 1 of 3

How to create a text as a block

m09366023695
Enthusiast
Enthusiast

I want to create a text .  sometime user want to delete it with call a function.

I Think the best solution is use block with a name.

 

I create a text with this function:

 

 Set app = GetObject(, "AutoCAD.Application")
app.ActiveDocument.ModelSpace.AddText txt, TextPosition, 120
0 Likes
485 Views
2 Replies
Replies (2)
Message 2 of 3

norman.yuan
Mentor
Mentor

So, you want a way to identify a Text entity, other than the available properties of the Text entity, such as its textual content, its layer, its style, color, position.... Well, making it a block (AcadBlockReference, not AcadBlock, hope you do know the difference between them) is a way, but an odd way: instead of adding a single object (Text entity) to the drawing, now you need to add 3 objects: a block definition (AcadBlock) with unique name, a Text entity in the block definition and a block reference showing the text, and you have to make sure there is only ONE BLOCK REFERENCE to the block in order for using the block name to identify the text making sense. So, the idea isn't good one in most cases.

 

As for creating a block from a text entity (or any type of entity. for that matter, you simply create a n AcadBlock, and then add the entity to it, and finally insert block block;

 

'' Create block definition

Dim blkDef As AcadBlock

Set blkDef=ThisDrawing.Blocks.Add([insPoint], "TheBlockName")

blkDef.AddText "text content", [inspoint], [height]

 

'' Create block reference

ThisDrawing.ModelSpace.InsertBlock "TheBlockName", 1, 1, 1, 0

 

Not know what is your purpose for such an idea, I guess what you actually need could be a block with single attribute, which can be identified by block name, but the "text" (AcadAttributeReference) user sees could have different content.

 

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 3

Ed__Jobe
Mentor
Mentor

 


@m09366023695 wrote:

sometime user want to delete it with call a function.


I agree with @norman.yuan . This is not a good solution. We could provide some suggestions if you explain in more detail why you want to do this. I ask 'why' because sometimes users want to do something unusual because they don't know how to use the features that are already in AutoCAD. For example, you could assign the text to a Group. The group has a name. You could programmatically attach an ID to the text, but that would be a maintenance problem. What if a user forgot to assign a name to the text? What if they didn't turn it into a block like you want? Then, you have to think about how hard it would be to edit something like that. It just creates more work. So the real question is, how can you make their work easier? What is hard about deleting text?

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes