Problem whit xRecord

Discussion in 'AutoCAD' started by fazzini, May 10, 2004.

  1. fazzini

    fazzini Guest

    I've make a function for stored the Xrecord in a drawing.
    I have follow the guide and i make a routine which stored
    many data conteins in four textbox in the drawing for a next use.
    But don't work.
    My wrong routine:


    Public Sub VariabiliTabelle()
    Dim Dic As AcadDictionary
    Dim xRec As AcadXRecord

    Dim xRecordType(0 To 4) As Integer
    Dim xRecordData(0 To 4) As Variant

    Dim Data As String

    'If dictionaries don't exists make him
    On Error GoTo Create
    Set Dic = ThisDrawing.Dictionaries("Tab") 'make current the dictionaries "Tab"
    Set xRec = Dic.GetObject("TabRec") 'make current the xrecord "TabRec"
    On Error GoTo 0

    'Ditta blocco
    xRecordType(0) = 300 'Is this the DXf code for text???
    xRecordData(0) = FormInserimentoTabelle.DittaBlocco 'My TextBox which conteins the value

    'Codice prototipo
    xRecordType(1) = 300
    xRecordData(1) = FormInserimentoTabelle.CodPrototipo

    'Codice progetto
    xRecordType(2) = 300
    xRecordData(2) = FormInserimentoTabelle.CodProgetto

    'Commessa
    xRecordType(3) = 300
    xRecordData(3) = FormInserimentoTabelle.Com

    'Tag operatore
    xRecordType(4) = 300
    xRecordData(4) = FormInserimentoTabelle.TagOperatore

    'Fix the value
    xRec.SetXRecordData xRecordType, xRecordData

    Data=xRecordData(4) 'Stored the value of my xRecord in a string var

    Exit Sub

    Create:
    If Dic Is Nothing Then
    Set Dic = ThisDrawing.Dictionaries.Add("Tab") 'Crea il dizionario nel caso non ci sia
    Set xRec = Dic.AddXRecord("TabRec") 'Crea l'xRecord nel dizionario
    End If
    Resume

    End Sub

    I'm new whit xRecord and the value is not save in the document object for next use.
    Where is my error?
    Thx for help and sorry for my english.
     
    fazzini, May 10, 2004
    #1
  2. fazzini

    tp Guest

    I use this macro. I hope it to be useful to you.

    ' ===== Main Module =====

    Public glbProjectScale As Double
    Public glbProjectUnits As Double
    Public glbProjectName As String

    ' Append current settings
    Function SetDwgSettings()
    Dim Dictionary As AcadDictionary
    Dim XRecord As AcadXRecord
    Dim XType As Variant
    Dim XData As Variant
    ReDim XType(0 To 2) As Integer
    ReDim XData(0 To 2) As Variant
    Const TP_DIC_NAME = "TpDicSettings"
    Const TP_REC_NAME = "TpRecSettings"
    On Error Resume Next
    Set Dictionary = ThisDrawing.Dictionaries(TP_DIC_NAME)
    On Error GoTo 0
    If Dictionary Is Nothing Then
    Set Dictionary = ThisDrawing.Dictionaries.Add(TP_DIC_NAME)
    Set XRecord = Dictionary.AddXRecord(TP_REC_NAME)
    ' Append Default XRecord Data
    XType(0) = 1: XData(0) = "#0"
    XType(1) = 2: XData(1) = "#0"
    XType(2) = 3: XData(2) = ""
    XRecord.SetXRecordData XType, XData
    End If
    Set XRecord = Dictionary.GetObject(TP_REC_NAME)
    XType(0) = 1: XData(0) = modStrings.MaskNumber(glbProjectScale)
    XType(1) = 2: XData(1) = modStrings.MaskNumber(glbProjectUnits)
    XType(2) = 3: XData(2) = glbProjectName
    ' Append new XRecord Data
    XRecord.SetXRecordData XType, XData
    End Function

    ' Retrieve stored settings
    Function GetDwgSettings()
    Dim Dictionary As AcadDictionary
    Dim XRecord As AcadXRecord
    Dim Counter As Long
    Dim XType As Variant
    Dim XData As Variant
    ReDim XType(0 To 2) As Integer
    ReDim XData(0 To 2) As Variant
    Const TP_DIC_NAME = "TpDicSettings"
    Const TP_REC_NAME = "TpRecSettings"
    On Error Resume Next
    Set Dictionary = ThisDrawing.Dictionaries(TP_DIC_NAME)
    On Error GoTo 0
    If Dictionary Is Nothing Then
    Set Dictionary = ThisDrawing.Dictionaries.Add(TP_DIC_NAME)
    Set XRecord = Dictionary.AddXRecord(TP_REC_NAME)
    ' Append Default XRecord Data
    XType(0) = 1: XData(0) = "#0"
    XType(1) = 2: XData(1) = "#0"
    XType(2) = 3: XData(2) = ""
    XRecord.SetXRecordData XType, XData
    End If
    Set XRecord = Dictionary.GetObject(TP_REC_NAME)
    ' Get current XRecordData
    XRecord.GetXRecordData XType, XData
    ' Retrieve stored XRecordData
    glbProjectScale = modStrings.UnmaskNumber(XData(0)) ' Scale
    glbProjectUnits = modStrings.UnmaskNumber(XData(1)) ' Units
    glbProjectName = XData(2) ' Project Name
    End Function

    ' ===== ModStrings Module =====

    Function MaskNumber(ByVal num As Variant) As Variant
    If VarType(num) = vbString Then
    MaskNumber = num
    Else
    MaskNumber = "#" & Replace(CStr(num), modStrings.DecimalSeparator, "|")
    End If
    End Function

    Function UnmaskNumber(ByVal varVal As Variant) As Variant
    Dim retVal
    If VarType(varVal) = vbString Then
    If Left$(varVal, 1) = "#" Then
    retVal = Replace(Mid$(varVal, 2), "|", modStrings.DecimalSeparator)
    If IsNumeric(retVal) Then
    varVal = Val(retVal)
    End If
    End If
    End If
    UnmaskNumber = varVal
    End Function

    Function DecimalSeparator() As String
    Static Separador As String
    If Separador = "" Then Separador = Mid$(Format$(0#, "0.0"), 2, 1)
    DecimalSeparator = Separador
    End Function
     
    tp, May 22, 2004
    #2
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.