Ad

Thursday, October 09, 2014

Word Adding Page Number and Number of Pages to A Header by .NET

Sometimes things on the internet are hard to find because most other questions are slightly related. One such instance I ran into is programattically adding in the page number and number of pages in a header. I’m sure the answer has been asked and answered somewhere on the internet, but I couldn’t find it.

My initial attempts came up way short. Using some of the examples overwrote the other text I needed in the header. So here is my code to get the job done.

Public Sub HeaderInformation(ByRef reportHeaderInfo As ReportHeaderInformation)
    ' Add info for header.
    Dim header As Word.HeaderFooter = oDoc.Sections.Last.Headers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary)
    Dim headerRange As Word.Range = header.Range
    headerRange.Text = "File Name: " & reportHeaderInfo.FileName & vbTab & vbTab & "Date: " & DateTime.Now.ToString("MM-dd-yy")
    headerRange.Text += "Project: " & reportHeaderInfo.ProjectName & vbTab & vbTab & "Time: " & DateTime.Now.ToString("hh:mm:ss")
    headerRange.Text += "Subproject: " & reportHeaderInfo.SubProject & " , Subproject No:" & reportHeaderInfo.SubProjectNo & vbTab & vbTab & "  of  "

    headerRange = header.Range
    headerRange.SetRange(header.Range.Text.IndexOf("of") - 2, header.Range.Text.IndexOf("of") - 1)
    headerRange.Fields.Add(headerRange, Word.WdFieldType.wdFieldPage)

    headerRange = header.Range
    headerRange.SetRange(header.Range.End - 1, header.Range.End)
    headerRange.Fields.Add(headerRange, Word.WdFieldType.wdFieldNumPages)

End Sub

Note that I had to get a range within the header range and then add the page number and number of pages fields to the header. Make sure not to utilize the character count of the header range because it doesn’t count the field’s characters. This ends up having the field being inserted into the original field. Using the Range.End returns the actual end and not the end of the character count.

Saturday, September 27, 2014

Missing Toolspace Tabs

Have you ever found tabs missing from Toolspace? Well there is an easy solution to get them to show up again. On the Home Tab of the ribbon, Palettes panel there is a collection of four buttons that toggle on/off prospector, Settings, Toolbox, and Survey. They are located conveniently next to the big Toolspace button. So if you find your are missing them, just press the buttons on the ribbon.

image

Thursday, September 25, 2014

Set Reference Text

Nothing like having to create a code snippet test to provide it to Autodesk so they can check to make sure their own code works. It’s not like they are going to provide me the source code so I can fix the error in the method. So I figured I’d create a blog post at the same time so Autodesk can steal it to and hopefully create a unit test so they can make sure non-buggy software doesn’t make it out into the world. Unfortunately for you, at least at the time of this writing, this post is entirely useless for setting reference text for a surface. It does work for alignments, profiles, and some other object types. Feel free to use the code for this. This code doesn’t have any error catching and would need improvements if used in a production environment.

The code throws an exception for setting surfaces as a reference saying it’s not the correct type of object.  

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.ApplicationServices.Core;
using Autodesk.AutoCAD.Runtime;
using Autodesk.Civil.DatabaseServices;
using Autodesk.Civil.DatabaseServices.Styles;

namespace SetReferenceTextTarget
{
    public class SetReferenceTextTargetTest
    {
        [CommandMethod("SetReferenceTextTargetTest")]
        public static void runCommand()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            Database db = HostApplicationServices.WorkingDatabase;

            try
            {
                using (Transaction tr = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
                {
                    var surfObjId = ed.GetEntity("Select Surface:").ObjectId;
                    var labelToUse = ed.GetEntity("Select label with surface reference text: ").ObjectId.GetObject(OpenMode.ForWrite) as Label;

                    // Get the reference text, yeah! We can't use link because this "modern" software hasn't implemented IEnumerable for the
                    // ObjectIdCollection yet. So we get to go through each one in a loop!
                    ObjectId refTxtlabelComponentObjId = ObjectId.Null;
                    foreach (ObjectId objIdTxt in labelToUse.GetTextComponentIds())
                    {
                        var txtComp = objIdTxt.GetObject(OpenMode.ForWrite) as LabelStyleReferenceTextComponent;
                        if (txtComp != null)
                        {
                            refTxtlabelComponentObjId = objIdTxt;
                        }
                    }

                    labelToUse.SetReferenceTextTarget(refTxtlabelComponentObjId, surfObjId);

                    tr.Commit();
                }
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Autodesk quality control sucks!: Here is proof: " + ex.Message);
            }
        }
    }
}

Wednesday, September 24, 2014

Render Contest

I almost ready to do an informative post about Civil 3D, then Imaginit sent me an email that made it so I don’t have to come up with original content for post material. Evidently they are having a contest where you can win prizes by doing work or voting on the work others have done.

How to Enter

  1. Designers simply upload your best rendering that was developed using software or products from either Autodesk or IMAGINiT Technologies. The contest is free to enter.
  2. IMAGINiT will share all entries across their social networks and entrants are encouraged to do the same.
  3. The submission deadline is October 1, 2014.

Prizes

The public will determine the three winners by voting for their favorite rendering on IMAGINiT’s RENDERiT Contest Facebook Page.

Voting closes on October 7, 2014 and winners will be announced on October 8, 2014.

Voters will also be eligible for a prize as everyone who votes will be entered into a drawing for a US$100 Apple gift card.

First prize: MakerBot Replicator Mini 3D Printer

Second prize: Polaroid Socialmatic

Third prize: Pebble Steel Smartwatch

Small commercial and residential projects seem to have less of an opportunity to come up with cool posts. Maybe next time.

Monday, September 22, 2014

Epson Printers

I’m out of blog ideas, so Epson Printers was kind enough to provide one for me.

Epson today announced its next-generation of SureColor® T-Series large-format color printers – the SureColor T3270, T5270, T7270, T5270D, and T7270D – are now shipping and available for purchase from a network of authorized T-Series resellers.

Equipped with Epson’s latest PrecisionCore TFP® print head and Epson UltraChrome® XD pigment ink, the SureColor T-Series provides technical, corporate and marketing professionals an unprecedented combination of precision, performance and brilliance.

Epson Now Shipping Next-Generation SureColor T-Series Large-Format Color Printers

LONG BEACH, Calif. – Sept. 22, 2014 – Epson today announced it is shipping its next-generation family of large-format color printers – the Epson® SureColor® T3270, T5270, T7270, T5270D, and T7270D. Equipped with Epson’s latest PrecisionCore TFP® printhead and Epson UltraChrome® XD pigment ink, the SureColor T-Series provides technical, corporate and marketing professionals an unprecedented combination of precision, performance and brilliance, and are now available for purchase through authorized Epson Professional Imaging T-Series resellers.

“We have been using the SureColor T5270D dual-roll 36-inch printer with the multifunction scanning module to create drawings for a variety of customers in the civil engineering market, with needs ranging from 36-inch wide output down to 18-inch drawings to meet strict LA County requirements,” said George Shweiri, Owner, Denn Engineers. “With simultaneous support for two different media widths, the dual-roll T-Series machine has allowed us to not only maximize space, but also reduce overhead and lower total cost of ownership. Plus, the scan to-network shared folders capability has elevated overall efficiency.”

Available in both single- and dual-roll models, the SureColor T-Series delivers extreme line accuracy with resolutions up to 2880 x 1440 dpi at incredibly fast speeds – producing a presentation quality D-size plot in as little as 25 seconds1. In addition, the SureColor T-Series 36- and 44-inch printer models offer an optional multifunction (MFP) module, enabling PC-free full color copy and scan capabilities – up to 36-inches wide – at best-in-class speeds for added convenience.

“The next-generation SureColor T-Series incorporates the latest in printing technology, and we are very excited to begin shipping into the hands of our customers,” said Timothy Check, product manager, Professional Imaging, Epson America, Inc. “Whether printing retail posters, corporate graphics, CAD drawings or GIS maps, the T-Series printers are cost-effective, scalable machines that really can do it all. We look forward to feedback from our customers and discovering even more unique applications and use cases.”

More about the SureColor T-Series

The SureColor T-Series is comprised of five printer models, offering varying performance and feature sets to accommodate a range of printing needs, all while retaining a minimal footprint to fit virtually anywhere.

Utilizing Epson’s UltraChrome XD ink, which delivers brilliant color and crisp lines on practically any media type and varied ink capacities to maximize efficiency, users can achieve truly archival and water-resistant output at an affordable cost. The SureColor T-Series printers are designed to be used exclusively with these specially-formulated inks, and not with other brands of cartridges or inks2. In addition, multiple optional features are available for the new SureColor T-Series, including a Multifunction MFP Scanner upgrade for the 36- and 44-inch single and dual-roll models, 320 GB internal print server upgrade and True Adobe® Postscript® 3 Hardware Engine.

Availability & Support

The Epson SureColor T-Series is currently available through authorized Epson Professional Imaging resellers. The SureColor T-Series printers offer a standard Epson PreferredSM Limited Warranty, a one-year program that includes toll-free advanced telephone access Monday through Friday and on-site service in the unlikely event of any hardware failure. Epson Preferred Plus extended service plans are available to provide coverage for up to two additional years. For more information, visit proimaging.epson.com.

LinkWithin

Blog Widget by LinkWithin

Ad