下面是我用editor.command 实现的把直线转换为多段线的方法。
注意在选择集后面要加上一个双引号,里面什么也不填,类似命令里面的空格或回车。不然命令会失败
还有就是如果在Transaction里面使用命令,一定要记得acTrans.Commit()提交,不然命令也会失败。
利用acedCmd也可以实现,这个命令是给低版本autocad用的。过几天我把vb代码贴上来,主要是参考9楼的代码,做了转化。谢谢。
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
'' 创建一个 TypedValue 数组,用于定义过滤条件
Dim acTypValAr(0) As TypedValue
acTypValAr.SetValue(New TypedValue(DxfCode.Start, "line"), 0)
'' 赋值过滤条件给 SelectionFilter 对象
Dim acSelFtr As SelectionFilter = New SelectionFilter(acTypValAr)
'' 要求在图形区域中选择对象
Dim acSSPrompt As PromptSelectionResult
acSSPrompt = ed.SelectAll(acSelFtr)
'' 如果提示状态是 OK,对象就被选择了
If acSSPrompt.Status = PromptStatus.OK Then
Dim acSSet As SelectionSet = acSSPrompt.Value
ed.Command("_PEDIT", "_M", acSSet, "", "_Y", "_J", 0, "")
End If 同样的命令用acedCmd实现
Private Declare Auto Function acedCmd Lib "acad.exe" _
(ByVal vlist As System.IntPtr) As Integer
<CommandMethod("FF3")> Public Sub FF3()
Dim acDocEd As Editor = Application.DocumentManager.MdiActiveDocument.Editor
'' 创建一个 TypedValue 数组,用于定义过滤条件 Create a TypedValue array to define the filter criteria
Dim acTypValAr(0) As TypedValue
acTypValAr.SetValue(New TypedValue(DxfCode.Start, "LINE"), 0)
'' 赋值过滤条件给 SelectionFilter 对象 Assign the filter criteria to a SelectionFilter object
Dim acSelFtr As SelectionFilter = New SelectionFilter(acTypValAr)
'' 要求在图形区域中选择对象 Request for objects to be selected in the drawing area
Dim acSSPrompt As PromptSelectionResult
acSSPrompt = acDocEd.SelectAll(acSelFtr)
' 如果提示状态是 OK,对象就被选择了 If the prompt status is OK,nobjects were selected
If acSSPrompt.Status = PromptStatus.OK Then
Dim acSSet As SelectionSet = acSSPrompt.Value
Dim rb As ResultBuffer = New ResultBuffer
rb.Add(New TypedValue(5005, "_PEDIT"))
rb.Add(New TypedValue(5005, "_M"))
rb.Add(New TypedValue(5007, acSSet))
rb.Add(New TypedValue(5005, ""))
rb.Add(New TypedValue(5005, "_Y"))
rb.Add(New TypedValue(5005, "_J"))
rb.Add(New TypedValue(5001, 0))
rb.Add(New TypedValue(5005, ""))
acedCmd(rb.UnmanagedObject)
Else
Application.ShowAlertDialog("Number of objects selected: 0")
End If
End Sub 学习,顶!! 牛,学习!!!!
页:
1
[2]