CAD/CAM discussion forum > CAD Tutorial & Tips > ZW CAD vb.net sample code: add and obtain XData expanded data

ZW CAD vb.net sample code: add and obtain XData expanded data

Rank: 5Rank: 5

Viola

posts: 10

Registered: 2013-7-12

Message 1 of 1

 ZW CAD vb.net sample code: add and obtain XData expanded data
30-07-2013 04:39 . pm | View his/her posts only
ZWCAD+ vb.net sample code: add and obtain XData expanded data.
vb.net sample codes:



Imports ZwSoft.ZwCAD.Runtime
Imports ZwSoft.ZwCAD.ApplicationServices
Imports ZwSoft.ZwCAD.DatabaseServices
Imports ZwSoft.ZwCAD.EditorInput
Imports ZwSoft.ZwCAD.Geometry

Public Class ZwcadApps
_
Public Sub SetXData()
Dim ZcDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim ZcDB As Database = ZcDoc.Database
Dim ZcEd As Editor = ZcDoc.Editor

Dim peo As New PromptEntityOptions(vbLf & "Select object:")
Dim per As PromptEntityResult = ZcEd.GetEntity(peo)
If per.Status = PromptStatus.OK Then
Dim ZwcadAppsName As String = ""
Do
Dim pStrOpts As PromptStringOptions = New PromptStringOptions(vbLf & "Enter application name:")
pStrOpts.AllowSpaces = False
Dim pStrRes As PromptResult = ZcDoc.Editor.GetString(pStrOpts)
If pStrRes.Status <> PromptStatus.OK Then
Return
End If
ZwcadAppsName = pStrRes.StringResult
Loop While ZwcadAppsName = ""
Using ZcTran As Transaction = ZcDB.TransactionManager.StartTransaction()
Dim Ent As Entity = ZcTran.GetObject(per.ObjectId, OpenMode.ForWrite)
Dim regTable As RegAppTable = ZcTran.GetObject(ZcDB.RegAppTableId, OpenMode.ForWrite)
If Not regTable.Has(ZwcadAppsName) Then
Dim regTableRec As New RegAppTableRecord()
regTableRec.Name = ZwcadAppsName
regTable.Add(regTableRec)
ZcTran.AddNewlyCreatedDBObject(regTableRec, True)
Ent.XData = New ResultBuffer(New TypedValue(1001, ZwcadAppsName), New TypedValue(1000, "This is a test for xdata."), New TypedValue(1003, "0"))
Else
ZcEd.WriteMessage(vbLf & "Duplicate RegAppTable!")
Exit Sub
End If
ZcTran.Commit()
End Using
ZcEd.WriteMessage(vbLf & "SetXData was done!")
Else
Return
End If
End Sub

_
Public Sub GetXData()
Dim ZcDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim ZcDB As Database = ZcDoc.Database
Dim ZcEd As Editor = ZcDoc.Editor

Dim peo As New PromptEntityOptions(vbLf & "Select object:")
Dim per As PromptEntityResult = ZcEd.GetEntity(peo)
If per.Status = PromptStatus.OK Then
Using ZcTran As Transaction = ZcDB.TransactionManager.StartTransaction()
Dim Ent As Entity = ZcTran.GetObject(per.ObjectId, OpenMode.ForRead)
Dim resBuf As ResultBuffer = Ent.XData()
If resBuf Is Nothing Then
ZcEd.WriteMessage("The object does not contain XData!")
Else
Dim IEnum As IEnumerator = resBuf.GetEnumerator
Do While IEnum.MoveNext
Dim tmpVal As TypedValue = CType(IEnum.Current, TypedValue)
Dim vString As String
Select Case tmpVal.TypeCode
Case 1000
vString = "Test string:"
Case 1001
vString = "Application name:"
Case 1003
vString = "Test layer:"
End Select
ZcEd.WriteMessage(vbLf & vString & tmpVal.Value.ToString)
Loop
ZcTran.Commit()
End If
End Using
Else
Return
End If
End Sub

End Class





Try ZWCAD+ free for 30 days:
http://www.zwsoft.com/zwcad+/
See also