What should be used as entity ID

<< Click to Display Table of Contents >>

Navigation:  How To >

What should be used as entity ID

Each Entity as well as each Class has a unique identification: 64bit digital Handle which stays the same after saving to file and changing the entity.

Handles are convenient IDs to work with the entities. For instance, we sign to the OnSelectEntity event:

<?xml version="1.0" encoding="UTF-8"?>
<cadsofttools version="2.0">
  <!-- Sign to OnSelectEntity event. Handle in result will be the last selected entity. All the selected entities can be accessed through calling "GetSelected" command, see GetSelected.xml -->
  <signtoevent Event="OnSelectEntity"/>
</cadsofttools>

 

When we click on any entity, we get its handle in the result parameter:

<cadsofttools version="2.0">
  <selectEntities>
     <result handle="$2B"/>
  </selectEntities>
</cadsofttools>  

 

After it we can use this handle handle="$2B" to work with the entity.

If we add the entity, the application creates a new Handle automatically and it is not possible to set Handle. This is the problem because when we add an entity, we do not know its handle.

Solution:

Use the HandleSave parameter with "@UniqueDigit"when you add an entity and then it can be called as the Handle alias.

Example, Add3.xml:

<?xml version="1.0" encoding="utf-8"?>
<cadsofttools version="2.0">
  <!-- Description: Example shows how to work with HandleSave -->  
  <add>    
     <cstText point="10,10,0" Text="HandleSave is @77" Height="3" HandleSave="@77" />  
  </add>            
  <!-- Handle alias @77 can be used for select and other instructions -->
  <select Handle="@77" />
  <apply Color="0;1;"/>    
  <FitToSize/>                      
  <!-- Sign to OnSelectEntity event. Handle in result will be the last selected entity. If you press entity which is created in this example, result will be its real Handle. -->
  <signtoevent Event="OnSelectEntity"/>
</cadsofttools>  

Go to CADEditorX