cart: empty [ Login ]

Watermark from DxfModel to Pdf

1 
easylift
1/24/2024 2:07 PM
Good morning, I would like when I export from DxfModel to Pdf (I use Matrix4D+PdfExporter) to set some lines and some blocks with some opacity (watermark). In Autocad I do it with the ctb file where I set a "screening" of 15 instead of 100 for the level concerned. I have read that you recently introduced support for the ctb file but only for color and line thickness. Is there another way to export some lines/blocks to PDF as a watermark? Thank you Best regards Ivan
Wout
1/25/2024 9:04 AM
Hi Ivan, Do you have a sample DWG/DXF/CBT file combo for me to look into? I can look into it on Monday. - Wout
easylift
1/25/2024 3:20 PM
Hi Wout, here is it attached the files. Ok, is not urgent. Thank you Ivan
Wout
1/31/2024 2:13 PM
Hi Ivan, I've implemented support for CTB screening in the latest CadLib 4.0 version. I would appreciate a small contribution for the implementation. Thank you for providing the test files. - Wout
easylift
2/2/2024 2:52 PM
Hi Wout, thank you for your work, I will send you bye banking account. Can you give me an example on how to use the new screening function? (if possibile in VB .NET) Thank you Ivan
Wout
2/2/2024 3:14 PM
Hi Ivan, In VB:
Visual Basic Code:
Dim graphicsConfig As GraphicsConfig = CType(GraphicsConfig.AcadLikeWithWhiteBackground.Clone(), GraphicsConfig) Dim ctbFile As CtbFile = New CtbFile("D:\support\easylift\1\Disegni Ascensori.ctb") graphicsConfig.PlotStyleManager = New PlotStyleProvider(ctbFile.GetPlotStyle)
In C#:
C# Code:
GraphicsConfig graphicsConfig = (GraphicsConfig)GraphicsConfig.AcadLikeWithWhiteBackground.Clone(); CtbFile ctbFile = new CtbFile("D:\\support\\easylift\\1\\Disegni Ascensori.ctb"); graphicsConfig.PlotStyleManager = ctbFile.GetPlotStyle;
- Wout
easylift
2/12/2024 3:44 PM
Hi Wout, I had now the time to try it. I wrote the code same you but I get the error that you see in the attached image. How to solve? Thank you Ivan
errore.png
Wout
2/13/2024 1:55 PM
Hi, I guess the decompile to VB wasn't accurate. But your error message already says what you have to do, you have to use AddressOf. You never used it? It has been part of VB.NET for over 20 years.
Visual Basic Code:
Dim ctbFile As New CtbFile("Your CTB filename.ctb") config.PlotStyleManager = AddressOf ctbFile.GetPlotStyle
- Wout
easylift
2/13/2024 4:30 PM
Sorry, I am not expert as you. Now it works the screening, thank you. But it doesn't work the color that I have read on other forum that was working. Here is it the code:
Visual Basic Code:
Dim model As DxfModel = New DxfModel(DxfVersion.Dxf15) model = DwgReader.Read("model.dwg") 'insert block Dim block As New DxfBlock("lift") Dim insertmodel As DxfModel = DwgReader.Read("table.dwg") Dim cloneContext As New CloneContext(insertmodel, model, ReferenceResolutionType.CloneMissing) For Each sourceentity As DxfEntity In insertmodel.Entities Dim clonedentity As DxfEntity clonedentity = sourceentity.Clone(cloneContext) block.Entities.Add(clonedentity) Next cloneContext.ResolveReferences() model.Blocks.Add(block) Dim insert As New DxfInsert(block, New Point3D(0, 0, 0)) insert.Rotation = 0 insert.ScaleFactor = New Vector3D(1, 1, 1) insert.Layer = model.GetLayerWithName("0") model.Entities.Add(insert) 'save pdf Dim stream As Stream Dim boundsCalculator As BoundsCalculator = New BoundsCalculator boundsCalculator.GetBounds(model) Dim bounds As Bounds3D = boundsCalculator.Bounds Dim paperSize As PaperSize = PaperSizes.GetPaperSize(PaperKind.A4) Dim pageWidth As Single = paperSize.Width / 100.0! Dim pageHeight As Single = paperSize.Height / 100.0! Dim margin As Single = 0.0! 'Dim margin As Single = 0.5! Dim to2DTransform As Matrix4D = DxfUtil.GetScaleTransform( bounds.Corner1, bounds.Corner2, New Point3D(bounds.Center.X, bounds.Corner2.Y, 0D), New Point3D((New Vector3D(margin, margin, 0D) * PdfExporter.InchToPixel)), New Point3D((New Vector3D(pageWidth - 2D * margin, (pageHeight - margin), 0D) * PdfExporter.InchToPixel)), New Point3D((New Vector3D(pageWidth / 2D, (pageHeight - margin), 0D) * PdfExporter.InchToPixel)) ) stream = File.Create("output.pdf") Dim pdfGraphics As PdfExporter = New PdfExporter(stream) Dim graphicsConfig As GraphicsConfig = CType(GraphicsConfig.AcadLikeWithWhiteBackground.Clone(), GraphicsConfig) graphicsConfig.BackColor = System.Drawing.Color.White graphicsConfig.TryDrawingTextAsText = True 'True 'graphicsConfig.FixedForegroundColor = System.Drawing.Color.Black 'graphicsConfig.DefaultLineWeight = 10 graphicsConfig.ShowHatchBoundaries = True Dim ctbFile As CtbFile = New CtbFile("Disegni Ascensori.ctb") graphicsConfig.PlotStyleManager = AddressOf ctbFile.GetPlotStyle pdfGraphics.DrawPage(model, graphicsConfig, to2DTransform, paperSize) pdfGraphics.EndDocument() System.Diagnostics.Process.Start("output.pdf")
regards Ivan
Wout
2/14/2024 1:30 PM
Hi Ivan, There as a bug indeed, the plot style was ignored for text/mtext. I have just fixed the problem, please download the lateset version. You're not the only user who is not familiar with the use of AddressOf in Visual Basic. I've just added a remark to the documentation of GraphicsConfig.PlotStyleManager for future users. Thank you for the report! - Wout
1