Quantcast
Channel: MicroStation Programming Forum - Recent Threads
Viewing all articles
Browse latest Browse all 7260

RE: Turn off level in View, C++

$
0
0

I have modified the program to hide levels for the active model reference or any attached model reference.  Right now you can only do one .dgn at a time.  Here is the source code:

std::wstring convertStringto_wstring(string s)
{
	const size_t cSize = s.length() + 1;
	wchar_t* wc = new wchar_t[cSize];
	mbstowcs(wc, s.c_str(), cSize);
	std::wstring converted(wc);
	delete[] wc;
	return converted;
}
extern "C"  DLLEXPORT int   MdlMain
(){
	int worked;
	DgnModelRefP modelRef4Levels;
	int cnt = 0;
	string line;
	ifstream infile;
	appendToFile("");
	infile.open("Turn off Levels.txt");
	DgnModelRefP modelRef = mdlModelRef_getActive();
	if (infile.is_open()){
		std::getline(infile, line);
		const std::wstring name = convertStringto_wstring(line);
		wchar_t* refname = new wchar_t[512];
		DgnModelRefP dgnModelRef = mdlModelRef_getActive();
		ModelRefIteratorP  iterator;
		mdlModelRefIterator_create(&iterator, dgnModelRef, MRITERATE_PrimaryChildRefs, 0);
		bool found = false;
		while (NULL != (modelRef = mdlModelRefIterator_getNext(iterator)) && found == false)
		{
			mdlModelRef_getDisplayName(modelRef, refname, 512, NULL);
			wstring refNameStr(refname);

			if (refNameStr == name)
			{
				modelRef4Levels = modelRef;
				found = true;
			}
		}
		mdlModelRefIterator_free(&iterator);
		mdlModelRef_getDisplayName(mdlModelRef_getActive(), refname, 512, NULL);
		wstring refNameStr(refname);
		delete[] refname;
		if (refNameStr == name)
		{
			modelRef4Levels = mdlModelRef_getActive();
		}
		
		while (std::getline(infile, line)) // Saves the line in id
		{
			const std::wstring& levelName = convertStringto_wstring(line);
			//List the levels in the references
			BoolInt isactivemodel = mdlModelRef_isActiveModel(modelRef4Levels);
			LevelID levid;
			mdlLevel_getIdFromName(&levid, modelRef4Levels, LEVEL_NULL_ID, levelName.c_str());
			worked = mdlView_setLevelDisplay(modelRef4Levels, 0, levid, FALSE);//not working, worked = 0
		}
	}
	infile.close();
	mdlDialog_cmdNumberQueue(FALSE, CMD_MDL_UNLOAD, mdlSystem_getCurrTaskID(), TRUE);
	return SUCCESS;
}

The input file, called "Turn off Levels.txt" might look like:

CC_Working.dgn, Default
G-WORK-2
G-WORK-4
C-GRID

This program would go into the file CC_Working.dgn and into the model Default, view 1 and turn off G-WORK-2, G-WORK-4, and C-GRID.  
I might eventually plan on making the program work for multiple .dgn files.  
Here is another example of the "Turn off Levels.txt" file:
Concrete Barrier and Guardrail.dgn
dsnCellElements
Level 5
dsnStdBlockModified

You could list many more levels, and if they are in the dgn they will be turned off (otherwise skipped).  You only need the model if there is more than one.

Note that the first line is listed in your level display.  It is the entire line that represents that model reference.  Just put that text in the first line and it is sure to run without crashing :)

Thanks for all the help today!  


Viewing all articles
Browse latest Browse all 7260

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>