Two of Scotland's biggest movie stars are getting together for a new comedy-drama inspired by one of the most disastrous flops in British cinema.

Ewan McGregor will star in Born To Be King, based on the story of the making of the 1948 David Niven movie, Bonnie Prince Charlie, legendary for its nightmarish shoot and catastrophic box-office takings.

McGregor will play an extra who happens to look like Niven, who suddenly finds himself in the limelight when the drunken star goes missing.

The film is written and will be directed by Peter Capaldi, best known as foul-mouthed political spin doctor Malcolm Tucker in The Thick of It. However, Capaldi also has impressive credentials as a film-maker, having won an Oscar for his short film, Franz Kafka's It's a Wonderful Life, in the 1990s.

Bonnie Prince Charlie was a would-be epic that cost a fortune to make and bombed with audiences and critics. Niven was signed to star but was desperately unhappy at being forced to abandon his easy-going lifestyle in Los Angeles for Britain and a wig and tartan.

The born-and-bred Englishman had been cast only because everyone in the movie world had been taken in by his lie that he was Scottish.

The production was plagued by disaster from the outset: it went through several directors, one of Niven's co-stars died and then the film disappeared virtually without trace, threatening to take the entire British film industry with it.

It has not exactly been smooth sailing for Born To Be King either. McGregor originally signed up in 2005 when it was called The Great Pretender and at the time hailed it as "a fantastic script".

Capaldi could not get the money together at the time, but didn't give up. It was at one time given another title – The Jacobite Slipper – and has featured in at least one list of the Greatest Scottish Films Never Made.

Now, with American backers on board, Born To Be King will finally start shooting at Pinewood Studios in Buckinghamshire in January.

McGregor will be joined by Kate Hudson, the star of Almost Famous and Bride Wars, who plays a Hollywood actress increasingly at odds with her co-star, but attracted to the extra who looks like him.

McGregor was philosophical about the wait. "I signed up to work on this film with Peter Capaldi about six years ago and, as so often is the way with independent films, it's taken this long to get the funding," he said. "I've known Peter since he acted with my uncle (actor Denis Lawson) in Local Hero in the 80s, and I've always loved his work."

Born To Be King takes its title from a line in the Skye Boat Song about Bonnie Prince Charlie's escape to the Hebrides. It is being described as both a "romantic comedy" and a "mistaken identity comedy".

Capaldi said: "The film will be artful and magical. And, of course, above all, I intend it to be entertaining."

It caused considerable excitement at the American Film Market last week, where distribution rights were up for sale.

Stephanie Denton of distribution company Indomina said: "Peter's screenplay seamlessly weaves the story of the film within the film. It's an exciting, entertaining and genuinely funny project."

Capaldi and McGregor will be hoping that Born To Be King turns out better than Bonnie Prince Charlie. With a huge budget, a major Hollywood star and a dramatic story from Scottish history, the 1948 film should have been one of British cinema's most celebrated epics.

Alexander Korda, the Hungarian refugee who became England's greatest movie mogul, had conquered America with The Private Life of Henry VIII, the first British film to be nominated for an Academy Award for Best Picture, and he was prepared to spend big money for a repeat.

Niven was at the time under contract to Sam Goldwyn, but Korda's London Film Productions offered the studio the then-astronomical sum of $150,000 for the use of his services.

Bonnie Prince Charlie was shot mainly in the studios at Shepperton, although there was some location filming in the Highlands.

The distinguished cast included Margaret Leighton as Flora MacDonald, Jack Hawkins as Lord George Murray and Scots actor John Laurie, who later played Private Frazer in TV's Dad's Army, as Blind Jimmie. When Charlie asks him if the clans will rally to him, Laurie replies that he will answer in song. He whips out his harp and starts to sing, in a scene that might remind modern audiences of a Little Britain sketch. Suddenly the landscape is awash with clansmen.

Many of the extras who played Charlie's men actually came from London's East End. Asked to cheer the appearance of the prince and let him know of the capture of the enemy colours, one cockney clansman blurted out: "Oi, David, We've got their f***in' flag!", or so Niven claimed in his entertaining, but highly unreliable, memoirs.

One reviewer of the film concluded: "Niven seems as much at home among the Highlanders as a goldfish in a haggis."

Just to add insult to injury, when Niven's birth certificate was discovered after his death it turned out that he had not been born in Kirriemuir in Angus, as he claimed, but in Belgrave Mansions in London.