当前位置: 首页>>代码示例>>C#>>正文


C# Document.Import方法代码示例

本文整理汇总了C#中Document.Import方法的典型用法代码示例。如果您正苦于以下问题:C# Document.Import方法的具体用法?C# Document.Import怎么用?C# Document.Import使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Document的用法示例。


在下文中一共展示了Document.Import方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExportImportXml_SimpleText

        public void ExportImportXml_SimpleText()
        {
            var exportDoc = new Document();

            var exportBuilder = new DocumentBuilder(exportDoc);

            exportBuilder.Write("Hello World");

            var exportBodyXml = exportDoc.Export(exportDoc.Sections.Cast<Section>().Single().Body, DocumentTextFormat.Xml);

            var importDoc = new Document();

            importDoc.Import(importDoc.Sections.Cast<Section>().Single().Body, DocumentTextFormat.Xml, exportBodyXml);

            importDoc.AssertXml(importDoc.Sections.Cast<Section>().Single().Body, exportBodyXml);
        }
开发者ID:vc3,项目名称:ExoMerge,代码行数:16,代码来源:DocumentExportImportTests.cs

示例2: ImageTag

        public void ImageTag(Document doc, SheetInfo info, ViewPortInfo vport)
        {
            // Create a new QRCoder Tag
            QRCoder.QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator();

            // Generate a new QR Tag
            QRCoder.QRCodeGenerator.QRCode qrCode = qrGenerator.CreateQrCode(data, QRCoder.QRCodeGenerator.ECCLevel.M);

            // Assemble a temp file name
            string tempfile = System.IO.Path.GetTempFileName() + ".QRTAG";

            // Get the Tags graphics element
            System.Drawing.Bitmap bmp = qrCode.GetGraphic(5);

            // Save it temporarily
            bmp.Save(tempfile);

            // Get the related view sheet
            View sheet = (View)doc.GetElement(info.sheetId);

            // Create a image element to return from import
            Element imageElement = null;

            // Get the Viewports label outline
            Outline labelOutline = vport.vport.GetLabelOutline();

            // Get the lower left corner
            XYZ labelCorner = new XYZ(info.sheet.Origin.X + (labelOutline.MinimumPoint.X), info.sheet.Origin.Y + labelOutline.MinimumPoint.Y, 0);

            // Add some distance value
            XYZ location = labelCorner.Add(new XYZ(0, -0.5/12.0, 0));

            // Import the image
            doc.Import(tempfile, new ImageImportOptions() { RefPoint = location, Placement = BoxPlacement.TopLeft }, sheet, out imageElement);

            // Delete temp file
            if (System.IO.File.Exists(tempfile)) System.IO.File.Delete(tempfile);
        }
开发者ID:DOCQR,项目名称:revit,代码行数:38,代码来源:RevitQR.cs

示例3: Execute

        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application 
        /// which contains data related to the command, 
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application 
        /// which will be displayed if a failure or cancellation is returned by 
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application 
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command. 
        /// A result of Succeeded means that the API external method functioned as expected. 
        /// Cancelled can be used to signify that the user cancelled the external operation 
        /// at some point. Failure should be returned if the application is unable to proceed with 
        /// the operation.</returns>
        public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData,
        ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            try
            {
                m_app = commandData.Application;
                m_doc = commandData.Application.ActiveUIDocument.Document;
                if (null == m_doc)
                {
                    message = "There is no active document.";
                    return Autodesk.Revit.UI.Result.Failed;
                }

                if (!m_doc.IsFamilyDocument)
                {
                    message = "Current document is not a family document.";
                    return Autodesk.Revit.UI.Result.Failed;
                }

                // Get the view where the dwg file will be imported
                View view = GetView();
                if (null == view)
                {
                    message = "Opened wrong template file, please use the provided family template file.";
                    return Autodesk.Revit.UI.Result.Failed;
                }

                // The dwg file which will be imported
                string AssemblyDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                string DWGFile = "Desk.dwg";
                string DWGFullPath = Path.Combine(AssemblyDirectory, DWGFile);

                Transaction transaction = new Transaction(m_doc, "DWGFamilyCreation");
                transaction.Start();
                // Import the dwg file into current family document
                DWGImportOptions options = new DWGImportOptions();
                options.Placement = Autodesk.Revit.DB.ImportPlacement.Origin;
                options.OrientToView = true;
                ElementId elementId = null;
                m_doc.Import(DWGFullPath, options, view, out elementId);

                // Add type parameters to the family
                AddParameters(DWGFile);
                transaction.Commit();
            }
            catch (Exception ex)
            {
                message = ex.ToString();
                return Autodesk.Revit.UI.Result.Failed;
            }

            return Autodesk.Revit.UI.Result.Succeeded;
        }
开发者ID:AMEE,项目名称:revit,代码行数:69,代码来源:Command.cs

示例4: ImportExportXml_Table

        public void ImportExportXml_Table()
        {
            var doc = new Document();

            var importBodyXml = @"
                <Body>
                  <Table>
                    <Row>
                      <Cell>
                        <Paragraph>
                          <Run>Number</Run>
                        </Paragraph>
                      </Cell>
                      <Cell>
                        <Paragraph>
                          <Run>Name</Run>
                        </Paragraph>
                      </Cell>
                      <Cell>
                        <Paragraph>
                          <Run>Yes/No</Run>
                        </Paragraph>
                      </Cell>
                    </Row>
                    <Row>
                      <Cell>
                        <Paragraph>
                          <Run>1</Run>
                        </Paragraph>
                      </Cell>
                      <Cell>
                        <Paragraph>
                          <Run>J. Doe</Run>
                        </Paragraph>
                      </Cell>
                      <Cell>
                        <Paragraph>
                          <Run>Yes</Run>
                        </Paragraph>
                      </Cell>
                    </Row>
                    <Row>
                      <Cell>
                        <Paragraph>
                          <Run>2</Run>
                        </Paragraph>
                      </Cell>
                      <Cell>
                        <Paragraph>
                          <Run>A. Smith</Run>
                        </Paragraph>
                      </Cell>
                      <Cell>
                        <Paragraph>
                          <Run>No</Run>
                        </Paragraph>
                      </Cell>
                    </Row>
                  </Table>
                </Body>
                ";

            doc.Import(doc.Sections.Cast<Section>().Single().Body, DocumentTextFormat.Xml, importBodyXml);

            doc.AssertXml(doc.Sections.Cast<Section>().Single().Body, importBodyXml);
        }
开发者ID:vc3,项目名称:ExoMerge,代码行数:66,代码来源:DocumentExportImportTests.cs

示例5: CloneRegion_RepeatableThatSpansParagraphs

        public void CloneRegion_RepeatableThatSpansParagraphs()
        {
            var doc = new Document();

            var runTexts1 = new[] { "^", "{{ PrecedingField }}", "{{ each Items }}", };

            var onlySection = doc.Sections.Cast<Section>().Single();

            var onlyPara = onlySection.Body.Paragraphs.Cast<Paragraph>().Single();

            onlyPara.ParagraphFormat.SpaceBefore = 10;
            onlyPara.ParagraphFormat.SpaceAfter = 1;

            doc.Import(onlyPara, DocumentTextFormat.Xml, "<Paragraph>\r\n" + string.Join("\r\n", runTexts1.Select(t => "<Run>" + t + "</Run>")) + "\r\n</Paragraph>");

            var runs1 = onlyPara.ChildNodes.Cast<Run>().ToArray();

            var newPara = new Paragraph(doc);

            newPara.ParagraphFormat.SpaceBefore = 1;
            newPara.ParagraphFormat.SpaceAfter = 10;

            onlySection.Body.ChildNodes.Add(newPara);

            var runTexts2 = new[] { "{{ Sequence }}", "{{ end each }}", "$", };

            doc.Import(newPara, DocumentTextFormat.Xml, "<Paragraph>\r\n" + string.Join("\r\n", runTexts2.Select(t => "<Run>" + t + "</Run>")) + "\r\n</Paragraph>");

            var runs2 = newPara.ChildNodes.Cast<Run>().ToArray();

            Container<Document, Node, DocumentToken<Node>, Type, object, string> root;
            MergeTemplateError<DocumentToken<Node>>[] errors;
            MergeTemplateCompiler.Compile(typeof(object), TokenParser, ExpressionParser, Scanner.GetTokens(doc), null, true, out root, out errors);

            var repeatable = root.Children.OfType<IRegion<DocumentToken<Node>>>().OfType<Repeatable<Document, Node, DocumentToken<Node>, Type, object, string>>().Single();

            Assert.AreEqual(runs1[2], repeatable.StartToken.Start);

            Assert.AreEqual(runs2[1], repeatable.EndToken.Start);

            doc.AssertXml(@"
                <Document>
                  <Section>
                    <Body>
                      <Paragraph paragraphformat_spacebefore='10' paragraphformat_spaceafter='1'>
                        <Run>^</Run>
                        <Run>{{ PrecedingField }}</Run>
                        <Run>{{ each Items }}</Run>
                      </Paragraph>
                      <Paragraph paragraphformat_spacebefore='1' paragraphformat_spaceafter='10'>
                        <Run>{{ Sequence }}</Run>
                        <Run>{{ end each }}</Run>
                        <Run>$</Run>
                      </Paragraph>
                    </Body>
                  </Section>
                </Document>");

            var existingInnerTokens = repeatable.GetInnerTokens().ToArray();

            var clonedTokens = Writer.CloneRegion(doc,
                new Tuple<DocumentToken<Node>, DocumentToken<Node>[], DocumentToken<Node>>(repeatable.StartToken, existingInnerTokens, repeatable.EndToken));

            AssertText(doc, @"^{{ PrecedingField }}{{ each Items }}
                                {{ Sequence }}{{ end each }}
                                {{ each Items }}
                                {{ Sequence }}{{ end each }}$
                                ");

            Assert.AreNotEqual(repeatable.StartToken, clonedTokens.Item1);
            Assert.AreNotEqual(repeatable.StartToken.Start, clonedTokens.Item1.Start);
            Assert.AreNotEqual(repeatable.StartToken.End, clonedTokens.Item1.End);

            Assert.AreEqual(existingInnerTokens.Length, clonedTokens.Item2.Length);

            Assert.AreNotEqual(repeatable.EndToken, clonedTokens.Item3);
            Assert.AreNotEqual(repeatable.EndToken.Start, clonedTokens.Item3.Start);
            Assert.AreNotEqual(repeatable.EndToken.End, clonedTokens.Item3.End);

            doc.AssertXml(@"
                <Document>
                  <Section>
                    <Body>
                      <Paragraph paragraphformat_spacebefore='10' paragraphformat_spaceafter='1'>
                        <Run>^</Run>
                        <Run>{{ PrecedingField }}</Run>
                        <Run>{{ each Items }}</Run>
                      </Paragraph>
                      <Paragraph paragraphformat_spacebefore='1' paragraphformat_spaceafter='10'>
                        <Run>{{ Sequence }}</Run>
                        <Run>{{ end each }}</Run>
                      </Paragraph>
                      <Paragraph paragraphformat_spacebefore='10' paragraphformat_spaceafter='1'>
                        <Run>{{ each Items }}</Run>
                      </Paragraph>
                      <Paragraph paragraphformat_spacebefore='1' paragraphformat_spaceafter='10'>
                        <Run>{{ Sequence }}</Run>
                        <Run>{{ end each }}</Run>
                        <Run>$</Run>
                      </Paragraph>
//.........这里部分代码省略.........
开发者ID:vc3,项目名称:ExoMerge,代码行数:101,代码来源:NodeTextDocumentWriterTests.cs

示例6: CloneRegion_RepeatableWithNoNestedRegions_NodesAndFieldsAreCloned

        public void CloneRegion_RepeatableWithNoNestedRegions_NodesAndFieldsAreCloned()
        {
            var doc = new Document();

            var runTexts = new[] { "^", "{{ PrecedingField }}", "{{ each Items }}", "{{ Sequence }}", "{{ end each }}", "$" };

            var importedNodes = doc.Import(doc.Sections.Cast<Section>().Single().Body.Paragraphs.Cast<Paragraph>().Single(),
                DocumentTextFormat.Xml,
                "<Paragraph>\r\n" + string.Join("\r\n", runTexts.Select(t => "<Run>" + t + "</Run>")) + "\r\n</Paragraph>"
                );

            var runs = importedNodes.Cast<Run>().ToArray();

            var root = MergeTemplateCompiler.Compile<Document, Node, DocumentToken<Node>, Type, object, string>(typeof(object), TokenParser, ExpressionParser, Scanner.GetTokens(doc));
            var repeatable = root.Children.OfType<IRegion<DocumentToken<Node>>>().OfType<Repeatable<Document, Node, DocumentToken<Node>, Type, object, string>>().Single();

            Assert.AreEqual(runs[2], repeatable.StartToken.Start);
            Assert.AreEqual(runs[4], repeatable.EndToken.Start);

            var existingInnerTokens = repeatable.GetInnerTokens().ToArray();

            var clonedTokens = Writer.CloneRegion(doc,
                new Tuple<DocumentToken<Node>, DocumentToken<Node>[], DocumentToken<Node>>(repeatable.StartToken, existingInnerTokens, repeatable.EndToken));

            AssertText(doc, "^{{ PrecedingField }}{{ each Items }}{{ Sequence }}{{ end each }}{{ each Items }}{{ Sequence }}{{ end each }}$\r\n");

            Assert.AreNotEqual(repeatable.StartToken, clonedTokens.Item1);
            Assert.AreNotEqual(repeatable.StartToken.Start, clonedTokens.Item1.Start);
            Assert.AreNotEqual(repeatable.StartToken.End, clonedTokens.Item1.End);

            Assert.AreEqual(existingInnerTokens.Length, clonedTokens.Item2.Length);

            Assert.AreNotEqual(repeatable.EndToken, clonedTokens.Item3);
            Assert.AreNotEqual(repeatable.EndToken.Start, clonedTokens.Item3.Start);
            Assert.AreNotEqual(repeatable.EndToken.End, clonedTokens.Item3.End);

            doc.AssertXml(@"
                <Document>
                  <Section>
                    <Body>
                      <Paragraph>
                        <Run>^</Run>
                        <Run>{{ PrecedingField }}</Run>
                        <Run>{{ each Items }}</Run>
                        <Run>{{ Sequence }}</Run>
                        <Run>{{ end each }}</Run>
                        <Run>{{ each Items }}</Run>
                        <Run>{{ Sequence }}</Run>
                        <Run>{{ end each }}</Run>
                        <Run>$</Run>
                      </Paragraph>
                    </Body>
                  </Section>
                </Document>");
        }
开发者ID:vc3,项目名称:ExoMerge,代码行数:55,代码来源:NodeTextDocumentWriterTests.cs


注:本文中的Document.Import方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。