<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Preventing Divide by Zero, problem with IF?]]></title><description><![CDATA[<p dir="auto">Hi All</p>
<p dir="auto">I'm a comparative newbie to sketchup and complete newbie to this forum.  I have searched this forum as best I can and have found a couple of other people who have a similar problem but no solution.  I'm hoping someone out there has worked this out.</p>
<p dir="auto">I have a simple component with a single custom attribute - angle.</p>
<p dir="auto">I then use LenX/TAN(angle) to work out LenY</p>
<p dir="auto">This works fine except when angle=90, because TAN(90) is undefined.</p>
<p dir="auto">In this case I would like to set LenY=0</p>
<p dir="auto">So I tried something like</p>
<p dir="auto">LenY = IF(angle=90,0,LenX/TAN(angle))</p>
<p dir="auto">and</p>
<p dir="auto">LenY = IF(angle&lt;90,LenX/TAN(angle),0)</p>
<p dir="auto">In both cases sketchup evaluates the part of the IF statement not required and causes an error.</p>
<p dir="auto">I have solved this problem by evaluating the other angle in the triangle</p>
<p dir="auto">ie</p>
<p dir="auto">LenY = LenX*TAN(90-angle)</p>
<p dir="auto">but I wonder why the IF method didn't work and if anyone out there has any alternative methods to implement this sort of defensive programming to prevent divide by zero</p>
<p dir="auto">IF(attrib1=0,0,attrib2/attrib1)</p>
<p dir="auto">I know others have the same problem, surely this should be easy</p>
<p dir="auto">anyway thanxs in advance, I love Sketchup and this site looks great!</p>
]]></description><link>https://community.sketchucation.com/topic/134284/preventing-divide-by-zero-problem-with-if</link><generator>RSS for Node</generator><lastBuildDate>Sun, 19 Apr 2026 05:36:21 GMT</lastBuildDate><atom:link href="https://community.sketchucation.com/topic/134284.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 05 Apr 2012 16:12:58 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Preventing Divide by Zero, problem with IF? on Thu, 05 Apr 2012 22:06:40 GMT]]></title><description><![CDATA[<p dir="auto">daredevil</p>
<p dir="auto">yeh I saw your bridge, very impressive work.  My models are a lot more humble but I aspire to create complex dynamic components.  That is the reason why I would like to find out how to do these things nicely and elegantly.</p>
<p dir="auto">I presume the IF problem we both had is a problem with the way sketchup parses the IF function.  I have a little experience with C++ from 20 years ago and would have expected it to work.</p>
<p dir="auto">Anyway I am wondering if I should learn Ruby and if these sort of things can be done in that.  I am frustrated with the way you enter formulas in the dynamic component attributes dialogue, it works fine for simple components but it is difficult to read complex nested functions in such a small text box.  Sometimes I have resorted to copy/paste into notepad, and use indentation to help match parenthesis and make it clearer and then copy/paste back.  It would also be nice to be able to add comments.</p>
<p dir="auto">From seeing the bridge you've made you're obviously well ahead of me. I would like to produce fully configurable pieces of furniture and joinery for my business.  Do you think I should persevere with Dynamic Components or will I discover that their limitations mean I should learn the Sketchup Ruby API?</p>
<p dir="auto">Again very impressive work you do, it would give me a real kick to produce something half as good as that  <img src="https://community.sketchucation.com/assets/plugins/nodebb-plugin-emoji/emoji/android/2600.png?v=6529dfcbe5e" class="not-responsive emoji emoji-android emoji--sunny" style="height:23px;width:auto;vertical-align:middle" title=":sunny:" alt="☀" /></p>
]]></description><link>https://community.sketchucation.com/post/1320296</link><guid isPermaLink="true">https://community.sketchucation.com/post/1320296</guid><dc:creator><![CDATA[FlobRob]]></dc:creator><pubDate>Thu, 05 Apr 2012 22:06:40 GMT</pubDate></item><item><title><![CDATA[Reply to Preventing Divide by Zero, problem with IF? on Thu, 05 Apr 2012 19:32:30 GMT]]></title><description><![CDATA[<p dir="auto">Hello,<br />
I had the same problem with a A/sin(B) when B = 0.<br />
I turned and turned to found a solution...<br />
Look at this <a href="http://forums.sketchucation.com/viewtopic.php?f" target="_blank" rel="noopener noreferrer nofollow ugc">thread</a></p>
]]></description><link>https://community.sketchucation.com/post/1320276</link><guid isPermaLink="true">https://community.sketchucation.com/post/1320276</guid><dc:creator><![CDATA[DareDevil]]></dc:creator><pubDate>Thu, 05 Apr 2012 19:32:30 GMT</pubDate></item></channel></rss>