So in the last post I showed how to pull out panels and put them back. We may want to add additional commands to the panel, such as a save button. This way the panel will contain all of the often used commands I might need. To do this follow the steps in this video: http://screencast.com/t/uKZM763ysc
Friday, October 31, 2014
Often times we will want all the time access to a ribbon or tab panel. Don’t forget all of the panels may be removed from the Ribbon and made to act like a large rectangular toolbar. To do this click and drag on as white space on the panel and then move it away from the ribbon. It should then pop out. To put it back you can hover over the panel and then press the arrow in the upper right hand corner of the reappearing portion of the panel.
Here is a short video (without sounds) showing the steps: http://screencast.com/t/X60b9PjmPh
Thursday, October 09, 2014
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 = header.Range
headerRange.SetRange(header.Range.End - 1, header.Range.End)
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
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.
Thursday, September 25, 2014
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.
public class SetReferenceTextTargetTest
public static void runCommand()
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
Database db = HostApplicationServices.WorkingDatabase;
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;
catch (System.Exception ex)
System.Windows.Forms.MessageBox.Show("Autodesk quality control sucks!: Here is proof: " + ex.Message);