how to turn on "Plot with plot styles" in the code?

how to turn on "Plot with plot styles" in the code?

wesbird
Collaborator Collaborator
370 Views
2 Replies
Message 1 of 3

how to turn on "Plot with plot styles" in the code?

wesbird
Collaborator
Collaborator

hi, I tried to print in black and white. I found, if "Plot with plot styles" is checked, then it's black and white. but if it's not checked, then the output still colored. how I can make sure "Plot with plot styles" is checked in my code. 

 

here is my code

 

private static bool PublishFile(string outputFilename,
	string mediaName,
	string styleSheetName,
	string plotDeviceName,
	int intStdScaleType)
{
	PlotRotation myPlotRotation = PlotRotation.Degrees000;

	bool ret = false;

	BlockTableRecord btr = Active.Database.CurrentSpaceId.GetObject<BlockTableRecord>();
	Layout lo = btr.LayoutId.GetObject<Layout>();

	// We need a PlotInfo object linked to the layout
	PlotInfo pi = new PlotInfo();
	pi.Layout = btr.LayoutId;

	// We need a PlotSettings object based on the layout settings which we then customize
	PlotSettings ps = new PlotSettings(lo.ModelType);
	ps.CopyFrom(lo);

	// The PlotSettingsValidator helps create a valid PlotSettings object
	PlotSettingsValidator psv = PlotSettingsValidator.Current;

	// We'll plot the extents, centered and scaled to fit
	psv.SetPlotType(ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Extents);
	//
	psv.SetUseStandardScale(ps, true);
	//psv.SetStdScaleType(ps, StdScaleType.ScaleToFit);
	StdScaleType myStdScaleType = StdScaleType.ScaleToFit;
	if (Enum.IsDefined(typeof(StdScaleType), intStdScaleType))
	{
		myStdScaleType = (StdScaleType)intStdScaleType;
	}
	psv.SetStdScaleType(ps, myStdScaleType);
	//
	try
	{
		//psv.SetPlotCentered(ps, true);
		psv.SetPlotCentered(ps, false);
		psv.SetPlotOrigin(ps, new Point2d(0, 0));
		//psv.SetPlotPaperUnits(ps, PlotPaperUnit.Inches);
		//psv.SetPlotPaperUnits(ps, PlotPaperUnit.Millimeters);
		psv.SetPlotRotation(ps, myPlotRotation);
	}
	catch (System.Exception caught)
	{
		throw;
	}

	// print in color or black/white 
	psv.RefreshLists(ps);

	//
	psv.SetCurrentStyleSheet(ps, styleSheetName);

	//
	psv.SetPlotConfigurationName(ps, plotDeviceName, mediaName);

	// We need to link the PlotInfo to the PlotSettings and then validate it
	pi.OverrideSettings = ps;
	PlotInfoValidator piv = new PlotInfoValidator();
	piv.MediaMatchingPolicy = MatchingPolicy.MatchEnabled;
	piv.Validate(pi);

	// A PlotEngine does the actual plotting (can also create one for Preview)
	if (PlotFactory.ProcessPlotState == ProcessPlotState.NotPlotting)
	{
		PlotEngine pe = PlotFactory.CreatePublishEngine();
		using (pe)
		{
			pe.BeginPlot(null, null);

			// We'll be plotting a single document
			pe.BeginDocument(pi, Active.Document.Name, null, 1, true, outputFilename);

			PlotPageInfo ppi = new PlotPageInfo();
			pe.BeginPage(ppi, pi, true, null);
			pe.BeginGenerateGraphics(null);
			pe.EndGenerateGraphics(null);

			// Finish the sheet
			pe.EndPage(null);
			// Finish the document
			pe.EndDocument(null);
			pe.EndPlot(null);
		}
		ret = true;
	}
	else
	{
		ret = false;
	}

	return ret;
}

Screenshot 2023-02-09 094750.png

Windows 10 64 bit, AutoCAD (ACA, Map) 2023
0 Likes
371 Views
2 Replies
Replies (2)
Message 2 of 3

norman.yuan
Mentor
Mentor

psv.SetCurrentStyleSheet(xxxx, "[A Mono PlotStyle Sheet].ctb");

 

You may want to first call PlotSettingValidator.GetPlotStyleSheetList() to see if the desired "mono-color" style sheet is available or not.

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 3

hippe013
Advisor
Advisor

Ensure that your layout (lo) is opened for write.

lo.PlotPlotStyles = True;
0 Likes