InsertBlock Method

InsertBlock Method

Anonymous
Not applicable
463 Views
2 Replies
Message 1 of 3

InsertBlock Method

Anonymous
Not applicable
Hi Group, VB6. I am using AutoCAD's Getpoint method to obtain a user selected point and then the InsertBlock method to insert a block into my drawing. If the block has attributes, I would like to display the Edit Attributes dialog box. Here is the problem that I am facing. For one thing, the only way I see to display AutoCAD's Edit Attributes dialog is via a SendCommand "DDATTE" to the ActiveDocument. This in itself is not a problem but DDATTE command expects the user to pick an attributed block from the screen (similar to lisp entsel). DDATTE accepts "last" as a valid choice and this works reliably most of the time. Note however that it can be unreliable since it is possible that the resulting block geometry may be outside the drawing display. In this case, the "last" object is not the object that I am interested in. I half expect a blockref object to have a method like say, Blockref.Attedit with an argument which would serve to signify whether a dialog box or command line interface is desired. Since I don't see this, my alternative is to create my own "Edit Attributes" dialog. Am I missing something? Regards, Ken Hutson San Antonio, TX
0 Likes
464 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
since you're resigned to using send command, can you not pass the entity name of the just created block to the command? Insertblock returns the blockobject convert that to ename then (command"Ddatte")(command ename) You could probably create your own attribute editor that works better than acads though, and dispense with sendcommand if you wanted... just a thought Mark "Ken Hutson" wrote in message news:40844dbe$1_1@newsprd01... > Hi Group,
0 Likes
Message 3 of 3

Anonymous
Not applicable
I prompt at the commandline for the attributes. Here is the code I use with the relevant section highlighted.
----------
Option Explicit

Public Sub Insert()
Dim strBlock As String
Dim blnRotate As Boolean
Dim blnSDP As Boolean
Dim blnText As Boolean
Dim varInsPt As Variant
Dim objBlockRef As AcadBlockReference
Dim objBlock As AcadBlock
Dim objEnt1 As AcadEntity
Dim varAttribRef As Variant
Dim objEnt(0) As AcadEntity
Dim dblScale As Double
Dim dblRotation As Double
Dim strHandle As String
Dim strAttValue As String
Dim objSSet As AcadSelectionSet
strBlock = GetSetting("AUTOMAP", "Block", "Name")
blnRotate = CBool(GetSetting("AUTOMAP", "Block", "Rotate"))
blnSDP = CBool(GetSetting("AUTOMAP", "Block", "SDP"))
blnText = CBool(GetSetting("AUTOMAP", "Block", "Text"))
Call Setlay.Setlay
On Error GoTo Errorhandler
varInsPt = ThisDrawing.Utility.GetPoint(, "Pick Insertion Point:")
On Error GoTo 0
Select Case UCase(ThisDrawing.GetVariable("MENUNAME"))
Case "Z:\RAA_UTIL04\MENUS\REGIONAL"
strBlock = "Z:\RAA_UTIL04\SYMBOLS\REGIONAL\" & strBlock & ".dwg"
Case "Z:\RAA_UTIL04\MENUS\STRIP"
strBlock = "Z:\RAA_UTIL04\SYMBOLS\STRIPMAP\" & strBlock & ".dwg"
End Select
dblScale = ThisDrawing.GetVariable("USERR1")
If blnRotate = True Then
dblRotation = ThisDrawing.Utility.GetAngle(varInsPt, "Pick Rotation Angle:")
Else
dblRotation = 0
End If
Set objBlockRef = ThisDrawing.ModelSpace.InsertBlock(varInsPt, strBlock, dblScale, dblScale, dblScale, dblRotation)
Set objSSet = CreateSSet.CreateSSet(False, 2, objBlockRef.Name)
For Each objEnt1 In objSSet
objEnt1.Update
Next objEnt1
objSSet.Delete
'**********Prompt for attributes
Set objBlock = ThisDrawing.Blocks.Item(objBlockRef.Name)
For Each objEnt1 In objBlock
If TypeOf objEnt1 Is AcadAttribute Then
For Each varAttribRef In objBlockRef.GetAttributes
If varAttribRef.TagString = objEnt1.TagString Then
If varAttribRef.TextString = "" Then
On Error GoTo ErrorHandler1
strAttValue = ThisDrawing.Utility.GetString(True, objEnt1.PromptString)
On Error GoTo 0
varAttribRef.TextString = strAttValue
Else
On Error GoTo ErrorHandler1
strAttValue = ThisDrawing.Utility.GetString(True, objEnt1.PromptString & "<" & varAttribRef.TextString & ">")
On Error GoTo 0
If strAttValue <> "" Then varAttribRef.TextString = strAttValue
End If
End If
Next varAttribRef
End If
Next objEnt1
'**********
If blnSDP = True Then
If blnText = True Then
strHandle = objBlockRef.Handle
SaveSetting "AUTOMAP", "Block", "Handle", strHandle
Call Ntext.Create(True)
Else
Set objSSet = CreateSSet.CreateEmptySSet
Set objEnt(0) = objBlockRef
objSSet.AddItems objEnt
Call SDP.SDPxdata(objSSet)
objSSet.Delete
End If
Else
If blnText = True Then
Call Ntext.Create(False)
End If
End If
Exit Sub
Errorhandler:
Resume
ErrorHandler1:
strAttValue = "Error Retrieving Attribute Value"
Resume Next
End Sub
----------
Regards - Nathan
0 Likes