About "IntersectWith" Method
CADForums.net Forum Index CADForums.net
Discussion of AutoCAD and other CAD software.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web cadforums.net
About "IntersectWith" Method

 
Post new topic   Reply to topic    CADForums.net Forum Index -> VBA
Author Message
anttam
Guest





Posted: Mon Mar 28, 2005 7:23 pm    Post subject: About "IntersectWith" Method Reply with quote

Dim ckIntersect As Boolean
ckIntersect = cktest(objSS.Item(0), objSS.Item(1))
---------------------------------------------------------------------
Function cktest(objEnt1 As AcadEntity, objEnt2 As AcadEntity) As Boolean
Dim iPt As Variant
Dim intersect As Boolean
On Error Resume Next
With ThisDrawing.Utility

intersect = False

If Not IsNull(objEnt1.IntersectWith(objEnt2, acExtendNone)) Then intersect = True

If intersect = True Then
iPt = objEnt1.IntersectWith(objEnt2, acExtendNone)
.Prompt vbCrLf & "intersect point = " & iPt(0) & "," & iPt(1)
Else: .promt vbCrLf & "No intersect!"
End If

If Err Then .Prompt vbCrLf & "Error as " & Err.Description

cktest = intersect

End With
End Function
--------------------------------------------------------------------------
* When there is intersect.......
the intersect point can shown and cktest = True

* When there is no intersect....
no intersect point is shown but cktest = True
"Command: Error as Subscript out of range" is shown
-----------------------------------------------------------------------
Q1. Why cktest still true when no intersection?
Q2. When there is more than one intersection points, how to shown them all?

Please Help~ Thanks!

Back to top
TomD
Guest





Posted: Mon Mar 28, 2005 8:00 pm    Post subject: Re: About "IntersectWith" Method Reply with quote

"anttam" <nospam@address.withheld> wrote in message
news:15891650.1112019860864.JavaMail.jive@jiveforum1.autodesk.com...
<SNIPPED>
Quote:
* When there is no intersect....
no intersect point is shown but cktest = True
"Command: Error as Subscript out of range" is shown
-----------------------------------------------------------------------
Q1. Why cktest still true when no intersection?
Q2. When there is more than one intersection points, how to shown them
all?

From what I understand, you have to check for a UBound of less than 0. I
don't at all understand why this works this way, but that's what I've
gathered, so far. (I only recently tried this out, and do not have it in
production, yet, so I could certainly be mistaken.)
Back to top
anttam
Guest





Posted: Mon Mar 28, 2005 9:53 pm    Post subject: Re: About "IntersectWith" Method Reply with quote

Hi~ TomD
Thanks for help, but how to check for a UBound?
Can you show me by examples?
Thanks a lot!

Back to top
Norman Yuan
Guest





Posted: Tue Mar 29, 2005 12:15 am    Post subject: Re: About "IntersectWith" Method Reply with quote

There is a bug in AutoCAD VBA Help's sample code for IntersectWith() method:

From sample code:

' Find the intersection points between the line and the circle
Dim intPoints As Variant
intPoints = lineObj.IntersectWith(circleObj, acExtendNone)

' Print all the intersection points
Dim I As Integer, j As Integer, k As Integer
Dim str As String
If VarType(intPoints) <> vbEmpty Then '' ========HERE IS THE
BUG===========
For I = LBound(intPoints) To UBound(intPoints)
str = "Intersection Point[" & k & "] is: " & intPoints(j) & ","
& intPoints(j + 1) & "," & intPoints(j + 2)
MsgBox str, , "IntersectWith Example"
str = ""
I = I + 2
j = j + 3
k = k + 1
Next
End If

The bug is that: IntersectWith() never returns a Variant of vbEmpty, it
returns an empty array of Double (that is UBound(returnVariant)=-1) if there
is no intersection, and returns an array of Double
(UBound(returnVariant)>=2), if there is 1 or more intersections.

So you need to check UBound() of returned variant to tell whether there is
intersection or not, as the other post suggested.

"anttam" <nospam@address.withheld> wrote in message
news:15891650.1112019860864.JavaMail.jive@jiveforum1.autodesk.com...
Quote:
Dim ckIntersect As Boolean
ckIntersect = cktest(objSS.Item(0), objSS.Item(1))
---------------------------------------------------------------------
Function cktest(objEnt1 As AcadEntity, objEnt2 As AcadEntity) As Boolean
Dim iPt As Variant
Dim intersect As Boolean
On Error Resume Next
With ThisDrawing.Utility

intersect = False

If Not IsNull(objEnt1.IntersectWith(objEnt2, acExtendNone)) Then
intersect = True

If intersect = True Then
iPt = objEnt1.IntersectWith(objEnt2, acExtendNone)
.Prompt vbCrLf & "intersect point = " & iPt(0) & "," & iPt(1)
Else: .promt vbCrLf & "No intersect!"
End If

If Err Then .Prompt vbCrLf & "Error as " & Err.Description

cktest = intersect

End With
End Function
--------------------------------------------------------------------------
* When there is intersect.......
the intersect point can shown and cktest = True

* When there is no intersect....
no intersect point is shown but cktest = True
"Command: Error as Subscript out of range" is shown
-----------------------------------------------------------------------
Q1. Why cktest still true when no intersection?
Q2. When there is more than one intersection points, how to shown them
all?

Please Help~ Thanks!
Back to top
TomD
Guest





Posted: Tue Mar 29, 2005 12:41 am    Post subject: Re: About "IntersectWith" Method Reply with quote

If Norman's post doesn't explain it enough, repost and I'll post a piece of
code I was using.

"anttam" <nospam@address.withheld> wrote in message
news:24981573.1112028820612.JavaMail.jive@jiveforum2.autodesk.com...
Quote:
Hi~ TomD
Thanks for help, but how to check for a UBound?
Can you show me by examples?
Thanks a lot!
Back to top
anttam
Guest





Posted: Tue Mar 29, 2005 10:11 pm    Post subject: Re: About "IntersectWith" Method Reply with quote

Norman

Thank you again~

anttam @w@
Back to top
anttam
Guest





Posted: Tue Mar 29, 2005 10:15 pm    Post subject: Re: About "IntersectWith" Method Reply with quote

Hi! TomD

It's Ok, thanks!

anttam
Back to top
 
Post new topic   Reply to topic    CADForums.net Forum Index -> VBA All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




Windows Server DSP VoIP Electronics New Topics
Powered by phpBB