.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Selecting Created/Modified Entities

9 REPLIES 9
Reply
Message 1 of 10
HJohn
399 Views, 9 Replies

Selecting Created/Modified Entities

Can someone help me here? I created a polyline from a group of lines suing Document.SendStringToExecute("_pedit" ..., but I can not select the newly created polyline using Editor.SelectAll. I guess I need to update o to do something before I could select it. The polyline was created within a transaction which was committed at the end. AutoCAD 2007
9 REPLIES 9
Message 2 of 10
Anonymous
in reply to: HJohn

Try Editor.SelectLast
Not tested, just an idea

~'J'~
Message 3 of 10
HJohn
in reply to: HJohn

There could be more than one polyline.
Message 4 of 10
Anonymous
in reply to: HJohn

My guess is that the commands are executing asynchronusly,
after the call to SelectAll().

If your code runs in the document context (e.g., from the
handler of a registered command), then you don't have to
put up with the SendStringToExecute() nonsense.

Try using the wrapper for acedCommand() that can be found
here:

http://www.caddzone.com/CommandLine.cs


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

wrote in message news:5525740@discussion.autodesk.com...
Can someone help me here? I created a polyline from a group of lines suing Document.SendStringToExecute("_pedit" ..., but I can not select the newly created polyline using Editor.SelectAll. I guess I need to update o to do something before I could select it. The polyline was created within a transaction which was committed at the end. AutoCAD 2007
Message 5 of 10
HJohn
in reply to: HJohn

Thank you for your reply. I wish I could use it, but it is too advanced for me and for what I do, :-(. I still don't understand what is happening or what I am missing. Using two routines, the first one SelectAll() the lines and call SendStringToExecute("_pedit"... ) making the polylines. The second routine, SelectAll() and gets the same bloody lines. If I stop after the first routine, and go into the drawing I see only the polylines and the lines are gone. What am I missing? What to update? I have seen calls to AddNewlyCreatedDBObject() in the .NET samples, is it something like that missing?
Message 6 of 10
Anonymous
in reply to: HJohn

Sorry, to say this, but being too timid to post your
code, and expecting others to try to guess what your
code is doing, is a bit unreasonable.

If you post the relevants parts of your code, I'm sure
you'll get some help.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

wrote in message news:5527371@discussion.autodesk.com...
Thank you for your reply. I wish I could use it, but it is too advanced for me and for what I do, :-(. I still don't understand what is happening or what I am missing. Using two routines, the first one SelectAll() the lines and call SendStringToExecute("_pedit"... ) making the polylines. The second routine, SelectAll() and gets the same bloody lines. If I stop after the first routine, and go into the drawing I see only the polylines and the lines are gone. What am I missing? What to update? I have seen calls to AddNewlyCreatedDBObject() in the .NET samples, is it something like that missing?
Message 7 of 10
HJohn
in reply to: HJohn

Thank you for your help. I thought might have been a simple miss step and therefore, there was no need to bother with the code. But, here is it. I am just beginning to develop it in .NET. I have a working version on LISP which I always wanted to port to VBA, but now that I can do it I thought may be it would be better to do it in .NET. If I can get this part, then the rest is no a problem. Hope you can help.


Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry

Public Class Test

_
Public Sub StartPoint()
Call MakePolylines("WALL_SECTIONS")
Call GetPolylines("WALL_SECTIONS")
End Sub

#Region "Functions"

#End Region
Public Sub MakePolylines(ByVal LayerName As String)
Dim t As Transaction = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction
Dim e As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim doc As Autodesk.AutoCAD.ApplicationServices.Document
Dim SRst As PromptSelectionResult
Dim SFilter As SelectionFilter
Dim Filter(0) As TypedValue
Dim SS As SelectionSet


Try

Filter(0) = New TypedValue(8, LayerName)

SFilter = New SelectionFilter(Filter)

SRst = e.SelectAll(SFilter)

If SRst.Status PromptStatus.OK Then
e.WriteMessage("Can not find any lines in this drawing, layer: " & LayerName)
Else
SS = SRst.Value

doc = Application.DocumentManager.MdiActiveDocument

doc.SendStringToExecute("_pedit" & vbCr & "m" & vbCr & "p" & vbCr & vbCr & "y" & vbCr & "j" & vbCr & vbCr & vbCr, False, False, False)

End If

SS = Nothing
SRst = Nothing
t.Commit()

Catch ex As Exception

t.Abort()

Finally

t = Nothing
End Try

End Sub
Public Sub GetPolylines(ByVal LayerName As String)
Dim t As Transaction = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction
Dim e As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim SRst As PromptSelectionResult
Dim SFilter As SelectionFilter
Dim Filter(0) As TypedValue
Dim SS As SelectionSet
Dim Poly As Polyline
Dim ObjId As ObjectId
Dim ObjIdColl() As ObjectId

Try


'Filter(0) = New TypedValue(0, "LWPOLYLINE")
Filter(0) = New TypedValue(8, LayerName)

SFilter = New SelectionFilter(Filter)

SRst = e.SelectAll()

If SRst.Status PromptStatus.OK Then
e.WriteMessage("Can not find any polylines in this drawing, layer: " & LayerName)
Else

SS = SRst.Value


ObjIdColl = SS.GetObjectIds

For Each ObjId In ObjIdColl
Dim ent As Entity = t.GetObject(ObjId, OpenMode.ForRead, True)
If TypeOf ent Is Polyline Then
Poly = ent

If Poly.Closed = True Then
'Add code here
End If

End If
Next ObjId


End If

t.Commit()

Catch ex As Exception

t.Abort()

Finally

t = Nothing
End Try
End Sub

End Class
Message 8 of 10
Anonymous
in reply to: HJohn

I'm afraid that you're not going to have much
luck with using SendStringToExecute().

I'm fairly certain the problem is that your
call to SelectAll() is executing *before* the
commands in SendStringToExecute() run.

I would suggest that you use the code that
I referred you to on my website, which will
eliminate the problem.

Here is a quick/dirty port to VB:

http://www.caddzone.com/CommandLine.vb

Imports CommandLineInterface

Add that file to your project, add the Imports
directive shown above to your code file, then
replace the call to SendStringToExecute() with
this:

CommandLine.Command( "._PEDIT", "_m", _
"_p", "", "_y", "_join", "", "")

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

wrote in message news:5527717@discussion.autodesk.com...
Thank you for your help. I thought might have been a simple miss step and therefore, there was no need to bother with the code. But, here is it. I am just beginning to develop it in .NET. I have a working version on LISP which I always wanted to port to VBA, but now that I can do it I thought may be it would be better to do it in .NET. If I can get this part, then the rest is no a problem. Hope you can help.


Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry

Public Class Test

_
Public Sub StartPoint()
Call MakePolylines("WALL_SECTIONS")
Call GetPolylines("WALL_SECTIONS")
End Sub

#Region "Functions"

#End Region
Public Sub MakePolylines(ByVal LayerName As String)
Dim t As Transaction = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction
Dim e As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim doc As Autodesk.AutoCAD.ApplicationServices.Document
Dim SRst As PromptSelectionResult
Dim SFilter As SelectionFilter
Dim Filter(0) As TypedValue
Dim SS As SelectionSet


Try

Filter(0) = New TypedValue(8, LayerName)

SFilter = New SelectionFilter(Filter)

SRst = e.SelectAll(SFilter)

If SRst.Status PromptStatus.OK Then
e.WriteMessage("Can not find any lines in this drawing, layer: " & LayerName)
Else
SS = SRst.Value

doc = Application.DocumentManager.MdiActiveDocument

doc.SendStringToExecute("_pedit" & vbCr & "m" & vbCr & "p" & vbCr & vbCr & "y" & vbCr & "j" & vbCr & vbCr & vbCr, False, False, False)

End If

SS = Nothing
SRst = Nothing
t.Commit()

Catch ex As Exception

t.Abort()

Finally

t = Nothing
End Try

End Sub
Public Sub GetPolylines(ByVal LayerName As String)
Dim t As Transaction = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction
Dim e As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim SRst As PromptSelectionResult
Dim SFilter As SelectionFilter
Dim Filter(0) As TypedValue
Dim SS As SelectionSet
Dim Poly As Polyline
Dim ObjId As ObjectId
Dim ObjIdColl() As ObjectId

Try


'Filter(0) = New TypedValue(0, "LWPOLYLINE")
Filter(0) = New TypedValue(8, LayerName)

SFilter = New SelectionFilter(Filter)

SRst = e.SelectAll()

If SRst.Status PromptStatus.OK Then
e.WriteMessage("Can not find any polylines in this drawing, layer: " & LayerName)
Else

SS = SRst.Value


ObjIdColl = SS.GetObjectIds

For Each ObjId In ObjIdColl
Dim ent As Entity = t.GetObject(ObjId, OpenMode.ForRead, True)
If TypeOf ent Is Polyline Then
Poly = ent

If Poly.Closed = True Then
'Add code here
End If

End If
Next ObjId


End If

t.Commit()

Catch ex As Exception

t.Abort()

Finally

t = Nothing
End Try
End Sub

End Class
Message 9 of 10
HJohn
in reply to: HJohn

Great! Thank you very much. It worked very good, you are good. Don't the AD people know that theirs method doesn't work? Why they don't fix it?
Message 10 of 10
Anonymous
in reply to: HJohn

wrote in message

>> Don't the AD people know that theirs
>> method doesn't work?

Yes, they've known that for about the same
amount of time that it hasn't worked, which
is since the release of AutoCAD 2000.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost