Fixed it by unchecking "Use Managed Compatibility Mode"
Tools->Options->Debugging->General->"Use Managed Compatibility Mode"
Fixed it by unchecking "Use Managed Compatibility Mode"
Tools->Options->Debugging->General->"Use Managed Compatibility Mode"
Dear All,
I was using RevitPythonShell for a while, and was very happy with the instant output and ability to verify the code.
Now Im building the whole Toolbox in Visual Studio in c#, and was wondering whether there is something similar for c#? Or what are you best practices to imidiatedly test your code?
For now Im translating bits of code from c# to python again, but Im sure there is more efficient way of doing this...
Any help, much appreciated,
Best, Luki
Hello
I found the loadfrom
in vb.net
attached code in image.
the code consists of searching all the cadlinks of Revit
to then select a DWG for later
Change the cadlink in the textbox.
regards
Hello!
Newbie question, sorry :)
I need to get value of the "Structural Material" parameter of the plate and copy it to another material parameter of the same plate. Do the same for the thickness.
Repeat for all plates in the model. Here is the code of existing macro that I am trying to add:
using System;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using System.Collections.Generic;
using System.Linq;
using RVTDocument = Autodesk.Revit.DB.Document;
using ASDocument = Autodesk.AdvanceSteel.DocumentManagement.Document;
using RVTransaction = Autodesk.Revit.DB.Transaction;
using Autodesk.Revit.DB.Steel;
using Autodesk.Revit.DB.Structure;
using Autodesk.AdvanceSteel.DocumentManagement;
using Autodesk.AdvanceSteel.Geometry;
using Autodesk.AdvanceSteel.Modelling;
using Autodesk.AdvanceSteel.CADAccess;
namespace PlateTest
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.DB.Macros.AddInId("B80DC6C6-1C7E-4DFF-9C93-B1446D138A80")]
public partial class ThisDocument
{
private void Module_Startup(object sender, EventArgs e)
{
}
private void Module_Shutdown(object sender, EventArgs e)
{
}
public void Start()
{
RVTDocument doc = this.Document;
List<SteelProxyElement> plates = new FilteredElementCollector(doc)
.WhereElementIsNotElementType()
.OfClass(typeof(SteelProxyElement))
.Cast<SteelProxyElement>()
.Where(i => i.GeomType == GeomObjectType.Plate)
.ToList();
List<StructuralConnectionHandler> joints = new FilteredElementCollector(doc)
.WhereElementIsNotElementType()
.OfClass(typeof(StructuralConnectionHandler))
.Cast<StructuralConnectionHandler>()
.ToList();
List<PlateInJoint> jointPlates = new List<PlateInJoint>();
using(RvtDwgAddon.FabricationTransaction t = new RvtDwgAddon.FabricationTransaction(doc, true, "Test plates"))
{
foreach(StructuralConnectionHandler joint in joints)
{
List<Subelement> subelems = joint.GetSubelements().ToList();
foreach(Subelement subelem in subelems)
{
if(subelem.Category.Id != new ElementId(BuiltInCategory.OST_StructConnectionPlates)) continue;
PlateInJoint pij = new PlateInJoint();
pij.subelem = subelem;
Reference rf = subelem.GetReference();
FilerObject filerObj = this.GetFilerObject(doc, rf);
Plate pl = filerObj as Plate;
double vol = pl.Volume / (1000000 * 29.504);
pij.plate = pl;
pij.volume = vol;
jointPlates.Add(pij);
}
}
}
View calculateView = this.ActiveView;
using(RVTransaction t = new RVTransaction(doc))
{
t.Start("Plate weight");
foreach(SteelProxyElement plate in plates)
{
Options opt = new Options() { View = calculateView };
GeometryElement geoElem = plate.get_Geometry(opt);
Solid sol = geoElem.First() as Solid;
ElementId mid = plate.get_Parameter(BuiltInParameter.STRUCTURAL_MATERIAL_PARAM).AsElementId();
double density = this.GetMaterialDensity(mid);
double vol = sol.Volume;
double mass = vol * density;
plate.LookupParameter("Volume").Set(vol);
plate.LookupParameter("Mass").Set(mass);
}
foreach(PlateInJoint pij in jointPlates)
{
Subelement subelem = pij.subelem;
ParameterValue pv = subelem.GetParameterValue(new ElementId(BuiltInParameter.STRUCTURAL_MATERIAL_PARAM));
ElementIdParameterValue idpv = pv as ElementIdParameterValue;
ElementId mid = idpv.Value;
double density = this.GetMaterialDensity(mid);
double mass = pij.volume * density;
List<ElementId> paramIds = subelem.GetAllParameters().ToList();
foreach(ElementId paramId in paramIds)
{
BuiltInParameter bparam = (BuiltInParameter)paramId.IntegerValue;
Element param = doc.GetElement(paramId);
if(param == null) continue;
if(param.Name == "Volume")
{
DoubleParameterValue dpv = new DoubleParameterValue(pij.volume);
subelem.SetParameterValue(paramId, dpv);
}
if(param.Name == "Mass")
{
DoubleParameterValue dpv = new DoubleParameterValue(mass);
subelem.SetParameterValue(paramId, dpv);
}
}
}
//catch{ }
t.Commit();
}
}
private double GetMaterialDensity(ElementId materialId)
{
RVTDocument doc = this.Document;
Material material = doc.GetElement(materialId) as Material;
PropertySetElement materialStructuralParams = doc.GetElement(material.StructuralAssetId) as PropertySetElement;
double density = materialStructuralParams.get_Parameter(BuiltInParameter.PHY_MATERIAL_PARAM_STRUCTURAL_DENSITY).AsDouble();
return density;
}
private FilerObject GetFilerObject(RVTDocument doc, Reference eRef)
{
FilerObject filerObject = null;
ASDocument curDocAS = DocumentManager.GetCurrentDocument();
if (null != curDocAS)
{
OpenDatabase currentDatabase = curDocAS.CurrentDatabase;
if (null != currentDatabase)
{
Guid uid = SteelElementProperties.GetFabricationUniqueID(doc, eRef);
string asHandle = currentDatabase.getUidDictionary().GetHandle(uid);
filerObject = FilerObject.GetFilerObjectByHandle(asHandle);
}
}
return filerObject;
}
#region Revit Macros generated code
private void InternalStartup()
{
this.Startup += new System.EventHandler(Module_Startup);
this.Shutdown += new System.EventHandler(Module_Shutdown);
}
#endregion
}
public class PlateInJoint
{
public Subelement subelem;
public Plate plate;
public double mass;
public double volume;
public ElementId materialId;
}
}
Please help!!!
Hi,
I create a api to create an area reinforcement in a floor like this.
But, when I try to edit the boundary curve of area reinforcement. it will be like this.
the end POINT of boundary curve is not connect to adjacent curve.
this situation is not same as create by Revit tool(Structural Area Reinforcement).
The boundary curve can connect to adjacent curve.
Because it will cause me a serious problem as I try to modify it by another api.
Please refer My api code is in Attachments.
Would you please help me how to fix my API connect to adjacent curve.
Thank a lots.
James
using System;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB.Structure;
using System.Windows.Forms;
using System.Collections.Generic;
namespace Revit.Reinf
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
[Autodesk.Revit.Attributes.Journaling(Autodesk.Revit.Attributes.JournalingMode.NoCommandData)]
public class CreateFloorAreaReinforcement_Test : IExternalCommand
{
private ExternalCommandData m_revit;
private UIApplication m_uiApp;
private UIDocument m_uidoc;
private Document m_doc;
public Result Execute(ExternalCommandData revit, ref string message, ElementSet elements)
{
m_revit = revit;
m_uiApp = m_revit.Application;
m_uidoc = m_uiApp.ActiveUIDocument;
m_doc = m_uidoc.Document;
try
{
Reference re = m_uidoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element, "Select a Floor");
using (Transaction Tr = new Transaction(m_doc, "Create Floor Area Reinf."))
{
Tr.Start();
Floor f = m_doc.GetElement(re) as Floor;
try
{
XYZ floorDir = new XYZ(10000 * Math.Cos(f.SpanDirectionAngle), 10000 * Math.Sin(f.SpanDirectionAngle), 0);
ElementId rebarBarTypeId = m_doc.GetDefaultElementTypeId(ElementTypeGroup.RebarBarType);
ElementId areaReinforcementTypeId = AreaReinforcementType.CreateDefaultAreaReinforcementType(m_doc);
ElementId rebarHookTypeId = ElementId.InvalidElementId;
IList<CurveLoop> outerLoops = new List<CurveLoop>();
IList<CurveLoop> innerLoops = new List<CurveLoop>();
outerLoops= GetFloorCurveLoops(f);
foreach (CurveLoop clop in outerLoops)
{
IList<Curve> cs = new List<Curve>();
foreach (Curve cur in clop)
{
cs.Add(cur);
}
AreaReinforcement AreaRein = AreaReinforcement.Create(m_doc, f, cs, floorDir, areaReinforcementTypeId, rebarBarTypeId, rebarHookTypeId);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
if (TransactionStatus.Committed != Tr.Commit())
{
Tr.RollBack();
return Result.Failed;
}
return Autodesk.Revit.UI.Result.Succeeded;
}
}
catch
{
return Autodesk.Revit.UI.Result.Cancelled;
}
}
private IList<CurveLoop> GetFloorCurveLoops(Floor f)
{
IList<CurveLoop> outerLoops=new List<CurveLoop>();
IList<Reference> sideFaces = null;
sideFaces = HostObjectUtils.GetTopFaces(f);
Element e = m_doc.GetElement(sideFaces[0]);
Face face = e.GetGeometryObjectFromReference(sideFaces[0]) as Face;
// Get edge loops as curve loops.
IList<CurveLoop> curveLoops = face.GetEdgesAsCurveLoops();
foreach (CurveLoop curveLoop2 in curveLoops)
{
outerLoops.Add(curveLoop2);
}
return outerLoops;
}
}
}
Follow this topic :
https://thebuildingcoder.typepad.com/blog/2014/05/on-handling-warnings-and-failures.html
We just can dismiss warning when we committed transaction,we want some of warnings to process with commit , and some of warning to cancel. But to save time ,we dont allow revit regenerate document many times so we commit transaction of the end of process.
Can I dismiss warning before I commit transaction,
I have a similar Problem. I want two know how to merge two parallel walls into a single multilayered wall which can be detected by the getboundry-function.
Is there a other way how can i get all sheets to list more quickly. If i have about 300 sheets Its loading too long.
Some precache or ???
today. im have error like you. you can try method setlayers().
http://www.revitapidocs.com/2018/0392b682-451d-5399-54b5-44373ce941c6.htm
wrote: CompoundStructure structure = wallType.GetCompoundStructure(); int layerCount = structure.LayerCount; for (int j = 1; j < layerCount; j++) { Material material = doc.GetElement(structure.GetMaterialId(j)) as Material; double width = structure.GetLayerWidth(j) * 304.8; string newWallTypeName = material.Name + "_" + width.ToString() + "mm"; TaskDialog.Show("newName", newWallTypeName); newType.Add(newWallTypeName); } using (Transaction trans = new Transaction(doc, "delete Layer")) { trans.Start(); for (int j = 1; j < layerCount; j++) { if (structure.DeleteLayer(1)) { TaskDialog.Show("!#!G", "MJAEINAIJ"); } } trans.Commit(); }I can successfully extract data in layers. After that , i want to delete all layers except the first one.
From my code, structure.DeleteLayer(1) return true;
and it returns error (Array out of range ) when i try to print out materials in layers that have been deleted.
It seems working perfectly, however, when i open revit , those layers remain there/
wrote: CompoundStructure structure = wallType.GetCompoundStructure(); int layerCount = structure.LayerCount; for (int j = 1; j < layerCount; j++) { Material material = doc.GetElement(structure.GetMaterialId(j)) as Material; double width = structure.GetLayerWidth(j) * 304.8; string newWallTypeName = material.Name + "_" + width.ToString() + "mm"; TaskDialog.Show("newName", newWallTypeName); newType.Add(newWallTypeName); } using (Transaction trans = new Transaction(doc, "delete Layer")) { trans.Start(); for (int j = 1; j < layerCount; j++) { if (structure.DeleteLayer(1)) { TaskDialog.Show("!#!G", "MJAEINAIJ"); } } trans.Commit(); }I can successfully extract data in layers. After that , i want to delete all layers except the first one.
From my code, structure.DeleteLayer(1) return true;
and it returns error (Array out of range ) when i try to print out materials in layers that have been deleted.
It seems working perfectly, however, when i open revit , those layers remain there/
You don't mention if you have added the line:
wallType.SetCompoundStructure(structure);
Just before trans.Commit();
ie,
wallType.SetCompoundStructure(structure); // structure now contains your reduced list of layers.
trans.Commit();
That committed the new (reduced) layers for me.
Hey all,
Quick question but I could not find the answer (nor find a correct solution) :
I create dimensions automatically (using Document.Create.NewDimension).
This method requires 3 arguments : a view, a Line (the line on which you put your dimensions), and a ReferenceArray in which you put all the points (in fact it's lines too) where you make the quotation.
The last argument is based in the documentation on real DetailLines which you need to create (using Document.Create.NewDetailCurve and then Curve.GeometryCurve.Reference).
If I don't create the DetailCurves I get an error.
The question is : is there a way to create the dimension without creating the DetailLines (which as time goes by are many, ugly, etc...)
Thanks
Benoit
Just to understand your need : what do you want to do with these Sheets ?
If the aim is just to have a list of all sheets : create a Schedule.
If you want to print all your presentations... there are cheap add-in for that.
Benoit
Hey James,
I have never worked with AreaReinforcement but the analogy with Rooms seems pertinent...
I guess what you call a BoundaryCurve is rather an IList<BoundarySegment>. You can easily loop on every BoundarySegment and check if it is connected to the previous one. If it is not, connect it !!
// Your BoundaryCurve, to be adapted...
IList<BoundarySegment> myContour = se.GetBoundarySegments(new SpatialElementBoundaryOptions())[0];
IList<Curve> myModifiedContour = new List<Curve>();
for (int i = 0; i < myContour.Count; i++)
{
BoundarySegment bs1 = myContour[i];
BoundarySegment bs2 = myContour[(i < myContour.Count - 1) ? i + 1 : 0];
myModifiedContour.Add(bs1.GetCurve());
if ((bs1.GetCurve().GetEndPoint(1) - bs2.GetCurve().GetEndPoint(0)).GetLength() > uiApp.Application.ShortCurveTolerance)
{
Line myLine = Line.CreateBound(bs1.GetCurve().GetEndPoint(1), bs2.GetCurve().GetEndPoint(0));
myModifiedContour.Add(myLine);
}
}
Hope this helps
Benoit
Your code is way too long for us (at least for me) to check.
Find what is really blocking and come back with a simple 10 lines piece of code / clear question so we can check it with you.
Benoit
I'm not sure if it answers your need but check the Add-in Manager, which is included in the SDK.
It allows you to build your .dll outside Revit and launch it in Revit immediately.
https://thebuildingcoder.typepad.com/blog/2011/05/debugging-an-add-in-without-restarting-revit.html
Benoit
Hi Geoff,
Thanks for taking your time to help me. I wil try your good solution!
I also find this way to get walls by name using linq and it's also working well with placing a new familyinstance.
But maybe your solutions is better and faster for the ram?
public IEnumerable<Wall> CollectWallsByName(Document doc, string name) { FilteredElementCollector collector = new FilteredElementCollector(doc); IList<Element> elements = collector.OfClass(typeof(Wall)).ToElements(); // Use a LINQ to filter name IEnumerable<Wall> collectWalls = from wall in elements.Cast<Wall>() where wall.Name == name select wall; return collectWalls; }
public void ChangeWallType(Document doc) { foreach (Wall w in CollectWallsByName(doc, "Wall 1")) { //do your thing } }
I get the same error in Revit 2019. The only things i changed about the https://github.com/jeremytammik/DockableDialog repository are:
To reproduce the rror:
Revit crashes with the following message
System.InvalidOperationException: 'BuildWindowCore failed to return the hosted child window handle.'
When I remove the WebBrowser component from the sample, it works just fine.
When I add the WebBrowser after loading the component and remove it immediately after adding, Revit will crash when opening a new document.
So my guess is the WebBrowser component is causing the trouble here.
Does anyone has any insight on this issue?
Hi,
I tried the first part but do you also get an error when collecting walls like the picture below?
Thanks again!
Hi Benoit!
This code works fine, no need to check. I just need to add the code so that it copies the material and the thickness of the plate and inserts it into another parameter of the same plate.
I'm sure I tripped some option that makes this appear. I'm interested to learn what it does and how to turn it off. Thanks.
Appears in Revit while debugging