コード例 #1
0
        public static void Run()
        {
            //ExStart:EditHyperlink


            // The path to the documents directory.
            string MyDir         = RunExamples.GetDataDir_DWGDrawings();
            string dwgPathToFile = MyDir + "AutoCad_Sample.dwg";

            using (CadImage cadImage = (CadImage)Image.Load(dwgPathToFile))
            {
                foreach (CadBaseEntity entity in cadImage.Entities)
                {
                    if (entity is CadInsertObject)
                    {
                        CadBlockEntity block = cadImage.BlockEntities[((CadInsertObject)entity).Name];
                        if (!string.IsNullOrEmpty(block.XRefPathName.Value))
                        {
                            block.XRefPathName.Value = "new file reference.dwg";
                        }
                    }

                    if (entity.Hyperlink == "https://products.aspose.com")
                    {
                        entity.Hyperlink = "https://www.aspose.com";
                    }
                }
            }

            //ExEnd:EditHyperlink
        }
コード例 #2
0
        public static void Run()
        {
            //ExStart:FreePointOfView
            // The path to the documents directory.
            string MyDir          = RunExamples.GetDataDir_ConvertingCAD();
            string sourceFilePath = MyDir + "conic_pyramid.dxf";
            var    outPath        = Path.Combine(MyDir, "FreePointOfView_out.jpg");

            using (CadImage cadImage = (CadImage)Image.Load(sourceFilePath))
            {
                JpegOptions options = new JpegOptions
                {
                    VectorRasterizationOptions = new CadRasterizationOptions
                    {
                        PageWidth = 1500, PageHeight = 1500
                    }
                };

                float xAngle = 10; //Angle of rotation along the X axis
                float yAngle = 30; //Angle of rotation along the Y axis
                float zAngle = 40; //Angle of rotation along the Z axis
                ((CadRasterizationOptions)(options.VectorRasterizationOptions)).ObserverPoint = new ObserverPoint(xAngle, yAngle, zAngle);

                cadImage.Save(outPath, options);
            }

            //ExEnd:FreePointOfView
            Console.WriteLine("\n3D images exported successfully to JPEG.\nFile saved at " + outPath);
        }
コード例 #3
0
ファイル: CAD.cs プロジェクト: aleksanderkakol/DWGReader
        private static List <string> IterateCADInsertsATTRIB(CadImage cadImage)
        {
            List <string> items = new List <string>();

            foreach (CadBlockEntity blockEntity in cadImage.BlockEntities.Values)
            {
                foreach (var entity in blockEntity.Entities)
                {
                    switch (entity.TypeName)
                    {
                    case CadEntityTypeName.INSERT:
                        CadInsertObject childInsertObject = (CadInsertObject)entity;
                        foreach (var attributes in childInsertObject.ChildObjects)
                        {
                            if (attributes.TypeName == CadEntityTypeName.ATTRIB)
                            {
                                CadAttrib attribute = (CadAttrib)attributes;
                                string    attr      = attribute.DefinitionTagString.Value;
                                items.Add(attr);
                            }
                        }
                        break;
                    }
                }
            }
            return(items);
        }
コード例 #4
0
        public static void Run()
        {
            //ExStart:PenSupportInExport
            string   MyDir          = RunExamples.GetDataDir_ConvertingCAD();
            string   sourceFilePath = MyDir + "conic_pyramid.dxf";
            CadImage cadImage       = (CadImage)Image.Load(sourceFilePath);
            CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
            PdfOptions pdfOptions = new PdfOptions();

            // Here user can change default start cap and end cap of pens when exporting CadImage object to
            // image. It can be using for all image formats: pdf, png, bmp, gif, jpeg2000, jpeg, psd, tiff, wmf.
            // If user doesn't use PenOptions, system will use its own default pens (different in defferent places).
            rasterizationOptions.PenOptions = new PenOptions
            {
                StartCap = LineCap.Flat,
                EndCap   = LineCap.Flat
            };

            pdfOptions.VectorRasterizationOptions = rasterizationOptions;

            cadImage.Save(GetFileFromDesktop(MyDir + "9LHATT-A56_generated.pdf"), pdfOptions);


            //ExEnd:PenSupportInExport
        }
コード例 #5
0
        public static void Run()
        {
            //ExStart:AddTextInDWG
            string MyDir         = RunExamples.GetDataDir_DWGDrawings();
            string dwgPathToFile = MyDir + "SimpleEntites.dwg";

            using (Image image = Image.Load(dwgPathToFile))
            {
                CadText cadText = new CadText();
                cadText.StyleType        = "Standard";
                cadText.DefaultValue     = "Some custom text";
                cadText.ColorId          = 256;
                cadText.LayerName        = "0";
                cadText.FirstAlignment.X = 47.90;
                cadText.FirstAlignment.Y = 5.56;
                cadText.TextHeight       = 0.8;
                cadText.ScaleX           = 0.0;
                CadImage cadImage = (CadImage)image;
                cadImage.BlockEntities["*Model_Space"].AddEntity(cadText);

                PdfOptions pdfOptions = new PdfOptions();
                CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions();
                pdfOptions.VectorRasterizationOptions = cadRasterizationOptions;
                cadRasterizationOptions.DrawType      = CadDrawTypeMode.UseObjectColor;
                //cadRasterizationOptions.CenterDrawing = true;
                cadRasterizationOptions.PageHeight = 1600;
                cadRasterizationOptions.PageWidth  = 1600;
                cadRasterizationOptions.Layouts    = new string[] { "Model" };
                image.Save(MyDir + "SimpleEntites_generated.pdf", pdfOptions);
            }

            //ExEnd:AddTextInDWG
        }
コード例 #6
0
        private static List <string> GetNotEmptyLayoutsForDxf(CadImage cadImage)
        {
            List <string> notEmptyLayouts = new List <string>();

            Dictionary <string, string> layoutBlockHandles = new Dictionary <string, string>();

            foreach (CadLayout layout in cadImage.Layouts.Values)
            {
                if (layout.BlockTableRecordHandle != null)
                {
                    layoutBlockHandles.Add(layout.BlockTableRecordHandle, layout.LayoutName);
                }
            }

            foreach (CadBaseEntity entity in cadImage.Entities)
            {
                if (layoutBlockHandles.ContainsKey(entity.SoftOwner.Value))
                {
                    string layoutName = layoutBlockHandles[entity.SoftOwner.Value];
                    if (!notEmptyLayouts.Contains(layoutName))
                    {
                        notEmptyLayouts.Add(layoutName);
                    }
                }
            }

            return(notEmptyLayouts);
        }
コード例 #7
0
        public static void Run()
        {
            //ExStart:DecomposeCADInsertObject

            string MyDir          = RunExamples.GetDataDir_ConvertingCAD();
            string sourceFilePath = MyDir + "conic_pyramid.dxf";

            using (CadImage cadImage = (CadImage)Image.Load(sourceFilePath))
            {
                for (int i = 0; i < cadImage.Entities.Length; i++)
                {
                    if (cadImage.Entities[i].TypeName == CadEntityTypeName.INSERT)
                    {
                        CadBlockEntity block = cadImage.BlockEntities[(cadImage.Entities[i] as CadInsertObject).Name];

                        foreach (CadBaseEntity baseEntity in block.Entities)
                        {
                            //  processing of entities
                        }
                    }
                }

                //ExEnd:DecomposeCADInsertObject
            }
        }
コード例 #8
0
        public static void Run()
        {
            //ExStart:SupportOfBlockClipping
            // The path to the documents directory.
            string MyDir = RunExamples.GetDataDir_DXFDrawings();

            string inputFile  = MyDir + "SLS-CW-CD-CE001-R01_blockClip.dxf";
            string outputFile = MyDir + "SLS-CW-CD-CE001-R01_blockClip.pdf";

            using (CadImage cadImage = (CadImage)Image.Load(inputFile))
            {
                var rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions
                {
                    BackgroundColor = Aspose.CAD.Color.White,
                    DrawType        = Aspose.CAD.FileFormats.Cad.CadDrawTypeMode.UseObjectColor,
                    PageWidth       = 1200,
                    PageHeight      = 1600,
                    BorderX         = 30,
                    BorderY         = 5,

                    Layouts = new string[] { "Model" }
                };

                PdfOptions pdfOptions = new Aspose.CAD.ImageOptions.PdfOptions
                {
                    VectorRasterizationOptions = rasterizationOptions
                };

                cadImage.Save(outputFile, pdfOptions);
                //ExEnd:SupportOfBlockClipping
            }
        }
コード例 #9
0
        public static void Run()
        {
            //ExStart:AddAttribute
            // The path to the documents directory.
            string MyDir                    = RunExamples.GetDataDir_DXFDrawings();
            string sourceFilePath           = MyDir + "conic_pyramid.dxf";
            List <CadBaseEntity> mtextList  = new List <CadBaseEntity>();
            List <CadBaseEntity> attribList = new List <CadBaseEntity>();

            using (CadImage cadImage = (CadImage)Image.Load(sourceFilePath))
            {
                foreach (var entity in cadImage.Entities)
                {
                    if (entity.TypeName == CadEntityTypeName.MTEXT)
                    {
                        mtextList.Add(entity);
                    }

                    if (entity.TypeName == CadEntityTypeName.INSERT)
                    {
                        foreach (var childObject in entity.ChildObjects)
                        {
                            if (childObject.TypeName == CadEntityTypeName.ATTRIB)
                            {
                                attribList.Add(childObject);
                            }
                        }
                    }
                }

                Assert.AreEqual(6, mtextList.Count);
                Assert.AreEqual(34, attribList.Count);
            }
        }
コード例 #10
0
      public static void Run()
      {
          //ExStart:MeshSupportForDWG
          // The path to the documents directory.
          string MyDir          = RunExamples.GetDataDir_DWGDrawings();
          string sourceFilePath = MyDir + "meshes.dwg";

          // Load an existing DWG file as CadImage.
          using (CadImage cadImage = (CadImage)Image.Load(sourceFilePath))
          {
              foreach (var entity in cadImage.Entities)
              {
                  if (entity is CadPolyFaceMesh)
                  {
                      CadPolyFaceMesh asFaceMesh = (CadPolyFaceMesh)entity;

                      if (asFaceMesh != null)
                      {
                          Console.WriteLine("Vetexes count: " + asFaceMesh.MeshMVertexCount);
                      }
                  }

                  else if (entity is CadPolygonMesh)
                  {
                      CadPolygonMesh asPolygonMesh = (CadPolygonMesh)entity;

                      if (asPolygonMesh != null)
                      {
                          Console.WriteLine("Vetexes count: " + asPolygonMesh.MeshMVertexCount);
                      }
                  }
              }
          }
          //ExEnd:MeshSupportForDWG
      }
コード例 #11
0
        private static List <string> GetNotEmptyLayoutsForDwg(CadImage cadImage)
        {
            List <string> notEmptyLayouts = new List <string>();

            foreach (CadLayout layout in cadImage.Layouts.Values)
            {
                foreach (CadBlockTableObject tableObject in cadImage.BlocksTables)
                {
                    if (string.Equals(tableObject.HardPointerToLayout.Value, layout.ObjectHandle, StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (cadImage.BlockEntities.ContainsKey(tableObject.BlockName))
                        {
                            CadBlockEntity cadBlockEntity = cadImage.BlockEntities[tableObject.BlockName];
                            if (cadBlockEntity.Entities.Length > 0)
                            {
                                notEmptyLayouts.Add(layout.LayoutName);
                            }
                        }
                        break;
                    }
                }
            }

            return(notEmptyLayouts);
        }
コード例 #12
0
        public static void Run()
        {
            //ExStart:SupportForHiddenLines
            // The path to the documents directory.
            string MyDir          = RunExamples.GetDataDir_DWGDrawings();
            string sourceFilePath = MyDir + "Bottom_plate.dwg";
            string outPath        = MyDir + "Bottom_plate.pdf";

            using (CadImage cadImage = (CadImage)Image.Load(sourceFilePath))
            {
                CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
                rasterizationOptions.PageHeight = cadImage.Height;
                rasterizationOptions.PageWidth  = cadImage.Width;
                rasterizationOptions.Layers     = new string[] { "Print", "L1_RegMark", "L2_RegMark" };



                PdfOptions pdfOptions = new PdfOptions();
                rasterizationOptions.Layouts          = new string[] { "Model" };
                pdfOptions.VectorRasterizationOptions = rasterizationOptions;

                cadImage.Save(outPath, pdfOptions);
            }

            Console.WriteLine("\nThe DWG file exported successfully to PDF.\nFile saved at " + MyDir);
        }
コード例 #13
0
        public static void Run()
        {
            //ExStart:SinglePDFWithDifferentLayouts

            // The path to the documents directory.
            string MyDir = RunExamples.GetDataDir_DWGDrawings();


            using (CadImage cadImage = (CadImage)Image.Load(MyDir + "City skyway map.dwg"))
            {
                CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
                rasterizationOptions.PageWidth  = 1000;
                rasterizationOptions.PageHeight = 1000;

                //custom sizes for several layouts
                rasterizationOptions.LayoutPageSizes.Add("ANSI C Plot", new SizeF(500, 1000));
                rasterizationOptions.LayoutPageSizes.Add("8.5 x 11 Plot", new SizeF(1000, 100));

                PdfOptions pdfOptions = new PdfOptions()
                {
                    VectorRasterizationOptions = rasterizationOptions
                };

                cadImage.Save(MyDir + "singlePDF_out.pdf", pdfOptions);
            }

            //ExEnd:SinglePDFWithDifferentLayouts
        }
コード例 #14
0
        public static void Run()
        {
            //ExStart:ExportOLEObjects

            // The path to the documents directory.
            string MyDir = RunExamples.GetDataDir_DWGDrawings();

            string[] files = new string[] { "D ZD junior D10m H2m.dwg", "ZD - Senior D6m H2m45.dwg" };

            PngOptions pngOptions = new PngOptions {
            };
            CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();

            pngOptions.VectorRasterizationOptions = rasterizationOptions;
            rasterizationOptions.Layouts          = new string[] { "Layout1" };

            foreach (string file in files)
            {
                using (CadImage cadImage = (CadImage)Image.Load(MyDir + file))
                {
                    cadImage.Save(MyDir + file + "_out.png", pngOptions);
                }
            }
            //ExEnd:ExportOLEObjects
        }
コード例 #15
0
        public static void Run()
        {
            //ExStart:MeshSupport
            string MyDir = RunExamples.GetDataDir_ConvertingCAD();

            string sourceFilePath = MyDir + ("meshes.dwg");
            string outPath        = MyDir + ("meshes.pdf");

            using (CadImage cadImage = (CadImage)Image.Load(sourceFilePath))
            {
                CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
                rasterizationOptions.PageWidth      = 1600;
                rasterizationOptions.PageHeight     = 1600;
                rasterizationOptions.TypeOfEntities = TypeOfEntities.Entities3D;
                rasterizationOptions.Layouts        = new string[] { "Model" };
                PdfOptions pdfOptions = new PdfOptions
                {
                    VectorRasterizationOptions = rasterizationOptions
                };

                {
                    cadImage.Save(outPath, pdfOptions);
                }
            }
            //ExEnd:MeshSupport
        }
コード例 #16
0
        public static void Run()
        {
            //ExStart:SupportMLeaderEntityForDWGFormat
            // The path to the documents directory.
            string MyDir = RunExamples.GetDataDir_DWGDrawings();
            string file  = "file path";

            using (Image image = Image.Load(file))
            {
                // Test
                CadImage cadImage = (CadImage)image;

                Assert.AreNotEqual(cadImage.Entities.Length, 0);
                CadMLeader cadMLeader = (CadMLeader)cadImage.Entities[0];

                Assert.AreEqual(cadMLeader.StyleDescription, "Standard");
                Assert.AreEqual(cadMLeader.LeaderStyleId, "12E");
                Assert.AreEqual(cadMLeader.ArrowHeadId1, "639");
                Assert.AreEqual(cadMLeader.LeaderLineTypeID, "14");

                CadMLeaderContextData context = cadMLeader.ContextData;

                Assert.AreEqual(context.ArrowHeadSize, 30.0, 0.1);
                Assert.AreEqual(context.BasePoint.X, 481, 1);
                Assert.AreEqual(context.ContentScale, 1.0, 0.01);
                Assert.AreEqual(context.DefaultText.Value, "This is multileader with huge text\\P{\\H1.5x;6666666666666666666666666666\\P}bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
                Assert.AreEqual(context.HasMText, true);

                CadMLeaderNode mleaderNode = context.LeaderNode;

                Assert.AreEqual(mleaderNode.LastLeaderLinePoint.X, 473, 1);
                CadMLeaderLine leaderLine = mleaderNode.LeaderLine;

                Assert.AreEqual(leaderLine.BreakEndPoint, null);
                Assert.AreEqual(leaderLine.BreakPointIndex.Value, 0);
                Assert.AreEqual(leaderLine.BreakStartPoint, null);
                Assert.AreEqual(leaderLine.LeaderLineIndex.Value, 0);
                Assert.AreEqual(leaderLine.LeaderPoints.Count, 4);

                Assert.AreEqual(mleaderNode.BranchIndex, 0);
                Assert.AreEqual(mleaderNode.DogLegLength, 8.0, 0.1);

                Assert.AreEqual(context.HasMText, true);
                Assert.AreEqual(context.TextAttachmentType.Value, 1);
                Assert.AreEqual(context.TextBackgroundColor.Value, 18);
                Assert.AreEqual(context.TextHeight, 20.0, 0.1);
                Assert.AreEqual(context.TextStyleID.Value, "11");
                Assert.AreEqual(context.TextRotation.Value, 0.0, 0.01);

                Assert.AreEqual(cadMLeader.ArrowHeadId1, "639");
                Assert.AreEqual(cadMLeader.LeaderType, 1);
                Assert.AreEqual(cadMLeader.BlockContentColor, 0);
                Assert.AreEqual(cadMLeader.LeaderLineColor, 0);
                Assert.AreEqual(cadMLeader.TextHeight, 1.0, 0.01);
            }
            //ExEnd:SupportMLeaderEntityForDWGFormat
        }
コード例 #17
0
        public static void Run()
        {
            //ExStart:ExportDWGToPDFOrRaster
            // The path to the documents directory.
            string MyDir          = RunExamples.GetDataDir_DWGDrawings();
            string sourceFilePath = MyDir + "Bottom_plate.dwg";
            string outPath        = MyDir + "Bottom_plate.pdf";

            using (CadImage cadImage = (CadImage)Image.Load(sourceFilePath))
            {
                // export to pdf
                CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
                rasterizationOptions.Layouts = new string[] { "Model" };

                bool   currentUnitIsMetric    = false;
                double currentUnitCoefficient = 1.0;
                DefineUnitSystem(cadImage.UnitType, out currentUnitIsMetric, out currentUnitCoefficient);

                if (currentUnitIsMetric)
                {
                    double metersCoeff = 1 / 1000.0;

                    double scaleFactor = metersCoeff / currentUnitCoefficient;

                    rasterizationOptions.PageWidth  = (float)(210 * scaleFactor);
                    rasterizationOptions.PageHeight = (float)(297 * scaleFactor);
                    rasterizationOptions.UnitType   = UnitType.Millimeter;
                }
                else
                {
                    rasterizationOptions.PageWidth  = (float)(8.27f / currentUnitCoefficient);
                    rasterizationOptions.PageHeight = (float)(11.69f / currentUnitCoefficient);
                    rasterizationOptions.UnitType   = UnitType.Inch;
                }

                rasterizationOptions.AutomaticLayoutsScaling = true;

                PdfOptions pdfOptions = new PdfOptions
                {
                    VectorRasterizationOptions = rasterizationOptions
                };

                cadImage.Save(outPath, pdfOptions);

                // export to raster
                //A4 size at 300 DPI - 2480 x 3508
                rasterizationOptions.PageHeight = 3508;
                rasterizationOptions.PageWidth  = 2480;

                PngOptions pngOptions = new PngOptions
                {
                    VectorRasterizationOptions = rasterizationOptions
                };
                cadImage.Save(outPath.Replace("pdf", "png"), pngOptions);
            }
        }
コード例 #18
0
        public static void Run()
        {
            //ExStart:LargeDWGToPDF
            // The path to the documents directory.
            string MyDir = RunExamples.GetDataDir_DWGDrawings();

            string    filePathDWG    = MyDir + "TestBigFile.dwg";
            string    filePathFinish = MyDir + "TestBigFile.dwg.pdf";
            Stopwatch stopWatch      = new Stopwatch();


            try
            {
                stopWatch.Start();
                using (CadImage cadImage = (CadImage)Image.Load(filePathDWG))
                {
                    stopWatch.Stop();


                    // Get the elapsed time as a TimeSpan value.
                    TimeSpan ts = stopWatch.Elapsed;

                    // Format and display the TimeSpan value.
                    string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                                       ts.Hours, ts.Minutes, ts.Seconds,
                                                       ts.Milliseconds / 10);
                    Console.WriteLine("RunTime for loading " + elapsedTime);

                    CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
                    rasterizationOptions.PageWidth  = 1600;
                    rasterizationOptions.PageHeight = 1600;
                    PdfOptions pdfOptions = new PdfOptions();
                    pdfOptions.VectorRasterizationOptions = rasterizationOptions;

                    stopWatch = new Stopwatch();
                    stopWatch.Start();
                    cadImage.Save(filePathFinish, pdfOptions);
                    stopWatch.Stop();

                    // Get the elapsed time as a TimeSpan value.
                    ts = stopWatch.Elapsed;

                    // Format and display the TimeSpan value.
                    elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                                ts.Hours, ts.Minutes, ts.Seconds,
                                                ts.Milliseconds / 10);
                    Console.WriteLine("RunTime for converting " + elapsedTime);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            //ExEnd:LargeDWGToPDF
        }
コード例 #19
0
ファイル: CAD.cs プロジェクト: aleksanderkakol/DWGReader
        public void SearchTextInDWGAutoCADFile(string sourceFilePath, List <object> attrList)
        {
            // The path to the documents directory.
            //string MyDir = RunExamples.GetDataDir_DWGDrawings();
            //string sourceFilePath = MyDir + "search.dwg";
            // Load an existing DWG file as CadImage.
            CadImage cadImage = (CadImage)Image.Load(sourceFilePath);

            // Search for text in the block section
            //IterateCADInserts(cadImage);
            IterateCADInserts(cadImage, attrList);
            return;
        }
コード例 #20
0
        public static void Run()
        {
            //ExStart:ReadingDWT
            // The path to the documents directory.
            string MyDir = RunExamples.GetDataDir_ConvertingCAD();

            using (CadImage image = (CadImage)Image.Load(MyDir + "example.dwt"))
            {
                foreach (CadBaseEntity entity in image.Entities)
                {
                    //do your work here
                }
            }
        }
コード例 #21
0
        public static void Run()
        {
            //ExStart:1
            // The path to the documents directory.
            string MyDir          = RunExamples.GetDataDir_DWGDrawings();
            string sourceFilePath = MyDir + "visualization_-_conference_room.dwg";

            using (CadImage cadImage = (CadImage)Image.Load(sourceFilePath))
            {
                CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
                rasterizationOptions.Layouts   = new string[] { "Model" };
                rasterizationOptions.NoScaling = true;

                // note: preserving some empty borders around part of image is the responsibility of customer
                // top left point of region to draw
                Point  topLeft = new Point(500, 1000);
                double width   = 3108;
                double height  = 2489;

                CadVportTableObject newView = new CadVportTableObject();
                newView.Name = new CadStringParameter();
                newView.Name.Init("*Active");
                newView.CenterPoint.X         = topLeft.X + width / 2f;
                newView.CenterPoint.Y         = topLeft.Y - height / 2f;
                newView.ViewHeight.Value      = height;
                newView.ViewAspectRatio.Value = width / height;

                for (int i = 0; i < cadImage.ViewPorts.Count; i++)
                {
                    CadVportTableObject currentView = (CadVportTableObject)(cadImage.ViewPorts[i]);
                    if (cadImage.ViewPorts.Count == 1 || string.Equals(currentView.Name.Value.ToLowerInvariant(), "*active"))
                    {
                        cadImage.ViewPorts[i] = newView;
                        break;
                    }
                }

                // Create an instance of PdfOptions
                Aspose.CAD.ImageOptions.PdfOptions pdfOptions = new Aspose.CAD.ImageOptions.PdfOptions();
                // Set the VectorRasterizationOptions property
                pdfOptions.VectorRasterizationOptions = rasterizationOptions;

                MyDir = MyDir + "ConvertDWGToPDFBySupplyingCoordinates_out.pdf";
                //Export the DWG to PDF
                cadImage.Save(MyDir, pdfOptions);
            }
            //ExEnd:1
            Console.WriteLine("\nThe DWG file exported successfully to PDF.\nFile saved at " + MyDir);
        }
コード例 #22
0
        public static void Run()
        {
            //ExStart:SaveDXFFiles
            // The path to the documents directory.
            string MyDir          = RunExamples.GetDataDir_DXFDrawings();
            string sourceFilePath = MyDir + "conic_pyramid.dxf";

            using (CadImage cadImage = (CadImage)Image.Load(sourceFilePath))
            {
                // any entities updates
                cadImage.Save(MyDir + "conic.dxf");
            }

            //ExEnd:SaveDXFFiles
        }
コード例 #23
0
        public static void Run()
        {
            //ExStart:RenderDWGDocument
            // The path to the documents directory.
            string MyDir          = RunExamples.GetDataDir_DWGDrawings();
            string sourceFilePath = MyDir + "Bottom_plate.dwg";

            using (CadImage cadImage = (CadImage)Image.Load(sourceFilePath))
            {
                CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
                rasterizationOptions.Layouts   = new string[] { "Model" };
                rasterizationOptions.NoScaling = true;

                // note: preserving some empty borders around part of image is the responsibility of customer
                // top left point of region to draw
                Point  topLeft = new Point(6156, 7053);
                double width   = 3108;
                double height  = 2489;

                CadVportTableObject newView = new CadVportTableObject();

                // note: exactly such table name is required for active view
                newView.Name.Value            = "*Active";
                newView.CenterPoint.X         = topLeft.X + width / 2f;
                newView.CenterPoint.Y         = topLeft.Y - height / 2f;
                newView.ViewHeight.Value      = height;
                newView.ViewAspectRatio.Value = width / height;

                // search for active viewport and replace it
                for (int i = 0; i < cadImage.ViewPorts.Count; i++)
                {
                    CadVportTableObject currentView = (CadVportTableObject)(cadImage.ViewPorts[i]);
                    if ((currentView.Name.Value == null && cadImage.ViewPorts.Count == 1) ||
                        string.Equals(currentView.Name.Value.ToLowerInvariant(), "*active"))
                    {
                        cadImage.ViewPorts[i] = newView;
                        break;
                    }
                }
                PdfOptions pdfOptions = new PdfOptions();
                rasterizationOptions.Layouts          = new string[] { "Model" };
                pdfOptions.VectorRasterizationOptions = rasterizationOptions;

                cadImage.Save(MyDir, pdfOptions);
            }
            //ExEnd:RenderDWGDocument
            Console.WriteLine("\nThe DWG file exported successfully to PDF.\nFile saved at " + MyDir);
        }
コード例 #24
0
        public static void Run()
        {
            string MyDir = RunExamples.GetDataDir_DWGDrawings();
            //ExStart:ImportImageToDWG
            string   dwgPathToFile = MyDir + "Drawing11.dwg";
            CadImage cadImage1     = (CadImage)Image.Load(dwgPathToFile);
            // using (Image image = ImageLoader.Load(dwgPathToFile))
            {
                CadRasterImageDef cadRasterImageDef = new CadRasterImageDef();
                cadRasterImageDef.ObjectHandle = "A3B4";
                cadRasterImageDef.FileName     = "road-sign-custom.png";

                CadRasterImage cadRasterImage = new CadRasterImage();
                cadRasterImage.ImageDefReference = "A3B4";
                cadRasterImage.InsertionPoint.X  = 26.77;
                cadRasterImage.InsertionPoint.Y  = 22.35;
                cadRasterImage.DisplayFlags      = 7;
                cadRasterImage.ImageSizeU        = 640;
                cadRasterImage.ImageSizeV        = 562;
                cadRasterImage.UVector.X         = 0.0061565450840500831;
                cadRasterImage.UVector.Y         = 0;
                cadRasterImage.VVector.X         = 0;
                cadRasterImage.VVector.Y         = 0.0061565450840500822;
                cadRasterImage.ClippingState     = 0;
                cadRasterImage.ClipBoundaryVertexList.Add(new Cad2DPoint(-0.5, 0.5));
                cadRasterImage.ClipBoundaryVertexList.Add(new Cad2DPoint(639.5, 561.5));

                CadImage cadImage = (CadImage)cadImage1;
                cadImage.BlockEntities["*Model_Space"].AddEntity(cadRasterImage);

                List <CadBaseObject> list = new List <CadBaseObject>(cadImage.Objects);
                list.Add(cadRasterImageDef);
                cadImage.Objects = list.ToArray();


                PdfOptions pdfOptions = new PdfOptions();
                CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions();
                pdfOptions.VectorRasterizationOptions = cadRasterizationOptions;
                cadRasterizationOptions.DrawType      = CadDrawTypeMode.UseObjectColor;
                cadRasterizationOptions.CenterDrawing = true;
                cadRasterizationOptions.PageHeight    = 1600;
                cadRasterizationOptions.PageWidth     = 1600;
                cadRasterizationOptions.Layouts       = new string[] { "Model" };
                cadImage1.Save(MyDir + "export2.pdf", pdfOptions);
            }
            //ExEnd:ImportImageToDWG
        }
コード例 #25
0
ファイル: CAD.cs プロジェクト: aleksanderkakol/DWGReader
        private static void IterateCADInserts(CadImage cadImage, List <object> attrList)
        {
            int map_id = Form1.map_id;
            int sys_id = Form1.sys_id;
            int grp_id = Form1.grp_id;

            foreach (CadBlockEntity blockEntity in cadImage.BlockEntities.Values)
            {
                foreach (var entity in blockEntity.Entities)
                {
                    switch (entity.TypeName)
                    {
                    case CadEntityTypeName.INSERT:
                        CadInsertObject childInsertObject = (CadInsertObject)entity;
                        ArrayList       mtext             = IterateMTEXTNodes(cadImage);
                        string          BTNdsc            = string.Empty;
                        foreach (CadMText text in mtext)
                        {
                            double ABSposX = Math.Abs(childInsertObject.InsertionPoint.X - text.InsertionPoint.X);
                            double ABSposY = Math.Abs(childInsertObject.InsertionPoint.Y - text.InsertionPoint.Y);
                            if (ABSposX <= 40 && ABSposY <= 40)
                            {
                                BTNdsc = text.Text;
                            }
                        }
                        foreach (var attributes in childInsertObject.ChildObjects)
                        {
                            if (attributes.TypeName == CadEntityTypeName.ATTRIB)
                            {
                                CadAttrib at = (CadAttrib)attributes;
                                foreach (string attrName in attrList)
                                {
                                    if (at.DefinitionTagString.Value == attrName)
                                    {
                                        BTNdsc = at.DefaultText;
                                    }
                                }
                            }
                        }
                        Database db = new Database();
                        db.InsertMap_zne(map_id, sys_id, grp_id, childInsertObject.InsertionPoint.X, childInsertObject.InsertionPoint.Y, childInsertObject.RotationAngle, childInsertObject.Name, BTNdsc);
                        db.Dispose();
                        break;
                    }
                }
            }
        }
コード例 #26
0
        public static void Run()
        {
            string MyDir = RunExamples.GetDataDir_DWGDrawings();
            //ExStart:ImportImageToDWG
            string dwgPathToFile = MyDir + "Drawing11.dwg";

            CadImage cadImage1 = (CadImage)Image.Load(dwgPathToFile);

            CadRasterImageDef cadRasterImageDef = new CadRasterImageDef("road-sign-custom.png", 640, 562);

            cadRasterImageDef.ObjectHandle = "A3B4";

            Cad3DPoint insertionPoint = new Cad3DPoint(26.77, 22.35);
            Cad3DPoint uVector        = new Cad3DPoint(0.0061565450840500831, 0);
            Cad3DPoint vVector        = new Cad3DPoint(0, 0.0061565450840500822);

            CadRasterImage cadRasterImage = new CadRasterImage(cadRasterImageDef, insertionPoint, uVector, vVector);

            cadRasterImage.ImageDefReference = "A3B4";
            cadRasterImage.DisplayFlags      = 7;
            cadRasterImage.ClippingState     = 0;
            cadRasterImage.ClipBoundaryVertexList.Add(new Cad2DPoint(-0.5, 0.5));
            cadRasterImage.ClipBoundaryVertexList.Add(new Cad2DPoint(639.5, 561.5));

            CadImage cadImage = (CadImage)cadImage1;

            cadImage.BlockEntities["*Model_Space"].AddEntity(cadRasterImage);

            List <CadBaseObject> list = new List <CadBaseObject>(cadImage.Objects);

            list.Add(cadRasterImageDef);
            cadImage.Objects = list.ToArray();


            PdfOptions pdfOptions = new PdfOptions();
            CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions();

            pdfOptions.VectorRasterizationOptions = cadRasterizationOptions;
            cadRasterizationOptions.DrawType      = CadDrawTypeMode.UseObjectColor;

            cadRasterizationOptions.PageHeight = 1600;
            cadRasterizationOptions.PageWidth  = 1600;
            cadRasterizationOptions.Layouts    = new string[] { "Model" };
            cadImage1.Save(MyDir + "export2.pdf", pdfOptions);
            //ExEnd:ImportImageToDWG
        }
コード例 #27
0
 public static void Run()
 {
     //ExStart:RenderDXFAsPDF
     // The path to the documents directory.
     string MyDir = RunExamples.GetDataDir_DXFDrawings();
     string sourceFilePath = MyDir + "conic_pyramid.dxf";
   using (CadImage image = (CadImage)Image.Load(fileName);
     {
         ImageOptionsBase options = new JpegOptions();
         options.VectorRasterizationOptions = new CadRasterizationOptions() {PdfProductLocation = "C:\PDF" /*path to pdf product and licence*/ };
         options.VectorRasterizationOptions.PageHeight = 1000;
         options.VectorRasterizationOptions.PageWidth = 1000;
         image.Save(outPath, options);
     }          
     }
     //ExEnd:RenderDXFAsPDF         
 }
コード例 #28
0
        public static void Run()
        {
            //ExStart:1
            string SourceDir = RunExamples.GetDataDir_DWGDrawings();

            using (CadImage cadImage = (CadImage)Image.Load(SourceDir + "SimpleEntites.dwg",
                                                            new LoadOptions()
            {
                SpecifiedEncoding = CodePages.Japanese,
                SpecifiedMifEncoding = MifCodePages.Japanese,
                RecoverMalformedCifMif = false
            }))
            {
                //do export or something else with cadImage
            }
            //ExEnd:1
            Console.WriteLine("OverrideAutomaticCodePageDetectionDwg executed successfully");
        }
コード例 #29
0
ファイル: CAD.cs プロジェクト: aleksanderkakol/DWGReader
        private static ArrayList IterateMTEXTNodes(CadImage cadImage)
        {
            ArrayList cadMTEXTList = new ArrayList();

            foreach (CadBlockEntity blockEntity in cadImage.BlockEntities.Values)
            {
                foreach (var entity in blockEntity.Entities)
                {
                    switch (entity.TypeName)
                    {
                    case CadEntityTypeName.MTEXT:
                        CadMText cadObjectMtext = (CadMText)entity;
                        cadMTEXTList.Add(cadObjectMtext);
                        break;
                    }
                }
            }
            return(cadMTEXTList);
        }
コード例 #30
0
        static void Main()
        {
            // The path to the documents directory.
            string dataDir = Aspose.Imaging.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            using (CadImage cadImage = (CadImage)Image.Load(dataDir + "conic_pyramid.dxf"))
            {
                CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
                rasterizationOptions.PageWidth      = 500;
                rasterizationOptions.PageHeight     = 500;
                rasterizationOptions.TypeOfEntities = TypeOfEntities.Entities3D;

                //rasterizationOptions.ScaleMethod = ScaleType.GrowToFit;

                rasterizationOptions.Layouts = new string[] { "Model" };
                PdfOptions pdfOptions = new PdfOptions();
                pdfOptions.VectorRasterizationOptions = rasterizationOptions;
                cadImage.Save(dataDir + "output.pdf", pdfOptions);
            }
        }