Hy,
finally official support has also no solution for this topic (yet)…
Regards
Feature
Hy,
finally official support has also no solution for this topic (yet)…
Regards
Feature
Sad that support couldn’t help. It is time to bring out nasty reflection hacks then.
edit: Found a way to do the DWG / DXF export without using reflection afterall
For the DWG / DXF export you must set your plugin project to target .NET 4.8 and then add a reference to RealDWG\RealDWG.dll.
public void ExportDrawing()
{
var context = IoC.Get<IApplicationContext>();
context.SetContext(Contexts.Drawing);
string myDocumentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string pdfOutputPath = Path.Combine(myDocumentsFolder, "Drawing.pdf");
ExportDrawingAsPDF(pdfOutputPath);
string dxfOutputPath = Path.Combine(myDocumentsFolder, "Drawing.dxf");
ExportDrawingInRealDwgFormat(dxfOutputPath, DWGInternalVersion.DXF);
}
private void ExportDrawingAsPDF(string outputPath)
{
List<Visual> visualElement = new List<Visual>();
ImageSourceExporter exporter = new ImageSourceExporter
{
OnlySelection = false
};
exporter.SetDrawingWorld();
// Rendered image size in pixels. Note that this produces a PDF with a bitmap inside, not a vector drawing.
// Need to figure out applicable resolution and aspect ratio for your paper size. Here are some values for portrait A4.
int width = 793;
int height = 1116;
PaperSize paperSize = new PaperSize("A4", 0, 0);
bool rotate = false;
int margins = 5;
var visualHosts = exporter.ExportManyVisuals(true, width - margins, height - margins);
foreach (var v in visualHosts)
{
var border = new Border
{
HorizontalAlignment = System.Windows.HorizontalAlignment.Center,
VerticalAlignment = System.Windows.VerticalAlignment.Center,
Child = v
};
visualElement.Add(border);
}
PdfExporter.VisualsToPdf(
visuals: visualElement,
pdfPath: outputPath,
width: width,
height: height,
margin: 0,
rotate: rotate,
paperKind: paperSize
);
}
private void ExportDrawingInRealDwgFormat(string outputPath, DWGInternalVersion format, bool onlySelectedComponents = false)
{
var writer = new RealDWG.RealDWGWriter();
writer.SetDrawingWord();
if (format == DWGInternalVersion.DXF)
{
writer.SetSaveFormat(VectorDrawingFormat.DXF);
}
else
{
writer.SetSaveFormat(VectorDrawingFormat.DWG);
writer.SetVersion(format.ToString());
}
writer.SetSelectAll(onlySelectedComponents);
writer.WriteFile(outputPath);
}
For custom views you need to first move the application camera and then call the CreateView method.
Something like this:
// Move the main camera to desired drawing view.
var context = IoC.Get<IApplicationContext>();
context.SetContext(Contexts.Configure); // Maybe needed to avoid modifying the drawing context camera.
ICamera camera = _application.ActiveWindow.Camera;
camera.PanValue = 45;
camera.TiltValue = -45;
camera.ChangeFocus(_application.World.Components);
// Create a custom drawing using the current camera view.
projectAction.CreateView(DrawingViewPoints.Current);
var custom = (IDrawingView)app.DrawingWorld.LayoutItems.Last();
custom.Scale = "1:3";
// TODO: Position the drawing view in the drawing world to fit template sheet along with other views.
Hy @TSy ,
it seems you had a short night?
Could it be that the reference to RealDWG.dll and change the projects framework to 4.8 is not enough?
Edit: I also add references to acdbmg.dll and asdbmgbrep.dll but that changes nothing…
Regards
Feature
Hy,
my last result for now (VC 4.7) is, that I’m praying every evening for an clean public API for save the current drawing in a format of choice…
Regards
Feature
Interesting discussion here and I am definitely supporting the automation of drawings.
Since the release of VC 4.0 I have been talking with the Sales guys in the US and send a request to VC Europe about improving the 2d aspect of Visual Components.
Both companies I worked for are designing lay-outs which shows over 100 + components and after creating a view, it is a very monotone 1 color block that is not really useful.
My question to any of you is (and I requested this a few times at VC):
Does anybody know if it possible to assign a color to a component so that after 2d convertion, that component is that color? We would like to highligh our additional components on our machines with a seperate color.
I know there is an add-on which allows you to change color AFTER converting to 2d but since every lay-out has 100+ components, this is time consuming and I would rather have a color preset so I won;t have to do that everytime.
Thanks,
Arjan
If it is possible to identify which sim world component produced each drawing element (probably yes), it should be fairly easy to make a .NET add-on which reads some custom property from the sim world component and changes the color of the drawing elements accordingly.
Same add-on could also have e.g. a button which adds those properties to selected components.
Hy,
now VC4.8 is released and I found a new Method:
VisualComponents.Create3D.PdfExporter.VisualsToPdf()
But how to cast ILayoutItem to Visual?
Thx & Regards
Feature
That’s not a new method.
There is ImageSourceExporter class in Create3D.Shared.
Hy @TSy ,
may you know if VC4.8 is able to export something useful from drawingTab in a beautiful way?
Thx & Regards
Feature
I can’t be 100% sure but I think there hasn’t been any change in this regard between 4.7 and 4.8.