View Single Post
You're going to want to "make new task". (OmniPlan doesn't have any sort of tree stuff, tasks just have more tasks as children.) The code snippet below is copying tasks from one OmniPlan file to another, but if you replace all the stuff referring to "oldTask" with code that talks to OmniFocus, you'll be getting fairly close to what you want. This code was pulled out of the "Join Projects" script on our extras page, so you might look there for more example code.

Since OmniFocus and OmniPlan both use the term 'task' but don't mean exactly the same thing, make extra sure that you're "using terms from" the correct application.

Code:
on copyTask(oldTask, newParent, destProject)
	using terms from application "OmniPlan"
		set n to name of oldTask
		set c to completed of oldTask
		set recalcDur to recalculates duration of oldTask
		set e to effort of oldTask
		set nt to note of oldTask
		
		-- do not set start date or duration yet		
		
		tell newParent
			set newTask to make new task with properties {name:n, completed:c, note:nt}
			set recalculates duration of newTask to recalcDur
		end tell
		
		
		-- assign resources
		repeat with a in assignments of oldTask
			set oldResID to id of resource of a
			set newResID to findNewID(oldResID, my resourceIDMap)
			set newTaskID to id of newTask
			set oldTaskID to id of oldTask
			set u to units of a
			tell destProject
				assign task id newTaskID to resource id newResID units u
			end tell
		end repeat
		
		--have to set effort/duration after assignments to make calc work out right
		tell destProject
			set effort of newTask to e
		end tell
		
		return newTask
	end using terms from
end copyTask