CAD/CAM discussion forum > CAD Tutorial & Tips > ZW CAD vb.net sample code: edit offset entity

ZW CAD vb.net sample code: edit offset entity

Rank: 5Rank: 5

Viola

posts: 10

Registered: 2013-7-12

Message 1 of 1

 ZW CAD vb.net sample code: edit offset entity
30-07-2013 04:29 . pm | View his/her posts only
ZWCAD+ vb.net sample code: edit offset entity.

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 OffsetObject()
Dim ZcDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim ZcDB As Database = ZcDoc.Database
Dim ZcEd As Editor = ZcDoc.Editor
Using ZcTran As Transaction = ZcDB.TransactionManager.StartTransaction()
Dim Ent As Curve
Do
Dim peo As New PromptEntityOptions(vbLf & "Select object:")
peo.SetRejectMessage(vbLf & "Must be curve.")
peo.AddAllowedClass(GetType(Curve), True)

Dim per As PromptEntityResult = ZcEd.GetEntity(peo)
If per.Status <> PromptStatus.OK Then
Return
End If

Ent = DirectCast(ZcTran.GetObject(per.ObjectId, OpenMode.ForWrite), Curve)
Loop While Ent is Nothing


Dim pro1 As New PromptDoubleOptions(vbLf & "Input offset distance:")
Dim proR1 As PromptDoubleResult = ZcEd.GetDouble(pro1)
If proR1.Status <> PromptStatus.OK Then
Return
End If
Dim dist As Double = proR1.Value

Dim curves As List(Of Curve) = New List(Of Curve)()
Dim Coffset As DBObjectCollection = Ent.GetOffsetCurves(dist)

For Each i As Object In Coffset
curves.Add(DirectCast(i, Curve))
Next
Dim ZcBLT As BlockTable = ZcTran.GetObject(ZcDB.BlockTableId, OpenMode.ForRead)
Dim ZcBLTR As BlockTableRecord = ZcTran.GetObject(ZcBLT(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
For Each j As Object In curves
ZcBLTR.AppendEntity(j)
ZcTran.AddNewlyCreatedDBObject(j, True)
Next

ZcTran.Commit()
End Using
End Sub

End Class



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