GreenBee Posted January 19, 2014 Share Posted January 19, 2014 Hi, I have drawn a line, an arc, and another line which make continuous object (endpoint of first line is the startpoint of an arc and endpoint of an arc is the startpoint of the second line). Problem occurs when I compare coordinates of an endopoint of the previous element to the startpoint of the next element. Something like this: if line1.endpoint(0)=arc1.startpoint(0) and line1.endpoint(1)=arc1.startpoint(1) then ... end if The program just skips that part of the code like the coordinates do not match. I've been busting my head with this for quite a while and can't find the solution. It becomes even more awkward because rarely it works just fine, and I haven't found the cause why it sometimes works and why in most of the cases it doesn't. And what amazes me the most is when I get him to write all the startpoints and all the endpoints of all the elements, they match perfectly, to the 11th decimal place. If someone knows the solution to this, I'd be most grateful. Thanks in advance Quote Link to comment Share on other sites More sharing options...
ReMark Posted January 19, 2014 Share Posted January 19, 2014 This "program" you are talking about is a custom lisp routine? Can you attach a copy to a subsequent post? Quote Link to comment Share on other sites More sharing options...
GreenBee Posted January 19, 2014 Author Share Posted January 19, 2014 I apologize, I forgot to mention the most important part. It's a vba code Quote Link to comment Share on other sites More sharing options...
GreenBee Posted January 19, 2014 Author Share Posted January 19, 2014 PocToc = ThisDrawing.Utility.GetPoint(, "Odaberite pocetnu tocku trase") ZadToc = ThisDrawing.Utility.GetPoint(, "Odaberite zadnju tocku trase") For Each SOS In ThisDrawing.SelectionSets If SOS.Name = "MySS" Then ThisDrawing.SelectionSets("MySS").Delete Exit For End If Next ThisDrawing.SelectionSets.Add ("MySS") Set objSS = ThisDrawing.SelectionSets("MySS") objSS.SelectOnScreen If objSS.Count Quote Link to comment Share on other sites More sharing options...
GreenBee Posted January 19, 2014 Author Share Posted January 19, 2014 For Each objent In objSS Select Case objent.ObjectName Case "AcDbLine" Set Pravac = objent L = L + Pravac.Length If (Pravac.StartPoint(0) = PocToc(0)) And (Pravac.StartPoint(1) = PocToc(1)) Then PrvaTocka(0) = PocToc(0) PrvaTocka(1) = PocToc(1) PrvaTocka(2) = PocToc(2) DrugaTocka(0) = Pravac.EndPoint(0) DrugaTocka(1) = Pravac.EndPoint(1) DrugaTocka(2) = Pravac.EndPoint(2) PlusMinus = True End If If (Pravac.EndPoint(0) = PocToc(0)) And (Pravac.EndPoint(1) = PocToc(1)) Then PrvaTocka(0) = PocToc(0) PrvaTocka(1) = PocToc(1) PrvaTocka(2) = PocToc(2) DrugaTocka(0) = Pravac.StartPoint(0) DrugaTocka(1) = Pravac.StartPoint(1) DrugaTocka(2) = Pravac.StartPoint(2) PlusMinus = True End If '<<<<<KRUZNI LUK>>>>> Case "AcDbArc" Set Luk = objent L = L + Luk.ArcLength Lluk = Luk.ArcLength Rluk = Luk.Radius PlusMinus = False 'Ako luk nije prvi element trase 'Ako je startpoint luka jednak drugoj tocki If Luk.StartPoint(0) = DrugaTocka(0) And Luk.StartPoint(1) = DrugaTocka(1) Then PrvaTocka(0) = Luk.StartPoint(0) PrvaTocka(1) = Luk.StartPoint(1) PrvaTocka(2) = Luk.StartPoint(2) DrugaTocka(0) = Luk.EndPoint(0) DrugaTocka(1) = Luk.EndPoint(1) DrugaTocka(2) = Luk.EndPoint(2) PlusMinus = True n = 10 End If 'Ako je endpoint luka jednak drugoj tocki If Luk.EndPoint(0) = DrugaTocka(0) And Luk.EndPoint(1) = DrugaTocka(1) Then PrvaTocka(0) = Luk.EndPoint(0) PrvaTocka(1) = Luk.EndPoint(1) PrvaTocka(2) = Luk.EndPoint(2) DrugaTocka(0) = Luk.StartPoint(0) DrugaTocka(1) = Luk.StartPoint(1) DrugaTocka(2) = Luk.StartPoint(2) PlusMinus = True n = 12 End If If PlusMinus = True Then 'pocetna tocka luka Set linija1 = ThisDrawing.ModelSpace.AddLine(PrvaTocka, Luk.Center) Set Krug = ThisDrawing.ModelSpace.AddCircle(PrvaTocka, SirCest / 3.5) sjeciste = linija1.IntersectWith(Krug, acExtendNone) Krug.Delete linija1.Delete Set PopLin = ThisDrawing.ModelSpace.AddLine(PrvaTocka, sjeciste) PopLin.Copy PopLin.Move sjeciste, PrvaTocka Set Kruzic = ThisDrawing.ModelSpace.AddCircle(PrvaTocka, SirCest / 3.5) 'sredisnja tocka luka Set linija1 = ThisDrawing.ModelSpace.AddLine(PrvaTocka, Luk.Center) Set linija2 = ThisDrawing.ModelSpace.AddLine(DrugaTocka, Luk.Center) linija1.Rotate PrvaTocka, pi / 2 linija2.Rotate DrugaTocka, pi / 2 sjeciste = linija1.IntersectWith(linija2, acExtendBoth) linija1.Delete linija2.Delete Set linija2 = ThisDrawing.ModelSpace.AddLine(sjeciste, Luk.Center) SredisnjaTockaLuka = linija2.IntersectWith(Luk, acExtendNone) linija2.Delete Set Krug = ThisDrawing.ModelSpace.AddCircle(SredisnjaTockaLuka, SirCest / 3.5) Set linija1 = ThisDrawing.ModelSpace.AddLine(SredisnjaTockaLuka, Luk.Center) sjeciste = linija1.IntersectWith(Krug, acExtendNone) Krug.Delete linija1.Delete Set PopLin = ThisDrawing.ModelSpace.AddLine(SredisnjaTockaLuka, sjeciste) PopLin.Copy PopLin.Move sjeciste, SredisnjaTockaLuka Set Kruzic = ThisDrawing.ModelSpace.AddCircle(SredisnjaTockaLuka, SirCest / 3.5) '------>Ostali profili na luku 'Ako je luk duzi od razmaka profila If Lluk > RazProf Then Alfa = (Lostatak * 180) / pi * Rluk ThisDrawing.Utility.Prompt Alfa & vbCrLf Set linija1 = ThisDrawing.ModelSpace.AddLine(Luk.Center, PrvaTocka) linija1.Rotate Alfa sjeciste2 = linija1.IntersectWith(Luk, acExtendNone) If sjeciste2(0) = 0 And sjeciste2(1) = 0 Then Alfa = -1 * Alfa linija1.Rotate (2 * Alfa) sjeciste2 = linija1.IntersectWith(Luk, acExtendNone) End If linija1.Delete Set linija1 = ThisDrawing.ModelSpace.AddLine(sjeciste2, Luk.Center) Set Krug = ThisDrawing.ModelSpace.AddCircle(sjeciste2, SirCest / 3.5) sjeciste = linija1.IntersectWith(Krug, acExtendNone) Krug.Delete linija1.Delete Set PopLin = ThisDrawing.ModelSpace.AddLine(sjeciste2, sjeciste) PopLin.Copy PopLin.Move sjeciste, sjeciste2 Set Kruzic = ThisDrawing.ModelSpace.AddCircle(PrvaTocka, SirCest / 3.5) End If PlusMinus = False End If End Select Next Quote Link to comment Share on other sites More sharing options...
GreenBee Posted January 19, 2014 Author Share Posted January 19, 2014 Sorry for the messy posts Quote Link to comment Share on other sites More sharing options...
ReMark Posted January 19, 2014 Share Posted January 19, 2014 Maybe a moderator can clean things up and put this thread in the proper forum. Sorry, I have no experience using VBA. Quote Link to comment Share on other sites More sharing options...
GreenBee Posted January 20, 2014 Author Share Posted January 20, 2014 Hi, I have drawn a line, an arc, and another line which make continuous object (endpoint of first line is the startpoint of an arc and endpoint of an arc is the startpoint of the second line). Problem occurs when I compare coordinates of an endopoint of the previous element to the startpoint of the next element using VBA code. Something like this: if line1.endpoint(0)=arc1.startpoint(0) and line1.endpoint(1)=arc1.startpoint(1) then ... end if The program just skips that part of the code like the coordinates do not match. I've been busting my head with this for quite a while and can't find the solution. It becomes even more awkward because on some occasions it works just fine, and I haven't found the cause why it sometimes works and why in most of the cases it doesn't. And what amazes me the most is when I get VBA to write all the startpoints and all the endpoints of all the elements, they match perfectly, to the 11th decimal place. If someone knows the solution to this, I'd be most grateful. Thanks in advance Quote Link to comment Share on other sites More sharing options...
Tyke Posted January 20, 2014 Share Posted January 20, 2014 The problem lies in that the coordinates do not match EXACTLY, there is a very, very small difference. The coordinates you see are to a certain precision, but when values are calculated their precision is sometimes more than that displayed. Although they look the same they are not. Try something that introduces a fuzzy match, something like: If Abs(line1.EndPoint(0) - arc1.StartPoint(0) < 0.00001 _ And Abs(line1.EndPoint(1) - arc1.StartPoint(0) < 0.00001 Then The rest of your code end If Quote Link to comment Share on other sites More sharing options...
GreenBee Posted January 20, 2014 Author Share Posted January 20, 2014 Thank you for quick response. I will sure try it. Quote Link to comment Share on other sites More sharing options...
SLW210 Posted January 20, 2014 Share Posted January 20, 2014 I merged your two posts. 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.