<?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: Creating multiple keyframes in 3ds Max Programming Forum</title>
    <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/creating-multiple-keyframes/m-p/10940384#M4520</link>
    <description>&lt;P&gt;for what reason you&lt;/P&gt;&lt;P&gt;a) always "select" nodes?&lt;/P&gt;&lt;P&gt;b) do "pCable.pos=pM" right before clearselection() ?&lt;/P&gt;&lt;P&gt;Besides, I'd use a different solution by sphere/line intersection.&lt;/P&gt;</description>
    <pubDate>Wed, 09 Feb 2022 21:45:35 GMT</pubDate>
    <dc:creator>istan</dc:creator>
    <dc:date>2022-02-09T21:45:35Z</dc:date>
    <item>
      <title>Creating multiple keyframes</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/creating-multiple-keyframes/m-p/10934890#M4519</link>
      <description>&lt;P&gt;I created the following code to calculate the location of the end of a boom from a bus (trolley) to an overhead cable.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="leeminardi_0-1644275181233.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1021998i1FC1E1B7E71AE003/image-size/medium?v=v2&amp;amp;px=400" role="button" title="leeminardi_0-1644275181233.png" alt="leeminardi_0-1644275181233.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;-- positions PointCable on line001 a distance LabelControl
-- from PointBus
-- v .01 2/6/2022 L. Minardi
clearlistener()
fn CalculateCablePoint =
(	
select $line001
cable = $
select $PointCable
pCable = $
sM = [0,0,0]
global delta = 0.1
global s = delta
global L= 20.
select $Bus
BusT = $.transform
select $PointBus
pBus = $.position 
sA = 0.0  -- % along value for A
sB = delta  -- initial % along guess for B
flag = true
pA = interpCurve3D cable 1 sA  -- point A 
pB = interpCurve3D cable 1 sB   -- point B
dA = distance pBus pA 
dB = distance pBus pB 
-- get to intervale containing solution
for i = 1 to 10 while flag do
(if dB &amp;gt; L then
  (
	pA = pB 
    sA = sB
    sB = sB + delta
	pB =  interpCurve3D cable 1 sB
	dB = distance pBus pB 
  )	
else
  ( flag = false
  )
  )
-- interval found, now iterate between A and B
flag = true
for i = 1 to 5 while flag do
(
  sM = (sA + sB)/2.
  pM =  interpCurve3D cable 1 sM
  dM = distance pBus pM
  err = abs(dm - L) 
  if (err &amp;lt; (0.01 * L)) then 
  (	flag = false	
   format ("i = %, error = %   ") i err
  )
if dM &amp;lt; L then
(
   pB = pM
   sB = sM 
)	
else
(
   pA = pM 
   sA = sM 
)
) -- end for
pCable.pos = pM
)  
CalculateCablePoint()
  
  &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp; It works for a single location of the bus.&amp;nbsp; I am trying to enhance it to generate keyframes as the bus moves.&amp;nbsp; I have tried adding a For loop for the entire program&amp;nbsp; and then the following statements to create keyframes at the end of the code. Note, pM is the point location of for the point object PointCable which the boom references with a LookAT constraint.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;	select $PointCable
	pCable = $
	slidertime = j
	with animate on
	pCable.pos = pM&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;The keyframes are created but they are all the location and do not track along the cable as the bus moves.&amp;nbsp; Here's the version with the loop.&amp;nbsp; Any suggestion as to how to get it to generate keyframes for each calculation of pM?&lt;/P&gt;&lt;LI-CODE lang="general"&gt;-- positions PointCable on line001 a distance LabelControl
-- from PointBus
-- v .02 2/7/2022 L. Minardi
clearlistener()
clearSelection
--fn cp =
--(	
--with animate on	
for j = 1 to 15 do
 (	
	select $line001
	cable = $
	select $PointCable
	pCable = $
	sM = [0,0,0]
	global delta = 0.1
	global s = delta
	global L= 20.
	select $Bus
	BusT = $.transform
	select $PointBus
	pBus = $.position 
	sA = 0.0
	sB = delta
	flag = true
	pA = interpCurve3D cable 1 sA
	pB = interpCurve3D cable 1 sB
	dA = distance pBus pA 
	dB = distance pBus pB 
	-- get to intervale containing solution
	for i = 1 to 10 while flag do
		(if dB &amp;gt; L then
		  (
			pA = pB 
			sA = sB
			sB = sB + delta
			pB =  interpCurve3D cable 1 sB
			dB = distance pBus pB 
		  )	
		else
		  ( flag = false
		  )
		)
	-- now iterate between A and B
	flag = true
	for i = 1 to 5 while flag do
	(
		sM = (sA + sB)/2.
		pM =  interpCurve3D cable 1 sM
		dM = distance pBus pM
		err = abs(dm - L) 
		if (err &amp;lt; (0.01 * L)) then 
			(	flag = false	
				format ("i = %, error = %   ") i err
			)
		if dM &amp;lt; L then
			(
			pB = pM
			sB = sM 
			)	
			else
			(
			pA = pM 
			sA = sM 
			)
	) -- end for

	pCable.pos = pM
	clearselection()
	select $PointCable
	pCable = $
	slidertime = j
	with animate on
	pCable.pos = pM

) -- end for j
&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Feb 2022 23:12:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/creating-multiple-keyframes/m-p/10934890#M4519</guid>
      <dc:creator>leeminardi</dc:creator>
      <dc:date>2022-02-07T23:12:35Z</dc:date>
    </item>
    <item>
      <title>Re: Creating multiple keyframes</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/creating-multiple-keyframes/m-p/10940384#M4520</link>
      <description>&lt;P&gt;for what reason you&lt;/P&gt;&lt;P&gt;a) always "select" nodes?&lt;/P&gt;&lt;P&gt;b) do "pCable.pos=pM" right before clearselection() ?&lt;/P&gt;&lt;P&gt;Besides, I'd use a different solution by sphere/line intersection.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Feb 2022 21:45:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/creating-multiple-keyframes/m-p/10940384#M4520</guid>
      <dc:creator>istan</dc:creator>
      <dc:date>2022-02-09T21:45:35Z</dc:date>
    </item>
    <item>
      <title>Re: Creating multiple keyframes</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/creating-multiple-keyframes/m-p/10940602#M4521</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/203084"&gt;@istan&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;for what reason you&lt;/P&gt;&lt;P&gt;a) always "select" nodes?&lt;/P&gt;&lt;P&gt;b) do "pCable.pos=pM" right before clearselection() ?&lt;/P&gt;&lt;P&gt;Besides, I'd use a different solution by sphere/line intersection.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/203084"&gt;@istan&lt;/a&gt;&amp;nbsp;thank you for your comments.&amp;nbsp; &amp;nbsp;My post was to help me in solving a bigger problem that is better described in &lt;A href="https://forums.autodesk.com/t5/3ds-max-programming/point-on-path-world-coordinates-for-several-values-of-percent/m-p/10938005/highlight/false#M28385" target="_blank" rel="noopener"&gt;this&lt;/A&gt; thread. With help from&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1634609"&gt;@denisT.MaxDoctor&lt;/a&gt;&amp;nbsp;the need for generating keyframes has been eliminated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As for using a "sphere/line intersection" approach the task is more complex if by "line" you meant straight line.. The path is a spline and there may be multiple solutions or none at all. I think a numerical solution works best in such a situation.&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Feb 2022 23:15:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/creating-multiple-keyframes/m-p/10940602#M4521</guid>
      <dc:creator>leeminardi</dc:creator>
      <dc:date>2022-02-09T23:15:57Z</dc:date>
    </item>
  </channel>
</rss>

