Community
InfraWorks Forum
Welcome to Autodesk’s InfraWorks Forums. Share your knowledge, ask questions, and explore popular InfraWorks topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Change viewport elevation using this script

3 REPLIES 3
Reply
Message 1 of 4
elliott.rosenfeld
2192 Views, 3 Replies

Change viewport elevation using this script

move_to_elevation.jpg

 

Use this script to change your viewport elevation. The elevation uses the units of measurement specified in your model, so if you are using meters to report elevation, then your changes to viewport elevation will adjust in meters as well:

 

1) Copy and paste this code into a code editor application such as Notepad++, and save this to extensible markup language as "movetoelevation.ui" within the C:\Program Files\Autodesk\InfraWorks 360 folder. Note: You can also directly download this file. The download link is included within this BIMagination blog post: http://autodesk.typepad.com/bimagination/2016/04/change-viewport-elevation-using-this-script.html

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>Dialog</class>
 <widget class="QDialog" name="Dialog">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>230</width>
    <height>103</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>Move To Elevation</string>
  </property>
  <widget class="QDialogButtonBox" name="buttonBox">
   <property name="geometry">
    <rect>
     <x>130</x>
     <y>60</y>
     <width>75</width>
     <height>25</height>
    </rect>
   </property>
   <property name="orientation">
    <enum>Qt::Horizontal</enum>
   </property>
   <property name="standardButtons">
    <set>QDialogButtonBox::Cancel</set>
   </property>
  </widget>
  <widget class="QPushButton" name="moveElevation">
   <property name="geometry">
    <rect>
     <x>20</x>
     <y>60</y>
     <width>100</width>
     <height>25</height>
    </rect>
   </property>
   <property name="text">
    <string>Move to Elevation</string>
   </property>
  </widget>
  <widget class="QLineEdit" name="txtElevation">
   <property name="geometry">
    <rect>
     <x>20</x>
     <y>30</y>
     <width>191</width>
     <height>20</height>
    </rect>
   </property>
   <property name="text">
    <string>2</string>
   </property>
  </widget>
  <widget class="QLabel" name="label">
   <property name="geometry">
    <rect>
     <x>20</x>
     <y>10</y>
     <width>131</width>
     <height>16</height>
    </rect>
   </property>
   <property name="text">
    <string>Elevation above surface</string>
   </property>
  </widget>
 </widget>
 <resources/>
 <connections>
  <connection>
   <sender>buttonBox</sender>
   <signal>accepted()</signal>
   <receiver>Dialog</receiver>
   <slot>accept()</slot>
   <hints>
    <hint type="sourcelabel">
     <x>248</x>
     <y>254</y>
    </hint>
    <hint type="destinationlabel">
     <x>157</x>
     <y>274</y>
    </hint>
   </hints>
  </connection>
  <connection>
   <sender>buttonBox</sender>
   <signal>rejected()</signal>
   <receiver>Dialog</receiver>
   <slot>reject()</slot>
   <hints>
    <hint type="sourcelabel">
     <x>316</x>
     <y>260</y>
    </hint>
    <hint type="destinationlabel">
     <x>286</x>
     <y>274</y>
    </hint>
   </hints>
  </connection>
 </connections>
</ui>

2) Open InfraWorks 360 and navigate to the position in your model where you want to adjust the viewport elevation. 

3) Open the Scripting Console.

4) Copy and paste this script into the Scripting Area: 

// Global variables
var db = app.ActiveModelDb; // handle for open model database
var model = app.ActiveModel; // active model
var doc = app.ActiveDocument(); // active document
var dbWkt = app.ActiveModel.CoordSysWkt;
var wkt = app.GetBestFittingUTM84ProjectionWkt(model.Boundary.BBox2d, dbWkt);

// Load the UI
var form = ui.LoadForm("movetoelevation.ui");
form.findChild("moveElevation").clicked.connect(MoveToElevation);

function MoveToElevation() {
	// height to adjust from surface 
	var hgt = (parseFloat (form.findChild("txtElevation").text));

	var posDom = model.GetViewPoint()["pos"];
	var pos = new adsk.Vec3d(posDom[0], posDom[1], posDom[2]); // create Vec3d from DOM
	//print("posWorld: " + pos.X + "," + pos.Y + "," + pos.Z);

	// Transform from world into DB
	var posDB = model.Transforms.transformWorld2DB(pos);
	print("Position: " + posDB.X + "," + posDB.Y + "," + posDB.Z);

	var ePnt = doc.FindElevation(new adsk.Vec3d(posDB.X, posDB.Y, 0));
	print("Existing surface elevation: " + ePnt.Z);

	// Elevate camera above surface level
	ePnt.Z += hgt;
	print("New surface elevation: " + ePnt.Z);
	print("------------------------------------------");

	// transform DB back to world
	pos = model.Transforms.transformDB2World(ePnt);
	var resDom = {
		pos : [pos.X, pos.Y, pos.Z]
	};
	model.SetViewPoint(resDom);
}

form.show();
gc();

5) Click Start Script. A dialog will appear in your model.

elevation_ui.jpg

 

6) Add an elevation offset value and click Move to Elevation.

The script adjusts your viewport elevation based on the ground surface elevation for your location. Therefore, if your ground surface elevation (*reported by the Z: value in the Status Bar) is already 180 meters, and you want your viewport to instead be at 250 meters elevation, then you would enter 70 into the Move to Elevation dialog.

 

7) The Scripting Console will report the elevation change, so you can double-check your original and updated viewport elevation.

script_evaluation.jpg


Principal Specialist, Infrastructure
3 REPLIES 3
Message 2 of 4

This is a high-quality information!


Eduardo Soethe Cursino
Civil Eng. | BIM Specialist
Soethe Cursino Consultoria | BIM for Infrastructure | LinkedIn



Autodesk Certified BIM Specialist: Road and Highways Solution
AutoCAD Civil 3D Certified Professional
AutoCAD Certified Professional
__________________________________________________________________________
Se a resposta resolveu o seu problema, clique em Aceitar como Solução isso ajuda os outros usuários a encontrar rapidamente uma reposta e Kudos de gostou.
Autodesk Community

Message 3 of 4
sduffin
in reply to: elliott.rosenfeld

Just curious how you got the cross walk striping in?  Thanks for your excellent posts!

Message 4 of 4

The crosswalk striping in that photo is actually a default decoration called "zebra cossing" that you can add to road styles. You can find it here:

zebra_crossing.png

 

 


Principal Specialist, Infrastructure

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report