我是新编程人员,因此,如果您的回答简单且使用相同的语言,我们将不胜感激。我正在处理更改CAD应用程序发明者的文件名系统。我已经开发了这些简单的代码行,可以使用数据集进行读取和写入,这是一个存储PrefixValues和文件序列的xml文件。
要生成新的数字,我有一个控制所有事件的类,并调用我的其他类和子例程来生成通过引用传递的数字。
[对于所有不同的文件,一切似乎都工作正常,但是,当我处理大量保存时,就像打开三个文件并为每个文件生成数字一样,输出严重复制了我的记录,我不知道我应该怎么做才能避免这个问题。这是代码的一部分。
Public Class NumberGenerator
Dim invPresetsPath As String = g_inventorApplication.FileLocations.PresetsPath
Dim xmlPrefixPath = invPresetsPath & "\" & "xmlPrefixPath.xml"
Dim DatSet As New ConfigDataSet
Sub NonDrawingNumberGen(ByRef NonDrawingNumber As String)
If My.Computer.FileSystem.FileExists(xmlPrefixPath) = True Then
DatSet.ReadXml(xmlPrefixPath)
End If
' First item from Row means the index and Second Item Means the Column 2 is the Non Drawing Number
' ***************************** ASSY AND PART NUMBER READ AND WRITE A NEW NUMBER ***************************
Dim TblNonDrawNumber As Integer = DatSet.Tables("NumberingTable").Rows(My.Settings.PrefixID)(2)
Dim NonDrNumber As String = TblNonDrawNumber.ToString("D7")
NonDrawingNumber = My.Settings.PrefixSet & "-" & NonDrNumber
' Replace the XML File current value Adding a New Value
DatSet.Tables("NumberingTable").Rows(My.Settings.PrefixID)(2) = TblNonDrawNumber + 1
DatSet.WriteXml(xmlPrefixPath)
End Sub
这是主类中的子例程,它调用先前的代码。
Public Sub m_fileUIEvents_OnPopulateFileMetadata(ByVal FileMetadataObjects As Inventor.ObjectsEnumerator, ByVal Formulae As String, ByVal Context As Inventor.NameValueMap, ByRef HandlingCode As Inventor.HandlingCodeEnum) Handles m_FileUIEvents.OnPopulateFileMetadata
For PartMakeComponentsCmd
If Context.Item(1) = "PartMakeComponentsCmd" Or Context.Item(1) = "PartMakePartCmd" Then
'does the verification of the extension
oMetadata = DirectCast(FileMetadataObjects.Item(1), FileMetadata)
CurrentName = oMetadata.FullFileName
FileExtension = Right(CurrentName, 3)
If FileExtension = "iam" Then
oMetadata = DirectCast(FileMetadataObjects.Item(1), FileMetadata)
Dim GenNumber As String
NumbGen.NonDrawingNumberGen(GenNumber)
oMetadata.FullFileName = oPath & GenNumber
oMetadata.DisplayName = GenNumber
oMetadata.TemplateFileName = "Assembly.aim"
oMetadata.DisplayNameOverridden = False
oMetadata.FileNameOverridden = True
HandlingCode = HandlingCodeEnum.kEventHandled
ElseIf FileExtension = "ipt" Then
'This section tries to duplicate the record
For Each oMetadata In FileMetadataObjects
Dim GenNumber As String
NumbGen.NonDrawingNumberGen(GenNumber)
oMetadata.DisplayName = GenNumber
oMetadata.DisplayNameOverridden = True
oMetadata.FileName = oPath & GenNumber
oMetadata.FileNameOverridden = True '*
Next
HandlingCode = HandlingCodeEnum.kEventHandled
End If
'Termination that defines that this only works for PartMakeComponents Command!`
End If
' ******************************** PART MAKE COMPONENTS END ***********************************************
这是我的xml文件的结构。我不知道这是什么tempuri org,但在Visual Basic中是用我的类型数据集创建的。
<?xml version="1.0" standalone="yes"?>
<ConfigDataSet xmlns="http://tempuri.org/ConfigDataSet.xsd">`
<NumberingTable>
<PrefixID>0</PrefixID>
<PrefixValue>61-03</PrefixValue>
<AssyPartCountValue>2</AssyPartCountValue>
<DrawingValue>0</DrawingValue>
<DescriptionValue>Test Record</DescriptionValue>
</NumberingTable>
<NumberingTable>
<PrefixID>1</PrefixID>
<PrefixValue>61-02</PrefixValue>
<AssyPartCountValue>5</AssyPartCountValue>
<DrawingValue>0</DrawingValue>
<DescriptionValue>This is another test description</DescriptionValue>
</NumberingTable>
</ConfigDataSet>
感谢您的帮助。
您的代码简化为几行代码
Module Module1
Const FILENAME = "c:\temp\test.xml"
Sub Main()
Dim ds As New DataSet()
ds.ReadXml(FILENAME)
End Sub
End Module