<?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: new_entity_name in PowerShape and PowerMill API Forum</title>
    <link>https://forums.autodesk.com/t5/powershape-and-powermill-api/new-entity-name/m-p/7339228#M1277</link>
    <description>&lt;P&gt;I admit I haven't made use of this feature before in macros.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the example you show at the end of your post, the tool you create will already use the next available name. &amp;nbsp;i.e. "1". &amp;nbsp;So I am confused as to exactly what this function will give you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry for not understanding!&lt;/P&gt;</description>
    <pubDate>Wed, 30 Aug 2017 14:20:07 GMT</pubDate>
    <dc:creator>luke.edwards.autodesk</dc:creator>
    <dc:date>2017-08-30T14:20:07Z</dc:date>
    <item>
      <title>new_entity_name</title>
      <link>https://forums.autodesk.com/t5/powershape-and-powermill-api/new-entity-name/m-p/7336711#M1272</link>
      <description>&lt;P&gt;Via the macro language we can have the next name that will be generated for the given entity type via the function &lt;STRONG&gt;new_entity_name&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Does a similar function or method exists in the current API ?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2017 17:37:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/powershape-and-powermill-api/new-entity-name/m-p/7336711#M1272</guid>
      <dc:creator>5axes</dc:creator>
      <dc:date>2017-08-29T17:37:41Z</dc:date>
    </item>
    <item>
      <title>Re: new_entity_name</title>
      <link>https://forums.autodesk.com/t5/powershape-and-powermill-api/new-entity-name/m-p/7336783#M1273</link>
      <description>&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN&gt;The code below should solve your problem, however, there may be a way to get this value through the API.&lt;/SPAN&gt;&lt;BR /&gt;For all cases where the API does not have the desired function, use the code below as the base (alternative method):&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;C#:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;string new_boundary = powerMILL.ExecuteEx(@"STRING $temp = new_entity_name('boundary')
                                            PRINT $temp
					    RESET LOCALVARS").ToString();&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Aug 2017 18:00:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/powershape-and-powermill-api/new-entity-name/m-p/7336783#M1273</guid>
      <dc:creator>rafael.sansao</dc:creator>
      <dc:date>2017-08-29T18:00:14Z</dc:date>
    </item>
    <item>
      <title>Re: new_entity_name</title>
      <link>https://forums.autodesk.com/t5/powershape-and-powermill-api/new-entity-name/m-p/7338077#M1274</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you don't want to use Execute commands (we usually try to avoid them) the next code should do what you want (example for a pattern):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;string newname = session.Patterns.CreateEmptyPattern().Name;&lt;BR /&gt;session.Patterns.ActiveItem.Delete();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you are working with other entity type (toolpath, boundary,...) just change Patterns to Toolpath or Boundary or whatever, following the Powermill API commands.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope it helps!&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 06:19:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/powershape-and-powermill-api/new-entity-name/m-p/7338077#M1274</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-08-30T06:19:34Z</dc:date>
    </item>
    <item>
      <title>Re: new_entity_name</title>
      <link>https://forums.autodesk.com/t5/powershape-and-powermill-api/new-entity-name/m-p/7338917#M1275</link>
      <description>&lt;P&gt;Both good solutions to the question. &amp;nbsp;But I just wondered why you want this functionality? &amp;nbsp;I'm interested in the context of the problem that 5axes is trying to solve.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 12:44:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/powershape-and-powermill-api/new-entity-name/m-p/7338917#M1275</guid>
      <dc:creator>luke.edwards.autodesk</dc:creator>
      <dc:date>2017-08-30T12:44:33Z</dc:date>
    </item>
    <item>
      <title>Re: new_entity_name</title>
      <link>https://forums.autodesk.com/t5/powershape-and-powermill-api/new-entity-name/m-p/7339066#M1276</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;luke.edwards.autodesk a écrit&amp;nbsp;:&lt;BR /&gt;
&lt;P&gt;Both good solutions to the question. &amp;nbsp;But I just wondered why you want this functionality? &amp;nbsp;I'm interested in the context of the problem that 5axes is trying to solve.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Thanks @Anonymous.edwards.Autodesk&amp;nbsp;for your answer and your interest in our problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Well for&amp;nbsp;the same situation as in the Macro language.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In Vb.net if I need to copy a tool , it's easy to get the New_entity_name :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Dim&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; new_entity_name &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;As&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Consolas" size="2"&gt;String&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; = Newtool.Duplicate().Name&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But&amp;nbsp; if I want to create a new tool&amp;nbsp; and if a tool wih the same name already exists in the project,&amp;nbsp; I need to get a non existing&amp;nbsp;name. Ie :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Dim&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; Newtool &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;As&lt;/FONT&gt; &lt;FONT color="#2b91af" face="Consolas" size="2"&gt;PMTool&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; = List_Tool.CreateBallNosedTool&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Consolas" size="2"&gt;Newtool.Name = &lt;/FONT&gt;&lt;FONT color="#a31515" face="Consolas" size="2"&gt;"BN-1/2"&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Newtool = List_Tool.CreateBallNosedTool&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Consolas" size="2"&gt;Newtool.Name = &lt;/FONT&gt;&lt;FONT color="#a31515" face="Consolas" size="2"&gt;"BN-1/2"&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#a31515" face="Consolas" size="2"&gt;&lt;FONT color="#000000"&gt;In this case the second tool will keep is original name -&amp;gt; &lt;STRONG&gt;1 &lt;/STRONG&gt;and&amp;nbsp;I don't have any message or error concerning the success of the "rename" operation.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#a31515" face="Consolas" size="2"&gt;&lt;FONT color="#000000"&gt;&lt;STRONG&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="rename_tool.jpg" style="width: 205px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/395765i598477F401569AD0/image-size/large?v=v2&amp;amp;px=999" role="button" title="rename_tool.jpg" alt="rename_tool.jpg" /&gt;&lt;/span&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#a31515" face="Consolas" size="2"&gt;&lt;FONT color="#000000"&gt;I can of course test if a tool already exists :&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;If&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; IsNothing(List_Tool.GetByName(&lt;/FONT&gt;&lt;FONT color="#a31515" face="Consolas" size="2"&gt;"BN-1/2"&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;)) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Then&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Consolas" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Newtool.Name = &lt;/FONT&gt;&lt;FONT color="#a31515" face="Consolas" size="2"&gt;"BN-1/2"&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Else&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; new_entity_name &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;As&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Consolas" size="2"&gt;String&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; = List_Tool.GetByName(&lt;/FONT&gt;&lt;FONT color="#a31515" face="Consolas" size="2"&gt;"BN-1/2"&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;).Duplicate().Name&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; List_Tool.GetByName(new_entity_name).Delete()&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Newtool.Name = new_entity_name&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;End&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Consolas" size="2"&gt;If&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#a31515" face="Consolas" size="2"&gt;&lt;FONT color="#000000"&gt;But a function like &lt;FONT face="Consolas" size="2"&gt;&lt;STRONG&gt;new_entity_name&lt;/STRONG&gt; would be usefull to get directly the new free name. &lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 13:31:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/powershape-and-powermill-api/new-entity-name/m-p/7339066#M1276</guid>
      <dc:creator>5axes</dc:creator>
      <dc:date>2017-08-30T13:31:33Z</dc:date>
    </item>
    <item>
      <title>Re: new_entity_name</title>
      <link>https://forums.autodesk.com/t5/powershape-and-powermill-api/new-entity-name/m-p/7339228#M1277</link>
      <description>&lt;P&gt;I admit I haven't made use of this feature before in macros.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the example you show at the end of your post, the tool you create will already use the next available name. &amp;nbsp;i.e. "1". &amp;nbsp;So I am confused as to exactly what this function will give you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry for not understanding!&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 14:20:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/powershape-and-powermill-api/new-entity-name/m-p/7339228#M1277</guid>
      <dc:creator>luke.edwards.autodesk</dc:creator>
      <dc:date>2017-08-30T14:20:07Z</dc:date>
    </item>
    <item>
      <title>Re: new_entity_name</title>
      <link>https://forums.autodesk.com/t5/powershape-and-powermill-api/new-entity-name/m-p/7339353#M1278</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;luke.edwards.autodesk a écrit&amp;nbsp;:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the example you show at the end of your post, the tool you create will already use the next available name. &amp;nbsp;i.e. "1". &amp;nbsp;So I am confused as to exactly what this function will give you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry for not understanding!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;As English is not a mother tongue, it may be difficult for me to explain my needs in some cases &lt;img id="smileywink" class="emoticon emoticon-smileywink" src="https://forums.autodesk.com/i/smilies/16x16_smiley-wink.png" alt="Smiley Wink" title="Smiley Wink" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So we will try via a common langage. &amp;nbsp;How to translate this MACRO code into an API code :&lt;/P&gt;
&lt;PRE&gt;DIALOGS MESSAGE OFF
DIALOGS ERROR OFF

STRING New_Name='BN-1/2'

IF ENTITY_EXISTS('Tool',$New_Name) {
	$New_Name=NEW_ENTITY_NAME('Tool','BN-1/2')
}

CREATE TOOL $New_Name BALLNOSED&lt;/PRE&gt;
&lt;P&gt;where&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;$New_Name=NEW_ENTITY_NAME('Tool','BN-1/2')&lt;/PRE&gt;
&lt;P&gt;Will be as simple as possible. &amp;nbsp;If you run several times this macro the result will be :&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Result.jpg" style="width: 173px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/395813iAC8EC371C3011A76/image-size/large?v=v2&amp;amp;px=999" role="button" title="Result.jpg" alt="Result.jpg" /&gt;&lt;/span&gt; &amp;nbsp;etc. etc ..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 14:54:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/powershape-and-powermill-api/new-entity-name/m-p/7339353#M1278</guid>
      <dc:creator>5axes</dc:creator>
      <dc:date>2017-08-30T14:54:19Z</dc:date>
    </item>
    <item>
      <title>Re: new_entity_name</title>
      <link>https://forums.autodesk.com/t5/powershape-and-powermill-api/new-entity-name/m-p/7339400#M1279</link>
      <description>&lt;P&gt;Excellent! &amp;nbsp;Now I understand perfectly!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Dim baseName = "BN-1/2"
Dim newName = baseName
Dim counter = 1
While activeProject.Tools.GetByName(newName) IsNot Nothing
  newName = baseName &amp;amp; "_" &amp;amp; counter
  counter = counter + 1
End While
' Now create the tool&lt;/PRE&gt;
&lt;P&gt;This should do what you need. &amp;nbsp;But yes, it is cumbersome. &amp;nbsp;I will look to get the API updated.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 15:03:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/powershape-and-powermill-api/new-entity-name/m-p/7339400#M1279</guid>
      <dc:creator>luke.edwards.autodesk</dc:creator>
      <dc:date>2017-08-30T15:03:10Z</dc:date>
    </item>
    <item>
      <title>Re: new_entity_name</title>
      <link>https://forums.autodesk.com/t5/powershape-and-powermill-api/new-entity-name/m-p/7341159#M1280</link>
      <description>&lt;P&gt;Even though Luke's solution is perfect, I've thought another way to do what you want. Instead of looping over all the tools that may have the same root name, it could be interesting take advantage of the Duplicate function, that acually does exactly what you want. If you have two tools called "BN-25" and "BN-25_1" and you duplicate the tool BN-25, PowerMill automatically check if the names BN-25_1, BN-25_2,... are already being used&amp;nbsp;and it creates the tool copy with the first available name. Therefore, the next code might be interesting:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;string toolname = "BN-25";
if (session.Tools.GetByName(toolname) != null)
{
//Create the new tool called BN-25_i ( i being 1,2,3,... the first number available) and saved its name in a string 
string new_tool_name = session.Tools.GetByName(toolname).Duplicate().Name;
} else
{
//Create the new tool and automatically changes it name to "BN-25"
session.Tools.CreateBallNosedTool().Name = toolname;
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope it helps!&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2017 06:44:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/powershape-and-powermill-api/new-entity-name/m-p/7341159#M1280</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-08-31T06:44:50Z</dc:date>
    </item>
  </channel>
</rss>

