PDA

View Full Version : Block insertion



jim.vipond
2005-01-27, 09:27 AM
Can anyone help?

I am trying to add a block definition into a drawing but not to insert it. I want the definition to match that of a block already existing on disk which is actually just an attribute. I have studied the online help in AutoCAD (2004) but am having difficulty because it isn't very good.

Thanks in advance.

mtuersley
2005-01-27, 03:13 PM
Think about it, Jim....you could just insert it then immediately delete it. That's probably the easiest, simplest way.

jim.vipond
2005-01-28, 09:15 AM
Yes tried that but because the block is an attribute I couldn't get it to insert with a default attribute value following the Autodesk sample code for inserting blocks. When I inserted the block there was no error given but AutoCAD seemed to be waiting for user input and that bombed the vba script. I also tried putting in extra returns as you would on the command line but this also didn't work. Is there a correct syntax for doing it and if so could someone let me know?

Thanks

office.81897
2005-01-29, 10:05 AM
try inserting the block to some new drawing ...
explode it ...
copy it to taget drawing using ctrl+c -> ctrl+v ...
in target drawing use the AutoCad command ATTREDEF ...

or

use the ATTRIBUTE MANAGER in AutoCad 2002 and above to change the Atttribute right in the existing block

www.plan-net.org

Jeff_M
2005-01-30, 06:43 PM
Does this help you?


Sub blocktest()
Dim oBlkRef As AcadBlockReference
Dim oblk As AcadBlock
Dim oEnt As AcadEntity
Dim oAtt As AcadAttribute
Dim dPt(2) As Double
Dim sName As String

sName = "c:\testblock.dwg"
Set oBlkRef = ThisDrawing.ModelSpace.InsertBlock(dPt, sName, 1#, 1#, 1#, 0#)
sName = oBlkRef.Name
oBlkRef.Delete
Set oblk = ThisDrawing.Blocks.Item(sName)
For Each oEnt In oblk
If TypeOf oEnt Is AcadAttribute Then
Set oAtt = oEnt
oAtt.TextString = "My new default value"
End If
Next
End Sub

jim.vipond
2005-01-31, 09:42 AM
Thanks everyone for your replies so far.

miff
When i have used the InsertBlock method it seems AutoCAD is pausing for user input of the attribute value. What I intended to try is turning off the "attreq" variable before inserting
the block but it will now have to wait for a couple of days before I can get round to it again. I will also try adding a value to the attribute as you have shown to see if this clears the pause.

Thanks again.

ntaylor
2005-01-31, 10:15 PM
Something else is wrong because the VBA InsertBlock method does not prompt for attribute values despite of what the "attreq" variable is set to.
Regards - Nathan