software discussion forum > CAD > Setting and Reading Xrecords
Setting and Reading Xrecords
12-04-2011 09:11 . am | View his/her posts only
I created a dictionary to my application and I'm trying to set Xrecords, but they keep failing. I wonder why?
If I run the subroutine Test it fails to write and retrieve the value. In the debugger it seems that I can't even write the value to the Xrecord but I'm not sure.
Thanks in advance and keep up the good work,
CODE: Module data
______________________________________
' Module contains constant and global variables
' for information exchange.
' Also functions for reading from current drawing
Public Const APPNAME As String = "REMODE"
Public Const VERSION As String = "0.0.1"
'XRecord Types
Private Const TCOUNTER As Integer = 60
Private Const TSTRING As Integer = 1
Private Const TEND As Integer = 70
Private AppDict As ZwcadDictionary
Private CurrentRecord As ZwcadXRecord
Public Function CheckCurrDrwForData() As Boolean
' Check if the current drawing has attached information
' we can use. Specifically the Dictionary named
' APPNAME
' TESTED: OK
On Error Resume Next
Set AppDict = ThisDocument.Dictionaries.Item(APPNAME)
If Err.Number <> 0 Then
Err.Clear
CheckCurrDrwForData = False 'Dictionary does not exist
Else
CheckCurrDrwForData = True
End If
End Function
Public Sub CreateDataOnCurrDrw()
' This sub creates the dictionaries for our use on current
' drawing
' TESTED: OK
If Not CheckCurrDrwForData Then
Set AppDict = ThisDocument.Dictionaries.Add(APPNAME)
End If
End Sub
Public Sub SetCurrentRecord(key As String)
' Check if requested record exists. If it exists
' set variable CurrentRecord to this Xrecord
CreateDataOnCurrDrw
On Error Resume Next
Set CurrentRecord = AppDict.Item(key)
If Err.Number <> 0 Then
Err.Clear
Set CurrentRecord = AppDict.AddXRecord(key)
End If
End Sub
Public Sub SetConcreteColumnCounter(val As Integer)
' This sub saves the calculated value in the drawing
' NO VALIDATION
' TESTS: Not Ok, Don't know if t
Dim Xtyp(1) As Integer
Dim Xval(1) As Variant
Xtyp(0) = TCOUNTER: Xval(0) = val
Xtyp(1) = TEND: Xval(1) = 0
SetCurrentRecord "ConcColCount"
CurrentRecord.SetXRecordData Xtyp, Xval
End Sub
Public Function GetConcreteColumnCounter() As Integer
' This sub saves the calculated value in the drawing
' NO VALIDATION
Dim Xtyp(1) As Integer
Dim Xval(1) As Variant
SetCurrentRecord "ConcColCount"
CurrentRecord.GetXRecordData Xtyp, Xval
GetConcreteColumnCounter = Xval(0)
End Function
____________________________________________
END OF CODE FOR MODULE data
CODE: Module Test
____________________________________________
Sub TestCounterXRecord()
Dim test As Integer
data.SetConcreteColumnCounter 5
test = data.GetConcreteColumnCounter
test = test + 1
data.SetConcreteColumnCounter test
test = data.GetConcreteColumnCounter()
MsgBox "Test value should be 6. It is: " & CStr(test) & vbCrLf
End Sub
____________________________________________
END OF CODE FOR MODULE Test
If I run the subroutine Test it fails to write and retrieve the value. In the debugger it seems that I can't even write the value to the Xrecord but I'm not sure.
Thanks in advance and keep up the good work,
CODE: Module data
______________________________________
' Module contains constant and global variables
' for information exchange.
' Also functions for reading from current drawing
Public Const APPNAME As String = "REMODE"
Public Const VERSION As String = "0.0.1"
'XRecord Types
Private Const TCOUNTER As Integer = 60
Private Const TSTRING As Integer = 1
Private Const TEND As Integer = 70
Private AppDict As ZwcadDictionary
Private CurrentRecord As ZwcadXRecord
Public Function CheckCurrDrwForData() As Boolean
' Check if the current drawing has attached information
' we can use. Specifically the Dictionary named
' APPNAME
' TESTED: OK
On Error Resume Next
Set AppDict = ThisDocument.Dictionaries.Item(APPNAME)
If Err.Number <> 0 Then
Err.Clear
CheckCurrDrwForData = False 'Dictionary does not exist
Else
CheckCurrDrwForData = True
End If
End Function
Public Sub CreateDataOnCurrDrw()
' This sub creates the dictionaries for our use on current
' drawing
' TESTED: OK
If Not CheckCurrDrwForData Then
Set AppDict = ThisDocument.Dictionaries.Add(APPNAME)
End If
End Sub
Public Sub SetCurrentRecord(key As String)
' Check if requested record exists. If it exists
' set variable CurrentRecord to this Xrecord
CreateDataOnCurrDrw
On Error Resume Next
Set CurrentRecord = AppDict.Item(key)
If Err.Number <> 0 Then
Err.Clear
Set CurrentRecord = AppDict.AddXRecord(key)
End If
End Sub
Public Sub SetConcreteColumnCounter(val As Integer)
' This sub saves the calculated value in the drawing
' NO VALIDATION
' TESTS: Not Ok, Don't know if t
Dim Xtyp(1) As Integer
Dim Xval(1) As Variant
Xtyp(0) = TCOUNTER: Xval(0) = val
Xtyp(1) = TEND: Xval(1) = 0
SetCurrentRecord "ConcColCount"
CurrentRecord.SetXRecordData Xtyp, Xval
End Sub
Public Function GetConcreteColumnCounter() As Integer
' This sub saves the calculated value in the drawing
' NO VALIDATION
Dim Xtyp(1) As Integer
Dim Xval(1) As Variant
SetCurrentRecord "ConcColCount"
CurrentRecord.GetXRecordData Xtyp, Xval
GetConcreteColumnCounter = Xval(0)
End Function
____________________________________________
END OF CODE FOR MODULE data
CODE: Module Test
____________________________________________
Sub TestCounterXRecord()
Dim test As Integer
data.SetConcreteColumnCounter 5
test = data.GetConcreteColumnCounter
test = test + 1
data.SetConcreteColumnCounter test
test = data.GetConcreteColumnCounter()
MsgBox "Test value should be 6. It is: " & CStr(test) & vbCrLf
End Sub
____________________________________________
END OF CODE FOR MODULE Test
12-04-2011 09:11 . am | View his/her posts only
Dear costis,
We tested your code both in ZWCAD and AutoCAD, and got the same error result, so it seems to be something wrong with your code itself.
After our analysis, we suggest you Xtyp, which you use to specify data type. Maybe you didn't specify the correct data type that leads to wrong result, please kindly check it through.
We also suggest you refer to SetXrecorddata sample in ZWCAD Developer help.
We tested your code both in ZWCAD and AutoCAD, and got the same error result, so it seems to be something wrong with your code itself.
After our analysis, we suggest you Xtyp, which you use to specify data type. Maybe you didn't specify the correct data type that leads to wrong result, please kindly check it through.
We also suggest you refer to SetXrecorddata sample in ZWCAD Developer help.
12-04-2011 09:11 . am | View his/her posts only
Thanks Daniel, I will test it further.
As for AutoCAD... after migrating to ZWCAD I never looked back! (Well... maybe once...)
As for AutoCAD... after migrating to ZWCAD I never looked back! (Well... maybe once...)



