实际上,您可以使用枚举值(在本例中为3)而不是枚举。我更喜欢在可能的情况下使用枚举,以提高代码的可读性。
- <CommandMethod("SetPipeFlowMethodToSlope")>
- Public Sub setPipeFlowMethodToSlope()
- 'Get Documents and Database
- Dim aDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
- Dim ed As Editor = aDoc.Editor
- Dim db As Database = aDoc.Database
- 'Build SelectionSet Options and Filter
- Dim acTypValAr(0) As TypedValue
- acTypValAr.SetValue(New TypedValue(DxfCode.Start, "AECC_PIPE"), 0)
- Dim pSelFil As SelectionFilter = New SelectionFilter(acTypValAr)
- Dim pSelFilOpt As New PromptSelectionOptions
- With pSelFilOpt
- .AllowDuplicates = False
- .AllowSubSelections = False
- .RejectObjectsFromNonCurrentSpace = True
- .RejectObjectsOnLockedLayers = False
- End With
- 'Prompt for Selection
- Dim PrmptSelRes As PromptSelectionResult = aDoc.Editor.GetSelection(pSelFilOpt, pSelFil)
- 'Test for a Good Selection
- If PrmptSelRes.Status = PromptStatus.OK Then
- 'Get the SelectionSet
- Dim ss As SelectionSet = PrmptSelRes.Value
- 'Begin a database transaction
- Using trans As Transaction = db.TransactionManager.StartTransaction
- For Each item As SelectedObject In ss
- 'Open each pipe in the selectionset for write
- Dim pipeObj As Pipe = trans.GetObject(item.ObjectId, OpenMode.ForWrite)
- 'Print the Network Name, Pipe Name & Current Flow Method.
- ed.WriteMessage(vbCrLf + "Network: " + pipeObj.NetworkName + " Name: " + pipeObj.Name + " - " + pipeObj.FlowDirectionMethod.ToString)
- 'Set the Flow Direction to BySlope
- [color="red"]pipeObj.FlowDirectionMethod = 3[/color]
- 'Print what we just did.
- ed.WriteMessage(vbCrLf + "Name: " + pipeObj.Name + " FlowDirectionMethod has been set to BySlope.")
- Next
- 'Commit the transaction.
- trans.Commit()
- End Using
- End If
- ed.WriteMessage(vbCrLf + "Command has completed successfully.")
- End Sub
https://msdn.microsoft.com/en-us/library/3sd4y2w7.aspx |