Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

The return value of "intersectWith" function (AutoCad) 1

Status
Not open for further replies.

erezzo

Computer
Apr 23, 2004
1
hi everyone, i'm trying to find the intersection point of two lines and then to create new lines using the intersection point (to break the line into two lines)...
my problem is when there isn't any intersection point- so the function "intersectWith" return unknown value. i need to check if there is a valid value or not but i don't know how... i tried the following code but the "if" statement don't give me the option that i need:

Dim ssetObj As AcadSelectionSet
Set ssetObj = ThisDrawing.SelectionSets.Add("TEST_SSET") ssetObj.SelectOnScreen
Dim newLine1 As AcadLine
Dim intPoint As Variant
intPoint = ssetObj.Item(0).IntersectWith
(ssetObj.Item(1), acExtendNone)
If VarType(intPoint) <> vbEmpty Then
Set newLine = ssetObj.Item(0)
Set AcadLine = ThisDrawing.ModelSpace.AddLine
(intPoint, newLine.EndPoint)
newLine.EndPoint = intPoint
End If
Next index2
Next index1

please help me - i can't find any other way........
 
Replies continue below

Recommended for you

Can you use the OSnap "AppInt" (Apparent Intersection) ??
 
Please see the code below - I have used your code and made it into a self-contained Subroutine by stripping off the 'Next' statements. I suggest you test it as a standalone sub first and then copy the relevant part to your procedure.

The key issue is testing for actual intersection of the lines - if the lines actually intersect, the variant intPoint has an upper bound (Ubound) value of 2 (0,1,2 implies x,y,z coords) - if they do not intersect the variant has Uboubnd=-1. I have used this property.

Also look at the other lines of code where they differ from yours - I leave it to you to understand why they were changed.

Code:
Sub BreakLine()
    Dim ssetObj As AcadSelectionSet
    On Error Resume Next
    ThisDrawing.SelectionSets("TEST_SSET").Delete
    On Error GoTo 0
    Set ssetObj = ThisDrawing.SelectionSets.Add("TEST_SSET")
    ssetObj.SelectOnScreen
    Dim newLine1 As AcadLine
    Dim intPoint As Variant
    intPoint = ssetObj.Item(0).IntersectWith(ssetObj.Item(1), acExtendNone)
    If UBound(intPoint) = 2 Then
        Set OldLine = ssetObj.Item(0)
        Set newLine1 = ThisDrawing.ModelSpace.AddLine(intPoint, OldLine.EndPoint)
        OldLine.EndPoint = intPoint
    End If
End Sub


Mala Singh
'Dare to Imagine'
 
An afterthought...

Apart from the method of testing if intPoint actually exists, please ignore the other changes in the code if they deviate the program flow from what you are trying to do.


Mala Singh
'Dare to Imagine'
 
Erezzo:

I know you posted this in April and I have responded in October - you might already have a solution to your problem or the specific query itself may be irrelevant at this point of time. (I see that you have not even marked this thread for e-mail notification - maybe you removed it after this was of no use to you)...

However, I would like to take this opportunity to make a point for others who are current help-seekers but do not respond to well-meaning replies to their queries:

When you post a query and someone responds to it in a non-casual way by way of being helpful, please give consideration to the fact that (having spent some effort in responding), the person responding would naturally want to know if his/her contribution was of any use..

Usually such a respondent flags a post for notification of any responses from the original/responding posters.

If there is no response from the original poster of the query in respect of usefulness/uselessness of his/her (respondents') sincere response, it is a discouraging factor.

As such, I'd suggest you (and all help seekers on all forums) - to respond to 'serious-looking' responses to threads initiated by you in one way or the other - this is in your own interest as a 'help-seeker'.

Remember that the respondent is not the one looking for help - usually he is a serious worker in the field of your query - and he is not getting anything (apart from your appreciation/goodwill) by spending time/effort responding to your 'HELP!!' posts...

I am hopeful that the forum management would do their bit to think of ways to convince help-seekers of the importance of following/responding to the threads initiated by them...
For one, they could make it impossible to post original threads which are not marked for email notification...






Mala Singh
'Dare to Imagine'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor