Ad

Thursday, March 08, 2012

Alignment Length Report

A long time ago I created an Alignment Length Report that created a report of all of the alignment lengths. The post was done utilizing VBA. Since VBA is on the way out, and I got a request for an updated report I decided to update the older blog post.

The first step is to dig out a starting point. In this case I decided to start with the Pipe Sample code located in this location: C:\Program Files\Autodesk\AutoCAD Civil 3D 2011\Sample\Civil 3D API\DotNet\VB.NET\PipeSample

Once we have it, open it up in Microsoft Visual Studio Express for VBA (or the professional version of the software). Next load the references, loading them is from the Project Properties.

image

Since we are going to export the data to Excel, we will need to add the Microsoft.Office.Interop.Excel. You may find that at the location in the image below or you will find it here: C:\ProgramData\Autodesk\C3D 2011\enu\Data\Reports\Net

image

I’m going to use PipeSample command and call it AlignmentsLengthReport. Delete the lines shown below.

image

Next change the Imports Statement to go from PipeNetwork to Land.

image

Also add “Imports Excel = Microsoft.Office.Interop.Excel” to the list.

Next delete all of the code blocks that are complaining in the error list. Make sure to keep the GetBaseObjects() function.

Now we can put in the code.

    <CommandMethod("AlignmentsLengthReport")> _
Public Sub CommandPipeSample()
Try
GetBaseObjects()
Using m_tm.StartTransaction
If m_bIsCreated = False Then
Dim excelApp As Excel.Application
Dim excelWorkbook As Excel.Workbook
Dim excelSheet As Excel.Worksheet

excelApp = CreateObject("Excel.Application")
excelApp.Visible = True

' Get a new workbook
excelWorkbook = excelApp.Workbooks.Add
excelSheet = excelWorkbook.ActiveSheet

Dim row As Integer = 1
Dim column As Integer = 1

excelSheet.Cells(row, 1).Value = "Alignment Name"
excelSheet.Cells(row, 2).Value = "Alignment Length"

row += 1

Dim objIds As ObjectIdCollection = m_oDocument.GetAlignmentIds()
For Each alignmentObjId As ObjectId In objIds
Dim alignment As Alignment = DirectCast(alignmentObjId.GetObject(OpenMode.ForRead), Alignment)
excelSheet.Cells(row, 1).Value = alignment.Name
excelSheet.Cells(row, 2).Value = alignment.Length
row += 1
Next
ElseIf m_bIsCreated Then
MsgBox("Please zoom to the network with the name of " + NETWORK_NAME)
End If
End Using
Catch
m_doc.Editor.WriteMessage("Error outputting results")
End Try
End Sub



The code creates a worksheet in Excel and then goes through each alignment and exports the alignment example. The code works better than the older version in that it directly gets the alignments, rather then going through all of the objects in the drawing looking for them.



The source code and dll may be found here. It is contained within a ZIP file, but the file extension has been changed to Change. Change the file extension to zip and extract the contents. Click on the dll and go to it’s properties and choose to Unblock the file. Once in Civil 3D 2011 type NETLOAD at the command line. Then type the AlignmentsLengthReport at the command line. It will then open Excel and output the results.



If you want to use the program in a different version of Civil 3D you will need to update the references and rebuild the project.

Saturday, February 18, 2012

Solr Installation, I Suck

I’ve tried installing stuff from the Apache Software Foundation before and haven’t had much luck. Today I’m determined to get Solr installed. If I succeed these are the steps I used.

First I downloaded and installed Java SE Development Kit from the Oracle website. I used the default location, but it looks like Apache would prefer you install it in the C:\jdk1.7.0_03 folder, but I installed it in the default folder.

Next I downloaded the ANT thingamajig and unzipped it and placed it in the C:\ANT folder. In order to get it to work we create the user variables in the control panel. The install documents also say you can run the set at the command line, but I’m not quite sure if that works. I did notice that I needed to type

set PATH=%PATH%;%ANT_HOME%\bin



at the command line in order to get ANT to work. If I close the command window I have to retype the string again. I’m sure there has to be a way to have this persist, but I couldn’t figure out how to do it.



image



Next open the Command Prompt. To do this go to the Start Menu and type run at the Search Programs and Files. Next type CMD to get the command prompt to open. Using cd.. go back a folder location, and then use the folder names to go the direction you want to go to.



SNAGHTMLdf7d966



You’ll want to end up in the folder location with the example code.



SNAGHTMLdf266e6



The folder contains the start.jar file. This is what is going to start the example. To start it type



java –jar start.jar



at the command line. This will start Solr using the example that comes with the Solr installation.



If you open a web browser and enter http://localhost:8983/solr/admin/ you can see that the installation is running. So yeah, I was able to figure it out and I have the steps to do it again, with some pictures.



image 



Next we need to load the data into the Solr that is running. To do this open a new command window and get to the example docs folder using the method above. Then type java –jar post.jar solr.xml monitor.xml to load the data into the Solr that is running into the other command window. This should load the data.



Still need to figure out how other things work, but at least I got it working.

Monday, February 06, 2012

XSL Reporting

When modifying the XSL Reporting you may want to make sure you are using the correct folder. The Report files are stored in this location, replacing the year with your product.

C:\ProgramData\Autodesk\C3D 2012\enu\Data\Reports\xsl

As long as you are running the reports from within Civil 3D you should be good to go. If you are using the LandXML reporting then you might end up with some problems. The Reporting tool typically utilizes the most recent version of Civil 3D (or maybe the last installed version, I don’t really know). So make sure the reports are utilizing the correct version you have modified. You can check by looking at the file location on the Forms Tab of the LandXML Reporting Tool:SNAGHTML7e8d1e8

I guess I should really start using the Last Modified By: field.

Saturday, February 04, 2012

Profile Blues

So I’m creating a profile in Civil 3D. Everything is going great. I’m able to open the program, set my profile and start working with Civil 3D. Then I get the big idea of setting my profile in the shortcut icon. This way whenever I start Civil 3D I’ll get my profile.

Suddenly I now have problems, big problems. The C that stands for Civil 3D in the upper left hand corner is now an A. Switching workspaces causes fatal errors. Sometimes the icons on the ribbon become question marks in clouds. The question marks may be living on cloud nine, but I’m far from it. What the heck did I do wrong?

It turns out the problem is how I created the profile. I created the profile from an AutoCAD based profile. Not quite sure how I got started with an AutoCAD based profile. It may have been because there is a profile in the default profile list in Options.

SNAGHTML35debb

The solution to recreate your profile using a Civil 3D profile. Maybe the <<C3D_Imperial>> or the <<C3D_Metric>> profile. This way you won’t have any issues like I have. If you do see the A in the corner you probably have this issue.

Tuesday, January 31, 2012

Rounding

You might not have noticed, or no one told you, but computers suck at math. Well more specifically they suck at rounding. I’ve been told JavaScript especially sucks at math, and one should avoid using it for Math. I guess that’s why Autodesk choose to use JavaScript to do the reporting within Civil 3D for the XSL type reports.

One such report is the Inverse_Report. You may notice that some of your bearings are slightly off. This is because of floating precision that computers use and the method Autodesk has chosen to round numbers. To fix this error we can use a common method to round the value to the correct number. To do this travel to the folder that holds the XSL reporting files:

C:\ProgramData\Autodesk\C3D 2012\enu\Data\Reports\xsl

Next open the General_Formating_JScript.xsl, if you are on my computer it will be on the top if you sort by Date modified (your results may vary). Once you open the file look for:

var anglePrec = 3;

If you want your bearings to be rounded to the nearest second change the value from 3 to 0. For any other rounding values, change it to the desired precision. Unsure why this wasn’t included in the Parcel settings within Civil 3D. This is just a diversion from the task at hand, otherwise known as padding.

Next scroll down until you reach this code snippet:

function formatAngleNumber(number)
{
var strFormatted;
strFormatted = number.toFixed(anglePrec);
return strFormatted;
}



Change the above code to the following:



function formatAngleNumber(number)
{
var strFormatted;
// strFormatted = number.toFixed(anglePrec);
strFormatted = Math.round(number * Math.pow(10, anglePrec)) / Math.pow(10, anglePrec);
return strFormatted;
}



The // comments out the original line of code. The next line makes the number large and then divides the resulting math by a large number to make it small again. By doing this we can hopefully eliminate the rounding issue.

LinkWithin

Blog Widget by LinkWithin