Bcc.GetSelectedEntities
Bcc.GetSelectedEntities(bIDsOnly)
Description
This function will return the data on the currently selected entities in the BobCAD graphics area.
Parameters
- bIDsOnly - boolean value
- true - will return a simple list of the entity ID's
- false - returns a table of the complete entity information.
Return
When true is passed as the input, the return will be a table:
retTable[i] containing the entity ID
When false is passed as the input, the return will be a table with keys for each entity type in the chain:
retTable[i].ID - the entity ID
retTable[i].SubIDs - a list containing a solid models sub entity ID's (faces, edges)
retTable[i].EntityData - a table containing the different data for each entity
Examples
Example showing the usage to obtain the selected entities ID's:
-- Get the selected entities in the workspace
retTable = Bcc.GetSelectedEntities(true)
-- If there were selected entities
if(retTable ~= nil) then
-- Get the total number of entities
local strInfo = "Total = "..retTable.ArraySize
-- Loop through the list getting the IDs
local i = 1
while (retTable[i] ~= nil) do
strInfo = strInfo.."\nEntity ID = "..retTable[i]
i = i + 1
end
-- Display the message box with the information
Bcc.ShowMessageBox(strInfo)
else
Bcc.ShowMessageBox("Nothing Selected!")
end
Result:
Example showing the usage to obtain the full entity info:
-- Get the selected entities in the workspace
retTable = Bcc.GetSelectedEntities(false)
-- If there were selected entities
if(retTable ~= nil) then
local strInfo = "Total = "..retTable.ArraySize
local i = 1
while (retTable[i] ~= nil) do
strInfo = strInfo.."\nEntity ID = "..retTable[i].ID;
local subIDs = retTable[i].SubIDs
if subIDs ~= nil then
strInfo = strInfo..", Number of Sub IDs = "..subIDs.ArraySize..", Sub ID List = {"
local iSub = 1
while subIDs[iSub] ~= nil do
if iSub ~= 1 then
strInfo = strInfo..", "
end
strInfo = strInfo..subIDs[iSub]
iSub = iSub + 1
end
strInfo = strInfo.."}"
end
local entData = retTable[i].EntityData
local strTmp = RecursiveStreamTable(entData)
if strTmp ~= nil then
strInfo = strInfo..strTmp
end
i = i + 1
end
-- Display the message box with the information
Bcc.ShowMessageBox(strInfo)
else
Bcc.ShowMessageBox("Nothing Selected!")
end
-- Build a string containing the entity ID's and all the entity information
function RecursiveStreamTable(tableData)
-- Validate the data is indeed a table and not empty
if(tableData ~= nil and type(tableData) == "table" ) then
local strInfo = " "
-- Loop through the table getting the key name and it's value
for k, v in pairs(tableData) do
if v ~= nil then
if type(v) == "table" then
local strTmp = RecursiveStreamTable(v)
if strTmp ~= nil then
if type(k) == "number" then
if k ~= 1 then
strInfo = strInfo..", "
end
strInfo = strInfo.."{"..strTmp.."}"
else
strInfo = strInfo..", " ..k.." = {"..strTmp.."}"
end
end
elseif type(v) == "boolean" then
strInfo = strInfo..", " ..k.." = "..(v and "true" or "false")
else
if type(k) == "number" then
if k ~= 1 then
strInfo = strInfo..", "
end
strInfo = strInfo..v
else
strInfo = strInfo..", " ..k.." = "..v
end
end
end
end
return strInfo
end
end
Result: