<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Converting Splines to Flattened Bezier Curves in Visual LISP, AutoLISP and General Customization Forum</title>
    <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/converting-splines-to-flattened-bezier-curves/m-p/8086522#M103266</link>
    <description>Yes, but like I mentioned, using "SendCommand" is not an option in this case.&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Fri, 22 Jun 2018 21:08:26 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2018-06-22T21:08:26Z</dc:date>
    <item>
      <title>Converting Splines to Flattened Bezier Curves</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/converting-splines-to-flattened-bezier-curves/m-p/8086365#M103264</link>
      <description>&lt;P&gt;Background:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;I am using python to modify elements in large AutoCAD files. I want to make changes to entities without using the "sendCommand" function. The end resulting drawings cannot contain any splines, among other things. In order to accomplish this I am converting the splines to flattened Bezier Curves (PolyLine). Image 1 helps illustrate this idea.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Image 1: Flattened Bezier Curve, Source:&amp;nbsp;https://pomax.github.io/bezierinfo/" style="width: 300px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/515266i9E1232334B432C57/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Image 1: Flattened Bezier Curve, Source:&amp;nbsp;https://pomax.github.io/bezierinfo/" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Image 1: Flattened Bezier Curve, Source:&amp;nbsp;https://pomax.github.io/bezierinfo/&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Problem:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;I succeeded in creating flattened Bezier Curves, although above degree 3, splines in AutoCAD no longer resemble Bezier Curves as seen below.&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Degree 3 Spline CV resembles flattened Bezier Curve" style="width: 967px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/515273i632D8C1F5F19B209/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Degree 3 Spline CV resembles flattened Bezier Curve" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Degree 3 Spline CV resembles flattened Bezier Curve&lt;/span&gt;&lt;/span&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Degree 4 curve does not match flattened Bezier Curve" style="width: 999px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/515274i15F045AE2A2833FD/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Degree 4 curve does not match flattened Bezier Curve" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Degree 4 curve does not match flattened Bezier Curve&lt;/span&gt;&lt;/span&gt;Question:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;How does AutoCAD define splines over degree 4? It appears that the AutoCAD spline is weighted, but when I ask for the weights of the spline i get the following error.&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 913px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/515277iB1F4372B735F4B91/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for reading&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jun 2018 19:34:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/converting-splines-to-flattened-bezier-curves/m-p/8086365#M103264</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-06-22T19:34:04Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Splines to Flattened Bezier Curves</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/converting-splines-to-flattened-bezier-curves/m-p/8086439#M103265</link>
      <description>&lt;P&gt;Flakeh,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the SPLINEDIT command has an option 'convert to Polyline'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;moshe&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jun 2018 20:20:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/converting-splines-to-flattened-bezier-curves/m-p/8086439#M103265</guid>
      <dc:creator>Moshe-A</dc:creator>
      <dc:date>2018-06-22T20:20:14Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Splines to Flattened Bezier Curves</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/converting-splines-to-flattened-bezier-curves/m-p/8086522#M103266</link>
      <description>Yes, but like I mentioned, using "SendCommand" is not an option in this case.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 22 Jun 2018 21:08:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/converting-splines-to-flattened-bezier-curves/m-p/8086522#M103266</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-06-22T21:08:26Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Splines to Flattened Bezier Curves</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/converting-splines-to-flattened-bezier-curves/m-p/8086799#M103267</link>
      <description>&lt;P&gt;here is a lisp function to convert spline to polyline&lt;/P&gt;&lt;P&gt;can you send a command like this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SendCommnad("(spline-&amp;gt;pline entity)")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the obj argument can be VLA-OBJECT or ENAME&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;moshe&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;(defun spline-&amp;gt;pline (obj / execmd ;| local function |;)

 (defun execmd (ename)
  (command "._splinedit" ename "p" "")
 ); execmd
  
 (cond
  ((eq (type obj) 'VLA-OBJECT)
   (execmd (vlax-vla-object-&amp;gt;ename obj))
  ); case
  ((eq (type obj) 'ENAME)
   (execmd obj)
  ); case
  ( t
   (prompt "\nerror: invalid argument.")
  ); case
 ); cond
); spline-&amp;gt;pline

&lt;/PRE&gt;</description>
      <pubDate>Sat, 23 Jun 2018 05:53:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/converting-splines-to-flattened-bezier-curves/m-p/8086799#M103267</guid>
      <dc:creator>Moshe-A</dc:creator>
      <dc:date>2018-06-23T05:53:02Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Splines to Flattened Bezier Curves</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/converting-splines-to-flattened-bezier-curves/m-p/8090432#M103268</link>
      <description>&lt;P&gt;I ended up answering my own question. The splines used in AutoCAD are B-splines. You can use the knots and control points along with the scipy.interpolate module in python to calculate sample points.&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Polyline approximation of a spline. The circles represent the control points calculated" style="width: 999px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/515971iFE53868EB1453F14/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Polyline approximation of a spline. The circles represent the control points calculated" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Polyline approximation of a spline. The circles represent the control points calculated&lt;/span&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Original spline, degree 3, 7 control points" style="width: 894px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/515972i02BE8DA01300F511/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Original spline, degree 3, 7 control points" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Original spline, degree 3, 7 control points&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jun 2018 19:29:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/converting-splines-to-flattened-bezier-curves/m-p/8090432#M103268</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-06-25T19:29:26Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Splines to Flattened Bezier Curves</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/converting-splines-to-flattened-bezier-curves/m-p/8090791#M103269</link>
      <description>&lt;P&gt;This is the python code i used to convert the splines into polylines.&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's useful because, like someone mentioned a couple times, there is a SPLINEDIT command to convert splines to polylines, but I prefer not to use "SendCommand". This code allows you to accomplish the same thing without using "SendCommand". The logic is all there so whomever finds this helpful can just transcribe it to LISP or VBA.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;def my_B_spline(obj,resolution):
    knots=obj.knots
    points=obj.controlpoints
    degree=obj.degree
    mtx,numP=form_matrix(points)
    def N(i,p,u):
        if p==0:
            if knots[i]&amp;lt;=u&amp;lt;knots[i+1]:
                return 1
            else:
                return 0
        else:
            if not (knots[i+p]-knots[i])==0:
                eq1=(u-knots[i])/(knots[i+p]-knots[i])
            else:
                eq1=0
            if not (knots[i+p+1]-knots[i+1])==0:
                eq2=(knots[i+p+1]-u)/(knots[i+p+1]-knots[i+1])
            else:
                eq2=0
            
            return eq1*N(i,p-1,u)+eq2*N(i+1,p-1,u)
    output=mtx[0]
    for u in np.linspace(knots[0],knots[-1],num=resolution,endpoint=False)[1:]:
        nextPoint=np.array([0,0,0],dtype='float')
        print("new time called")
        for i in range(0,numP):
            nextPoint+=N(i,degree,u)*mtx[i]
        output=np.vstack([output,nextPoint])
    return np.vstack([output,mtx[-1]])&lt;/PRE&gt;&lt;P&gt;It takes a spline object and resolution(how many points you want to divide the spline into) and returns an array of sample points on the spline.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jun 2018 00:18:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/converting-splines-to-flattened-bezier-curves/m-p/8090791#M103269</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-06-26T00:18:49Z</dc:date>
    </item>
  </channel>
</rss>

