Hi,
I am filtering for objects based on layer as shown below.The layer consists of lines and arcs.Is there anyway to convert all these entities into a polyline and get the object id of this single entity.Appreciate any ideas.
Dim acTypValArPath(0) AsTypedValue
Dim sf As SelectionFilter = New SelectionFilter(New TypedValue() {New TypedValue(8, "FirstBias")})
Dim ss As SelectionSet = acEditor.SelectAll(sf).Value
Dim idarray As ObjectId() = ss.GetObjectIds()
Dim id AsObjectId
For Each id In idarray
Dim entity As = trLocal.GetObject(id, OpenMode.ForRead, True)
Next id
If (typeof entity is Arc) Then
......
End If
If (typeof entity is Line) Then
.......
End If
Thanks
Gulzar
Solved! Go to Solution.
Solved by _gile. Go to Solution.
Hi,
As I replied you in this other thread, if you want to hard-code the "join" option of the "PEDIT" command, you can get some inspiration from this reply. The MJOIN command uses the PolylineSegement and PolylneSegmentCollection classes defined in the GeometryExtensions assembly. The source code (C#) and compiled assemblies are downloadable from this reply.
But it seems to me that you're missing the AutoCAD and .NET basics.
So, you'd perhaps rather do some "scripting" with the "PEDIT" command.
Here's an example using a Tony Tanzillo's Editor.Command extension method which allow to pass managed types arguments to the command (as the LISP "command" function).
Imports System.Reflection Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.EditorInput Imports Autodesk.AutoCAD.Runtime Namespace gulzar25.JoinIntoPolyline ' credit to Tony Tanzillo ' http://www.theswamp.org/index.php?topic=43113.msg483306#msg483306 Module MyEditorExtensions Dim runCommand As MethodInfo = _ GetType(Editor).GetMethod("RunCommand", BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.Public) <System.Runtime.CompilerServices.Extension> _ Public Function Command(ed As Editor, ParamArray args As Object()) As PromptStatus If Application.DocumentManager.IsApplicationContext Then Throw New InvalidOperationException("Invalid execution context for Command()") End If If ed.Document <> Application.DocumentManager.MdiActiveDocument Then Throw New InvalidOperationException("Document is not active") End If Return DirectCast(runCommand.Invoke(ed, New Object() {args}), PromptStatus) End Function End Module Public Class Commands <CommandMethod("MJOIN")> _ Public Sub MultipleJoin() Dim acEditor As Editor = Application.DocumentManager.MdiActiveDocument.Editor Dim sf As SelectionFilter = New SelectionFilter(New TypedValue() {New TypedValue(8, "FirstBias")}) Dim psr As PromptSelectionResult = acEditor.SelectAll(sf) If psr.Status <> PromptStatus.OK Then Return End If acEditor.Command("_.pedit", "_multiple", psr.Value, "", "_join", 0.0, "") End Sub End Class End Namespace
IMO, scripting AutoCAD commands with .NET looks like hunting mosquitoes with a bazooka, this task would have been much more simply done with LISP:
(defun c:join (/ ss) (if (setq ss (ssget "_X" '((8 . "FirstBias")))) (command "_.pedit" "_multiple" ss "" "_join" 0.0 "") ) (princ) )
Did you add the 'MyEditorExtensions' module, from the upper code, to your project?
It's where the Editor.Command() extension method is defined.
The code I posted does select all entities on the "FirstBias" layer
acEditor.SelectAll(sf)
and only uses this selection in the PEDIT command call:
acEditor.Command("_.pedit", "_multiple", psr.Value, "", "_join", 0.0, "")
The empty string ("") argument after psr.Value validates this selection.
The code would be safer if it filtered the entity types too:
Dim typedValues() As TypedValue = {New TypedValue(8, "FirstBias"), New TypedValue(0, "ARC,LINE,LWPOLYLINE")} Dim sf As SelectionFilter = New SelectionFilter(typedValues)
This is due to the PEDITACCEPT system variable setting.
Here's a (safer) new version which stores the current PEDITACCEPT value, changes it to 1 while running the PEDIT command and restore it to the previous value.
<CommandMethod("MJOIN")> _ Public Sub MultipleJoin() Dim acEditor As Editor = Application.DocumentManager.MdiActiveDocument.Editor Dim peditAccept As Short = CShort(Application.GetSystemVariable("PEDITACCEPT")) Try Application.SetSystemVariable("PEDITACCEPT", 1) Dim typedValues() As TypedValue = {New TypedValue(8, "FirstBias"), New TypedValue(0, "ARC,LINE,LWPOLYLINE")} Dim sf As SelectionFilter = New SelectionFilter(typedValues) Dim psr As PromptSelectionResult = acEditor.SelectAll(sf) If psr.Status <> PromptStatus.OK Then Return End If acEditor.Command("_.pedit", "_multiple", psr.Value, "", "_join", 0.0, "") Catch ex As Exception MsgBox(ex.Message) Finally Application.SetSystemVariable("PEDITACCEPT", peditAccept) End Try End Sub
Assuming you're begining with AutoCAD customization, I think you didn't choose the easiest route with .NET. AutoLISP is really much simpler and you'd find much more help for these kind of basics.
Can't find what you're looking for? Ask the community or share your knowledge.