RoboCatz.com
About FLL | Navigation | Playbook | Strategy | Models | Techniques | RobotC | Programming | Robot News |

Part Extractor

This script can be used to extract data from the parts used to construct models that are added to the Roblox worlds through the toolbox menu(s).

Add a Script to the Model

When a model is added to your world through the toolbox menu, you can view the model and its parts by using the Explorer panel and accessing the Workspace item at the top of the list. Click on the triangle next to the model you added. Then click on the 'plus' sign to add a "script" to the model. Copy and paste the code below into the newly created script. Then run your world. This script will create text in the output panel. You can copy the text generated into other worlds where you have loaded the module scripts to create and manipulate basic shapes.

Extracting Data from Parts

Add this script to any model to extract data from the model's parts.

Example:
--[[ Part Extractor Script
This script should be added to a model that you wish to extract the parts.
This script will analyze all of the parts of that model by iterating through an array of the part's children.
Attributes of each part (such as size, color, position, rotation, etc) will be assigned to temporary variables for used in generating a result string.
The result string will be created by concatenating all of the attributes you wish to include.  Feel free to modify these attributes as desired.
The result string will be printed to the console (Output) panel.
The process being performed here is similar to 'compilation' where a program written in one language 
  analyzes content from another language and then outputs a translation in a 3rd language.
]]
print("Starting part extractor")
local myParent = script.Parent
local extractedParts = myParent:GetChildren()
function round(num, numDecimalPlaces)
	return tonumber(string.format("%." .. (numDecimalPlaces or 0) .. "f", num))
end
for i=1,#extractedParts do
	--print(extractedParts[i])
	if(extractedParts[i]:IsA("Part")) then
		local myPart = extractedParts[i]
		local myAnchorStatus = myPart.Anchored  -- Boolean
		local myPosition = myPart.Position      -- Vector3
		local myColor = myPart.Color            -- Color3
		local mySize = myPart.Size              -- Vector3
		local myRotation = myPart.Rotation      -- Vector3
		local cFrame = myPart.CFrame
		local result = ``                       -- Initialize empty result string
		result = result .. `x={round(cFrame.p.x,2)},y={round(cFrame.p.y,2)},z={round(cFrame.p.z,2)}, `  -- Add the position as x,y,z parameters based on the cFrame position's x,y,z
		result = result .. `color=Color3.new({round(myColor.r,2)},{round(myColor.g,2)},{round(myColor.b,2)}), `  -- Add the color as r,g,b
		result = result .. `material={myPart.Material}, `  -- Add the material as a String
		result = result .. `rotateBy=Vector3.new({myRotation.x},{myRotation.y},{myRotation.y}), `  -- Add the rotation
		result = result .. `size=Vector3.new({round(mySize.x,2)},{round(mySize.y,2)},{round(mySize.y,2)}), `  -- Add the size
		result = result .. `dummy='' `  -- Add the size
		print(`s.cube(\{`.. result .. ` \})`)
	end
end