Importing Page setup from another file

Importing Page setup from another file

Anonymous
Not applicable
632 Views
3 Replies
Message 1 of 4

Importing Page setup from another file

Anonymous
Not applicable

Dear colleagues,

 

Is there an easy way to import Page setup from another file? Practically what you get when you click on "import" in "Page setup manager" dialogue? Are these objects AcDbPlotSettings?

 

I wouldn't like to use acedCommandS, of course, but on the other hand I don't want to open whole new database, search just for that one object in Plot settings dictionary, and close it. Is there any shortcut?

0 Likes
Accepted solutions (1)
633 Views
3 Replies
Replies (3)
Message 2 of 4

tbrammer
Advisor
Advisor
Accepted solution

Try this:

 

Acad::ErrorStatus ImportPlotSettings(AcDbDatabase *pDbTarget, LPCWSTR pcImportFile, LPCWSTR pcPlotSettingsName)
{
	Acad::ErrorStatus es;
	AcDbDatabase *pDbSource = new AcDbDatabase(false, true); // no defaults, no Document
	es = pDbSource->readDwgFile(pcImportFile);     // DWG that holds your page setup

	AcDbDictionary *pDict = 0;
	es = pDbSource->getPlotSettingsDictionary(pDict, AcDb::kForRead);

	if (es == Acad::eOk)
	{
		AcDbObjectId myPlotsettingId;
		es = pDict->getAt(pcPlotSettingsName, myPlotsettingId); // get your page setup
		pDict->close();

		AcDbPlotSettings *pPS = NULL, *pPsCopy = NULL;
		if ( (es=acdbOpenObject(pPS, myPlotsettingId, AcDb::kForRead)) == Acad::eOk )
		{
			pPsCopy = new AcDbPlotSettings(false);
			es = pPsCopy->copyFrom(pPS); 
			pPS->close();
		}

		if (pPsCopy)
		{
			es = pPsCopy->addToPlotSettingsDict(pDbTarget);
			if (es == Acad::eOk)
				pPsCopy->close();
			else
			{
				delete pPsCopy;
				pPsCopy = NULL;
			}
		}		
	}

	delete pDbSource;

	return es;
}

Thomas Brammer ● Software Developer ● imos AGLinkedIn
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.

Message 3 of 4

Anonymous
Not applicable

Thanks, this idea is clear and straight forward.

 

I would just like to ask you about LPCWSTR type, I haven't seen it before and cant find much in documentation, that's some sort of light weight string type or something?

0 Likes
Message 4 of 4

Alexander.Rivilis
Mentor
Mentor

LPCWSTR is the same as const ACHAR *

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member