
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am getting a "'Autodesk.Revit.UI.Macros.ApplicationEntryPoint.Application' is a 'property' but is used like a 'type' (CS0118) - C:\ProgramData\Autodesk\Revit\Macros\2014\Revit\AppHookup\module1\Source\module1\ThisApplication.cs:44,5" error at the underlined part of the code. I am new to coding and I just want to be able to use the macro below. Any help would be appreciated.
/*
* Created by SharpDevelop.
* User: JGomez
* Date: 10/6/2015
* Time: 8:43 AM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using System.Collections.Generic;
using System.Linq;
namespace module1
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.DB.Macros.AddInId("7ABD34CC-5DC0-43E5-8B0C-99B95643040A")]
public partial class ThisApplication
{
private void Module_Startup(object sender, EventArgs e)
{
}
private void Module_Shutdown(object sender, EventArgs e)
{
}
#region Revit Macros generated code
private void InternalStartup()
{
this.Startup += new System.EventHandler(Module_Startup);
this.Shutdown += new System.EventHandler(Module_Shutdown);
}
#endregion
public void macro1()
{
UIDocument uidoc = this.ActiveUIDocument;
Document doc = uidoc.Document;
Application app = doc.Application;
// Get the family symbol named "North Arrow 2"
FamilySymbol famSym = new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol)).Where(q => q.Name == "North Arrow 2").First() as FamilySymbol;
// use a transaction group so that all the individual transactions are merged into a single entry in the Undo menu
// this is optional
using (TransactionGroup tg = new TransactionGroup(doc,"Create and Orient Instances"))
{
tg.Start();
// create an infinite loop so user can create multiple instances in a single command
// ESC when prompted to select a point will thrown an exception which is how the loop is exited
while (true)
{
try
{
XYZ pickPoint = uidoc.Selection.PickPoint("Click to specify instance location. ESC to stop placing instances.");
FamilyInstance familyInstance = null;
// Create the instance with the default orientation
// This is done in its own transaction so that the user can see the new instance when they are prompted for the orientation
using (Transaction t = new Transaction(doc,"Place Instance"))
{
t.Start();
familyInstance = doc.Create.NewFamilyInstance(pickPoint, famSym, doc.ActiveView);
t.Commit();
}
XYZ orientPoint = uidoc.Selection.PickPoint("Click to specify orientation. ESC to stop placing instances.");
// Create a line between the two points
// A transaction is not needed because the line is a transient element created in the application, not in the document
Line orientLine = app.Create.NewLineBound(pickPoint, orientPoint);
// Compute the angle between the vertical direction (XZY.BasisY) and the orientLine
double angle = XYZ.BasisY.AngleTo(orientLine.Direction);
// For diagnostics in Task dialog below
double angleDegrees = angle * 180 / Math.PI;
// AngleTo always returns the smaller angle between the two lines (for example, it will always return 10 degrees, never 350)
// so if the orient point is to the left of the pick point, then correct the angle by subtracting it from 2PI (Revit measures angles in degrees)
if (orientPoint.X < pickPoint.X)
angle = 2 * Math.PI - angle;
// To show the need for angle corrections
double angleDegreesCorrected = angle * 180 / Math.PI;
//TaskDialog.Show("info","Angle directly from AngleTo = " + angleDegrees + "\n Angle after X correction = " + angleDegreesCorrected);
// Create an axis in the Z direction
Line axis = app.Create.NewLineBound(pickPoint, new XYZ(pickPoint.X, pickPoint.Y, pickPoint.Z + 10));
using (Transaction t = new Transaction(doc,"Orient Instance"))
{
t.Start();
ElementTransformUtils.RotateElement(doc, familyInstance.Id, axis, -angle);
t.Commit();
}
}
catch
{
// Get here when the user hits ESC when prompted for selection
// "break" exits from the while loop
break;
}
}
// Consolidate all the transactions for the individual creation / rotation transactions into a single Undo item
tg.Assimilate();
}
}
}
}
Solved! Go to Solution.