PanHasan Posted August 13, 2009 Share Posted August 13, 2009 Hi i wrote some code and it works it used to find the point of intersect of a ray and a line everything works fine but if i draw a line using ortho it returns the start point of the line not the intersect anybody knows how to fix this <CommandMethod("src")> _ Public Sub src() Dim lCmd As Editor = Application.DocumentManager.MdiActiveDocument.Editor Dim acBaza As Database = lCmd.Document.Database Dim trn As Transaction = acBaza.TransactionManager.StartTransaction Dim usrPointOp As PromptPointOptions = New PromptPointOptions("Wskarz srodek pomieszczenia :") Dim usrPoint As PromptPointResult = lCmd.GetPoint(usrPointOp) Dim ptkPoprzedni As Point3d = usrPoint.Value Dim ptkNajblizszy As Point3d = usrPoint.Value If usrPoint.Status = PromptStatus.OK Then Dim tmpPoint As Point3d = New Point3d(usrPoint.Value.X + 1, usrPoint.Value.Y, usrPoint.Value.Z) Dim srcLine As Ray = New Ray() srcLine.BasePoint = usrPoint.Value srcLine.SecondPoint = tmpPoint 'FILTRACJA LINII Dim typeValue() As TypedValue = {New TypedValue(0, "line")} Dim selFilter As SelectionFilter = New SelectionFilter(typeValue) Dim selResult As PromptSelectionResult = lCmd.SelectAll(selFilter) Dim ssLinie As SelectionSet = selResult.Value Dim tabID() As ObjectId = ssLinie.GetObjectIds 'TRANSAKCJA Try Dim btr As BlockTableRecord = trn.GetObject(acBaza.CurrentSpaceId, OpenMode.ForWrite) btr.AppendEntity(srcLine) trn.AddNewlyCreatedDBObject(srcLine, True) Dim ra As Ray = CType(trn.GetObject(srcLine.Id, OpenMode.ForRead), Ray) Dim ptkPrzeciecia As Point3dCollection = New Point3dCollection() Dim intthis As Integer Dim intThat As Integer Dim objID As ObjectId Dim licz As Integer = 0 Dim ilosc As Integer = 0 Dim lnNajblizsza As Line = Nothing For Each objID In tabID Dim ln As Line = CType(trn.GetObject(objID, OpenMode.ForRead), Line) ln.IntersectWith(ra, Intersect.OnBothOperands, ra.GetPlane(), ptkPrzeciecia, intthis, intThat) 'SZUKANIE NAJBLIZSZEJ LINII If ptkPrzeciecia.Count <> ilosc Then ilosc = ptkPrzeciecia.Count If licz = 0 Then ptkNajblizszy = ptkPrzeciecia.Item(0) lnNajblizsza = ln End If If ptkNajblizszy.X >= ptkPrzeciecia.Item(licz).X Then ptkNajblizszy = ptkPrzeciecia.Item(licz) lnNajblizsza = ln End If licz = licz + 1 End If Next lCmd.WriteMessage(ptkNajblizszy.ToString) If lnNajblizsza <> Nothing Then lnNajblizsza.Highlight() End If ' rysujOdPomocniczy(ptkPoprzedni, ptkNajblizszy, lnL1) ' szukajPtk(ptkNajblizszy, ptkPoprzedni, tabID, lnL1) trn.Commit() Catch ex As Exception Finally trn.Dispose() End Try End If End Sub End Class Quote Link to comment Share on other sites More sharing options...
SEANT Posted August 13, 2009 Share Posted August 13, 2009 That is interesting (and rather disturbing). I’d have to dissect the routine in depth to know if it is a bug in the managed arx API, though. In any event, this change to the code seems to work okay: ra.IntersectWith(ln, Intersect.OnBothOperands, ra.GetPlane(), ptkPrzeciecia, intthis, intThat) Switched which object's IntersectWith method was called. Quote Link to comment Share on other sites More sharing options...
PanHasan Posted August 13, 2009 Author Share Posted August 13, 2009 Hi yes your right but i need to use it in the old way i find the intersects points with a ray when i change that param to ln it works fine for the ortho lines but crashes for all others ;( Quote Link to comment Share on other sites More sharing options...
SEANT Posted August 13, 2009 Share Posted August 13, 2009 Does this work any better? Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.EditorInput Imports Autodesk.AutoCAD.Geometry <CommandMethod("src")> _ Public Sub src() Dim lCmd As Editor = Application.DocumentManager.MdiActiveDocument.Editor Dim acBaza As Database = lCmd.Document.Database Dim trn As Transaction = acBaza.TransactionManager.StartTransaction Dim usrPointOp As PromptPointOptions = New PromptPointOptions("Wskarz srodek pomieszczenia :") Dim usrPoint As PromptPointResult = lCmd.GetPoint(usrPointOp) Dim ptkPoprzedni As Point3d = usrPoint.Value Dim ptkNajblizszy As Point3d = usrPoint.Value If usrPoint.Status = PromptStatus.OK Then Dim tmpPoint As Point3d = New Point3d(usrPoint.Value.X + 1, usrPoint.Value.Y, usrPoint.Value.Z) Dim srcLine As Ray = New Ray() srcLine.BasePoint = usrPoint.Value srcLine.SecondPoint = tmpPoint 'FILTRACJA LINII Dim typeValue() As TypedValue = {New TypedValue(0, "line")} Dim selFilter As SelectionFilter = New SelectionFilter(typeValue) Dim selResult As PromptSelectionResult = lCmd.SelectAll(selFilter) Dim ssLinie As SelectionSet = selResult.Value Dim tabID() As ObjectId = ssLinie.GetObjectIds 'TRANSAKCJA Try Dim btr As BlockTableRecord = trn.GetObject(acBaza.CurrentSpaceId, OpenMode.ForWrite) srcLine.SetDatabaseDefaults() btr.AppendEntity(srcLine) trn.AddNewlyCreatedDBObject(srcLine, True) Dim objID As ObjectId Dim licz As Integer = 0 Dim ilosc As Integer = 0 Dim ra3d As Ray3d = New Ray3d(srcLine.StartPoint, srcLine.SecondPoint) Dim lnNajblizsza As Line = Nothing For Each objID In tabID Dim ln As Line = CType(trn.GetObject(objID, OpenMode.ForRead), Line) Dim ls As LineSegment3d = New LineSegment3d(ln.StartPoint, ln.EndPoint) Dim ptkPrzeciecia As Point3dCollection = New Point3dCollection(ls.IntersectWith(ra3d)) 'SZUKANIE NAJBLIZSZEJ LINII If ptkPrzeciecia.Count <> ilosc Then ilosc = ptkPrzeciecia.Count If licz = 0 Then ptkNajblizszy = ptkPrzeciecia.Item(0) lnNajblizsza = ln End If If ptkNajblizszy.X >= ptkPrzeciecia.Item(licz).X Then ptkNajblizszy = ptkPrzeciecia.Item(licz) lnNajblizsza = ln End If licz = licz + 1 End If Next lCmd.WriteMessage(ptkNajblizszy.ToString) If lnNajblizsza <> Nothing Then lnNajblizsza.Highlight() End If ' rysujOdPomocniczy(ptkPoprzedni, ptkNajblizszy, lnL1) ' szukajPtk(ptkNajblizszy, ptkPoprzedni, tabID, lnL1) trn.Commit() Catch ex As Exception Finally trn.Dispose() End Try End If End Sub Quote Link to comment Share on other sites More sharing options...
PanHasan Posted August 13, 2009 Author Share Posted August 13, 2009 Yes you are great it works perfect thanks a lot Quote Link to comment Share on other sites More sharing options...
PanHasan Posted August 13, 2009 Author Share Posted August 13, 2009 Opps I find a problem witch code above everything works fine but if the ls and a ray3d it generates an error and the app crashes any idea why ? Dim ptkPrzeciecia As Point3dCollection = New Point3dCollection(ls.IntersectWith(ra3d)) Quote Link to comment Share on other sites More sharing options...
SEANT Posted August 13, 2009 Share Posted August 13, 2009 It probably not sensible to give advice on a routine of which I know almost nothing about its ultimate purpose, but here I go anyway. Does this perform any better? <CommandMethod("src")> _ Public Sub src() Dim lCmd As Editor = Application.DocumentManager.MdiActiveDocument.Editor Dim acBaza As Database = lCmd.Document.Database Dim usrPointOp As PromptPointOptions = New PromptPointOptions("Wskarz srodek pomieszczenia :") Dim usrPoint As PromptPointResult = lCmd.GetPoint(usrPointOp) Dim ptkPoprzedni As Point3d = usrPoint.Value Dim ptkNajblizszy As Point3d = usrPoint.Value If usrPoint.Status = PromptStatus.OK Then Dim tmpPoint As Point3d = New Point3d(usrPoint.Value.X + 1, usrPoint.Value.Y, usrPoint.Value.Z) Dim srcLine As Ray = New Ray() srcLine.BasePoint = usrPoint.Value srcLine.SecondPoint = tmpPoint 'FILTRACJA LINII Dim typeValue() As TypedValue = {New TypedValue(0, "line")} Dim selFilter As SelectionFilter = New SelectionFilter(typeValue) Dim selResult As PromptSelectionResult = lCmd.SelectAll(selFilter) Dim ssLinie As SelectionSet = selResult.Value Dim tabID() As ObjectId = ssLinie.GetObjectIds 'TRANSAKCJA Using trn As Transaction = acBaza.TransactionManager.StartTransaction Try Dim btr As BlockTableRecord = trn.GetObject(acBaza.CurrentSpaceId, OpenMode.ForWrite) Dim objID As ObjectId Dim licz As Integer = 0 Dim ilosc As Integer = 0 Dim ra3d As Ray3d = New Ray3d(srcLine.StartPoint, srcLine.SecondPoint) Dim lnNajblizsza As Line = Nothing For Each objID In tabID Dim ln As Line = CType(trn.GetObject(objID, OpenMode.ForRead), Line) Dim ls As LineSegment3d = New LineSegment3d(ln.StartPoint, ln.EndPoint) Dim ptArray() As Point3d = ls.IntersectWith(ra3d) If ptArray Is Nothing Then Continue For Dim ptkPrzeciecia As Point3dCollection = New Point3dCollection(ptArray) 'SZUKANIE NAJBLIZSZEJ LINII If ptkPrzeciecia.Count <> ilosc Then ilosc = ptkPrzeciecia.Count If licz = 0 Then ptkNajblizszy = ptkPrzeciecia.Item(0) lnNajblizsza = ln End If If ptkNajblizszy.X >= ptkPrzeciecia.Item(licz).X Then ptkNajblizszy = ptkPrzeciecia.Item(licz) lnNajblizsza = ln End If licz = licz + 1 End If Next lCmd.WriteMessage(ptkNajblizszy.ToString) If lnNajblizsza <> Nothing Then lnNajblizsza.Highlight() End If ' rysujOdPomocniczy(ptkPoprzedni, ptkNajblizszy, lnL1) ' szukajPtk(ptkNajblizszy, ptkPoprzedni, tabID, lnL1) srcLine.SetDatabaseDefaults() btr.AppendEntity(srcLine) trn.AddNewlyCreatedDBObject(srcLine, True) trn.Commit() Catch ex As Exception srcLine.Dispose() lCmd.WriteMessage("Operation Error!") End Try End Using End If End Sub Quote Link to comment Share on other sites More sharing options...
PanHasan Posted August 13, 2009 Author Share Posted August 13, 2009 Yes this time it works in all cases thx Quote Link to comment Share on other sites More sharing options...
SEANT Posted August 13, 2009 Share Posted August 13, 2009 Yes this time it works in all cases thx That's good to hear. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.