Jump to content

VBA Inserting text inside a just inserted block


jakebullet70

Recommended Posts

Hi all! (using Acad 2007)

 

Ok - I am inserting a block into a existing drawing. The block is basically a line with a 'X x' placeholder. Now each 'X x' is suppose to get replaced with text to show inches and a fraction. How do I do that? I have already calc'd the inches and fraction so that is not a problem, its just how to replace the 'X x' with the text

 

I am new to Autocad and just learning about layers. In fact the blocks get inserted on there own layers.

 

Thanks again for all the help!!!

 

Steve AKA: confusion is my middle name

Link to comment
Share on other sites

I take you know the values in vba program so adding the attributes is something like this

txtx1 = CStr(FormatNumber(pt1(0), 3))
TXTY1 = CStr(FormatNumber(pt1(1), 3))

attribs(1).TextString = txtx1
attribs(2).TextString = TXTY1

attribs(1).Update
attribs(2).Update

 

i am sure if you search here you will find an example of inserting a block with attributes Did you check the Autocad tutorials on your PC I would have thought that it would be there.

Link to comment
Share on other sites

OK - still having fun (read problems) with this...

 

When I insert my block it inserts fine. I use:

Set oJustInsertedBlock = ThisDrawing.ModelSpace.InsertBlock((insertionPnt, blockpath, 1#, 1#, 1#, rotateAngle)

This returns a block reference just fine.

 

I then do:

 

vAttr = oJustInsertedBlock.GetAttributes

But this is returning a blank...

So I did a check with

 

Debug.Print oJustInsertedBlock.HasAttributes

This came up false to that tells me why GetAttributes is failing.

 

I then loaded the inserted block by itself and did a Attribute Extraction and sure enough, there is one attribute and its the one I want. I see the X x text that I need to replace and the name of it. Don't know why I can't see it though after I insert it...

 

Help... :cry:

Link to comment
Share on other sites

WOW...

Ok here it is... :) Found this on the web

 

'You're not inserting a block here, you're inserting a drawing

which consists of a block reference with attributes. Once you

do this the inserted drawing becomes a block in the parent

drawing.'

 

so...

For Each ent In ThisDrawing.Blocks.Item(blkRef.Name)
     If TypeOf ent Is AcadBlockReference Then
          Set blkRef2 = ent
          If blkRef2.HasAttributes Then
        MsgBox "bingo"
     End If
  End If
 Next ent

 

I ran this as a test and yep! I found my attribute!

Link to comment
Share on other sites

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