API to write an ASCII comma delimited point file (of X,Y,Z values)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Problem statement:
Using the Navisworks API to write an ASCII comma delimited point file (of X,Y,Z values) is the goal here.
Background:
Within the Navis Manage environment we coordinate routing of piping, conduits, and other utilities through congested areas. The ability to output coordinates within the Navis environment has a place next to switchback within the workflow.
Initially reading the points (X,Y,Z) from the “measure tools” object appears to be a logical approach.
An example of our work flow:
Figure A above
Using the sample model “west” included with the installation we select the “Point Line” option on “Review” tab, while displaying the “Measure Tools” dialog.
Selecting four points, we copy and paste the XYZ value to a .txt file.
Figure B above
Using AutoCAD and AutoLISP, we create 3D Polyline, and extrude a circle along it.
Figure C above
Back in Navis we Append the AutoCAD file.
The core objective here is to reduce the tedious cut and paste step of collecting coordinates from the “Measure Tools” dialog.
The envisioned solution:
We know certain prerequisites will exist in our .NET C# code per the Autodesk API plugin examples.
The Navisworks API must be downloaded / Installed and confirmed operational.
A programmers Integrated Development (IDE) is required, in our case Microsoft Visual Studio 2022 (VS).
The target framework .NET version of Navisworks API must be set in VS. (4.8 in our case)
(and a number of other VS setting, along with correct code structure, references, etc.) Best guidance is the example code supplied with the Autodesk API.
Those housekeeping details aside our initial C# .NET 4.8 approach using VS 2022 represents the development environment.
To start we used sample code Plugin “coderun” and tested the first few approaches.
Approach One:
// Start variation of BoundingBox3D in API Documentation that works in codeRun Navis
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Autodesk.Navisworks.Api;
namespace CScript
{
public class CScript
{
static public void Main()
{
Point3D centreOfBox = null;
// string variableXYZ = "1,2,3";
string variableABC = null;
BoundingBox3D bb3d = Autodesk.Navisworks.Api.Application.ActiveDocument.CurrentSelection.SelectedItems.BoundingBox();
centreOfBox = bb3d.Center;
variableABC = centreOfBox.ToString();
MessageBox.Show(Autodesk.Navisworks.Api.Application.Gui.MainWindow, variableABC );
}
}
}
// end working codeRun example.
This works as expected and the message box contains (1213.566, 789.976545, 0.000000)
Next we tried turning on the measure tool with the idea we would have access to the FirstPoint property.
// 6/19/2022 11:48:47 AM Current code stream: in coderun, Now returning firstpoint value
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Autodesk.Navisworks.Api;
namespace CScript
{
public class CScript
{
static public void Main()
{
// Variables
// Point3D pt0 = null;
string st0 = null;
// turn on measure tool
Autodesk.Navisworks.Api.Application.MainDocument.Tool.Value = Tool.MeasurePointLine;
// should be point obj DocumentCurrentMeasurement..::..EndPoint Property
Point3D container0 = Autodesk.Navisworks.Api.Application.MainDocument.CurrentMeasurement.FirstPoint;
// non-static field, method, or property 'Autodesk.Navisworks.Api.DocumentParts.DocumentCurrentMeasurement.FirstPoint.get';
// chg to str and set var to value
st0 = container0.ToString();
MessageBox.Show(Autodesk.Navisworks.Api.Application.Gui.MainWindow, st0 );
}
}
}
6/19/2022 11:48:47 AM Current code shown above now returning firstpoint value, so I'm moving to next step
6/26/2022 3:04:29 PM I learned:
1) I can make a New Empty Points List
Point3DList myPointList = new Point3DList();
2) put a point into that list
Point3D pnt1 = new Point3D(6217.2983254261298498, 6217.2983254261298498, 6217.2983254261298498);
3) Get the point from the list
Console.WriteLine(myPointList.ItemAt(2));
So now the process of collecting each point from the measure tool or mousedown event is a next step.
myPointList.Add(pnt1);
Greg