I didn't read all the previous post due to time, but this may give me a better perspective by not doing that and just trying to accomplish your goal.
Looks like you want to do this:
Import titleblock information from an old file and have the titleblock filled out in a new file with the same info.
First question:
In the old files, are the block references consistent in the block name & attribute names?
If so..
Then using the Acad object model, define your two Acad documents with variables so they are easy to access. Or as I do lots of times, I create an new autocad instance and make it invisible.
Open & Access the old drawing.
Access the block reference you are after by name
Access the attribute references within it
Store the values of the attributes in an array (or multiple variable)
Close the old drawing.
Access the new drawing.
Access the new block reference
Access the attributes references
Set the values of the attribute references.
(Or set the textboxes of your dialog to have the attribute values if that's what you are doing.)
Finished.
I can write some code for you if you need, doesn't seem that
difficult though.
Good luck.
I did something similar, but here's what I did. I got a list from accounting of all our projects, put it all in an access database and coordinated with IT about linking my database to thier data as it's input for project authorization, created a form in AutoCAD VBA to look up the projects information out of my access DB, that then it fills out my dialog box for the titleblock information. BUT...
Instead of setting attribute values, my standard titleblocks already have attributes with defualt values of fields text that points to these custom drawing properties (DWGPROPS). So my userform, when I press 'OK', it sets these custom drawing properties' values. When ever I pull in a titleblock, any size, as many as I want, they are already filled out. I do also have a feature to actually write the text into the attribute values (fields scare some users apparently) because I named the custom dwg properties (textboxes, comboboxes, etc.) the same as the attribute tags (no spaces hence the underscores) so I can use my array in the program in 2 different ways at the choice of the users.
'~~~~Heres some code for setting DWGPROPS:
'~~~~this is the code behind the button
'~~~~ on the userform to that then
'~~~~calls a function called writefields
Private Sub btnWriteFields_Click()
writeFields
Me.lblProgress.Caption = "Fields have been written to the file."
Me.btnWriteFields.Enabled = False
Me.lbltest.Caption = "1"
End Sub
'~~~writefields function, calls mkListAry function
'~~~also calls custFldAry function & ChgFld function
Private Function writeFields()
Dim chkForErr As Boolean
Dim i As Integer
oldEval = ThisDrawing.GetVariable("FIELDEVAL")
mkListAry
If custFldAry > "" Then On Error GoTo 0
For i = LBound(fldList) To UBound(fldList)
changeFld ThisDrawing, fldList(i, 0), frmDwgProp.Controls(fldList(i, 1)).Value
Next i
ThisDrawing.SetVariable "FIELDEVAL", 31
ThisDrawing.Regen (acActiveViewport)
ThisDrawing.SetVariable "FIELDEVAL", oldEval
Me.lbltest.Caption = "1"
End Function
'~~~
Private Function mkListAry()
'array = Field Name, Control Name (textboxes, etc.)
fldList(0, 0) = "Client_Name1": fldList(0, 1) = "tbClientNameA"
fldList(1, 0) = "Client_Name2": fldList(1, 1) = "tbClientNameB"
fldList(2, 0) = "Client_Address1": fldList(2, 1) = "tbClientAddress"
fldList(3, 0) = "Client_City": fldList(3, 1) = "tbClientCity"
fldList(4, 0) = "Client_State": fldList(4, 1) = "tbClientState"
fldList(5, 0) = "Client_Zip": fldList(5, 1) = "tbClientZip"
fldList(6, 0) = "Project_Name1": fldList(6, 1) = "tbProjectNameA"
fldList(7, 0) = "Project_Name2": fldList(7, 1) = "tbProjectNameB"
fldList(8, 0) = "Project_Address1": fldList(8, 1) = "tbProjectAddress"
fldList(9, 0) = "Project_City": fldList(9, 1) = "tbProjectCity"
fldList(10, 0) = "Project_State": fldList(10, 1) = "tbProjectState"
fldList(11, 0) = "Project_Zip": fldList(11, 1) = "tbProjectZip"
fldList(12, 0) = "UEI_Project_Number": fldList(12, 1) = "tbProjectNumber"
fldList(13, 0) = "Discipline": fldList(13, 1) = "cboDiscipline"
fldList(14, 0) = "Plan_Signer": fldList(14, 1) = "tbPlanSigner"
fldList(15, 0) = "Signature_Date": fldList(15, 1) = "tbSigDate"
fldList(16, 0) = "Lic_or_Reg": fldList(16, 1) = "cboLicReg"
fldList(17, 0) = "Lic-Reg_Number": fldList(17, 1) = "tbLicRegNumber"
fldList(18, 0) = "Start_Date": fldList(18, 1) = "tbDwgStart"
fldList(19, 0) = "Current_Rev_Number": fldList(19, 1) = "tbCurrentRevNum"
fldList(20, 0) = "Drawn_By": fldList(20, 1) = "tbDrawnBy"
fldList(21, 0) = "Checked_By": fldList(21, 1) = "tbCheckedBy"
fldList(22, 0) = "Approved_By": fldList(22, 1) = "tbApprovedBy"
fldList(23, 0) = "Sheet_Count": fldList(23, 1) = "tbSheetCount"
End Function
''''function custFldAry - returns a comma delimted string of
'all the custom field names for the current drawing and thier values
'in that order. It also returns just a field last optionally.
''''function chngFld will change a fields value or alternatively
'create the given field name and set the value if it does not already exist
Function custFldAry(Optional NoVals As Boolean) As String
Dim docInfo As AcadSummaryInfo
Set docInfo = ThisDrawing.SummaryInfo
Dim fName As String
Dim fVal As String
Dim fResult As String
Dim i As Integer
For i = 0 To (docInfo.NumCustomInfo - 1)
docInfo.GetCustomByIndex i, fName, fVal
If justFields = False Then fName = fName & "," & fVal
If i = docInfo.NumCustomInfo - 1 Then
fResult = fResult & "," & fName
Else
If fResult = "" Then
fResult = fName
Else
fResult = fResult & "," & fName
End If
End If
Next i
If Left(fResult, 1) = "," Then fResult = Mid(fResult, 2)
custFldAry = fResult
End Function
Function chngFld(fldName As String, newVal As String)
On Error GoTo bumDeal
Dim custProps As AcadSummaryInfo
Set custProps = ThisDrawing.SummaryInfo
If InStr(1, custFldAry(True), fldName) < 1 Then GoTo createIt
custProps.SetCustomByKey fldName, newVal
Set custProps = Nothing
Exit Function
createIt:
custProps.AddCustomInfo fldName, newVal
Set custProps = Nothing
Exit Function
bumDeal:
Set custProps = Nothing
End Function
'~~~~end code
Hopefully I didn't snip that up too much.
Enjoy & Good Luck.
null