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

Break/Trim command

7 REPLIES 7
Reply
Message 1 of 8
Anonymous
2430 Views, 7 Replies

Break/Trim command

i would like to know if someone knows how to implement or use break or trim command with c#.
please give me an idea or some example.
i know how to select de objects, get ids, and i need to intersect to get the length of one of the break lines
7 REPLIES 7
Message 2 of 8
Anonymous
in reply to: Anonymous

You can use IntersectWith() to get intersections between de objects, that would include the points you use to break de objects.

You can use Curve.GetSplitCurves() to actually break objects into several parts, if they are derived from Curve.

Sorry, I don't have any examples handy but searching the newsgroups on the right terms might turn up something.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5866218@discussion.autodesk.com...
i would like to know if someone knows how to implement or use break or trim command with c#.
please give me an idea or some example.
i know how to select de objects, get ids, and i need to intersect to get the length of one of the break lines
Message 3 of 8
Anonymous
in reply to: Anonymous

Is there what you lookin for?

'//virtual Acad::ErrorStatus
'//AcDbCurve::getSplitCurves(
'//const AcGePoint3dArray& points,
'//AcDbVoidPtrArray& curveSegments) const;
Public Shared Sub BreakCurve()
Dim db As Database = HostApplicationServices.WorkingDatabase
Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
Using doclock As DocumentLock = doc.LockDocument
Using tr As Transaction = db.TransactionManager.StartTransaction()
Try

Dim bt As BlockTable = tr.GetObject(db.BlockTableId, OpenMode.ForRead)
Dim btr As BlockTableRecord = DirectCast(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)
Dim opt As PromptEntityOptions = New PromptEntityOptions(Environment.NewLine & "Select curve to break: ")
Dim eres As PromptEntityResult = ed.GetEntity(opt)
If eres.Status <> PromptStatus.OK Then
Return
End If
Dim ent As Entity = (CType(tr.GetObject(eres.ObjectId, OpenMode.ForRead, False), Entity))
Dim opt1 As PromptPointOptions = New PromptPointOptions(Environment.NewLine & "Enter a first point")
Dim opt2 As PromptPointOptions = New PromptPointOptions(Environment.NewLine & "Enter a second point")
Dim res1 As PromptPointResult = ed.GetPoint(opt1)
Dim p As Point3d = res1.Value
opt2.BasePoint = p
opt2.UseBasePoint = True
Dim res2 As PromptPointResult = ed.GetPoint(opt2)
Dim pts As Point3dCollection = New Point3dCollection
pts.Add(res1.Value)
pts.Add(res2.Value)
Dim curv As Curve = (CType(tr.GetObject(ent.ObjectId, OpenMode.ForWrite, False), Curve))
Dim objs As DBObjectCollection = curv.GetSplitCurves(pts)
If objs.Count > 0 Then
MessageBox.Show("Objects: " & objs.Count.ToString)
For Each obj As DBObject In objs
btr.AppendEntity(obj)
tr.AddNewlyCreatedDBObject(obj, True)
Next
ent.Erase()
ent.Dispose()
tr.Commit()
End If
Catch ex As Exception
MessageBox.Show(ex.StackTrace)
Finally
tr.Dispose()
End Try
End Using
End Using
End Sub

~'J'~
Message 4 of 8
Anonymous
in reply to: Anonymous

The problem is a bit more complicated than what Fatty's code shows.

First, the break points must lie exactly on the curve, and must be sorted by their distance from the start of the curve.

You can use GetClosestPointTo() to get the closest point on the curve. You can use GetDistAtPoint() to get the distance used to sort the break points.

Fatty's code also shows the bad habit of Using + Dispose(), which is needless and confusing. If you use Using() then you don't have to call Dispose().

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5866218@discussion.autodesk.com...
i would like to know if someone knows how to implement or use break or trim command with c#.
please give me an idea or some example.
i know how to select de objects, get ids, and i need to intersect to get the length of one of the break lines
Message 5 of 8
Anonymous
in reply to: Anonymous

Dear Tony, thanks again
I've forgot about 'Using' as always 🙂
Btw, middle part between break points is still there
How to delete it?
Regards,

~'J'~ Message was edited by: Fatty
Message 6 of 8
Anonymous
in reply to: Anonymous

Fatty - objects returned by GetSplitCurves() are not databas-resident.

Only add those you want to the database, and call Dispose() on the rest.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5867193@discussion.autodesk.com...
Dear Tony, thanks again
I've forgot about 'Using' as always 🙂
Btw, middle part between break points is still there
How to delete it?
Regards,

~'J'~

Message was edited by: Fatty
Message 7 of 8
Anonymous
in reply to: Anonymous

Ah, it's so easy
Thanks

~'J'~
Message 8 of 8
Anonymous
in reply to: Anonymous

thanks for your help!
im trying to use Fatty's code to solve my problem.
i have to know the distance (throw the polyline) from the star to the point where a line intersects the polyline).
in AutoCAD i try the poly and read length, but throw the code is more complicated

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