Quantcast
Channel: All Revit API Forum posts
Viewing all 66651 articles
Browse latest View live

[Revit API] Converts a "Revit Elements" to solids and creates a family.

$
0
0

Thank you for reading first.
What I'm trying to do is...
I'm going to make the "Revit Elements" into a single solid and write it in "Revit Family".

( The reason I do this is to control the generated solids.     Please refer to the picture!! )

Please help me.

 

Modifiable Object.PNG

 

#region Namespaces using System; using System.Collections.Generic; using System.Diagnostics; using Autodesk.Revit.ApplicationServices; using Autodesk.Revit.Attributes; using Autodesk.Revit.DB; using Autodesk.Revit.UI; using Autodesk.Revit.UI.Selection; using System.Linq; using System.Text; using System.IO; using System.Windows.Forms; #endregion namespace RibbonButton { [Transaction(TransactionMode.Manual)] public class Commend : IExternalCommand { #region string DirSearch(string start_dir, string filename_pattern) { foreach (string d in Directory.GetDirectories( start_dir)) { foreach (string f in Directory.GetFiles( d, filename_pattern)) { return f; } string f2 = DirSearch(d, filename_pattern); if (null != f2) { return f2; } } return null; } #endregion public UIDocument ActiveUIDocument { get; private set; } public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Autodesk.Revit.ApplicationServices.Application app = uiapp.Application; Document doc = uidoc.Document; // Code Start ↓ // Element selection IList<Reference> selectedConduits = uidoc.Selection.PickObjects(ObjectType.Element); // Solid Union Solid union = null; foreach (var item in selectedConduits) { SolidGeometry solidgeo = item as Solid; foreach (GeometryObject obj in solidgeo) { Solid solid = obj as Solid; if (null != solid && 0 < solid.Faces.Size) { if (null == union) { union = solid; } else { union = BooleanOperationsUtils.ExecuteBooleanOperation(union, solid,BooleanOperationsType.Union); } } } } // Create Generic Model using (Transaction trans = new Transaction(doc, "Transaction")) { try { trans.Start(); DirSearch(app.FamilyTemplatePath, "Metric Generic Model.rft"); trans.Commit(); } catch { } } // Code End ↑ return Result.Succeeded; } } }

 


Material Takeoff Schedule for Selected Elements

$
0
0

Hi,

I'm trying to understand if it's possible to create a Material Takeoff ViewSchedule for specific elements selected.

 

I know that I can create a schedule for the "Category" of the ElementIds of the selected elements:

schedule = ViewSchedule.CreateMaterialTakeoff(document, selectedElementCategoryId);

but I'm not sure if that's the same as the actual elements themselves.

 

Can anyone assist to clarify this?

 

Thanks

Re: Cancel EditFamily if error or corruption

$
0
0

Thanx RP, that answers my question there's no roll back after you have edited the family. 

Re: The document was opened detached, so saveascentral must be set to true?

Re: Modify Model Lines of an Existing Floor Slab

$
0
0

Unfortunately I do not believe this is possible at this time. You can create penetrations or openings in the floor, but not modify the actual boundary unless you recreate as you mentioned.

Re: Cancel EditFamily if error or corruption

$
0
0

Hi  ,

 

you can use an event to prevent an error and then you can use a RollBack to cancel the opening.

Look at this link : https://forums.autodesk.com/t5/revit-api-forum/ignore-warning-message-contraints-on-editfamily/td-p/9482670 

 

You can change the event for the search for "DocumentCorruption" type failures: :

 

private void App_FailuresProcessing(object sender, FailuresProcessingEventArgs e) { FailuresProcessingEventArgs fpArgs = e as FailuresProcessingEventArgs; FailuresAccessor accessor = fpArgs.GetFailuresAccessor(); FailureHandlingOptions op = accessor.GetFailureHandlingOptions(); op.SetClearAfterRollback(true); accessor.SetFailureHandlingOptions(op); foreach (FailureMessageAccessor msgAccessor in accessor.GetFailureMessages()) { if (msgAccessor.GetSeverity() == FailureSeverity.DocumentCorruption) { fpArgs.SetProcessingResult(FailureProcessingResult.ProceedWithRollBack) } } fpArgs.SetProcessingResult(FailureProcessingResult.Continue); }

 

 

😉

Re: Material Takeoff Schedule for Selected Elements

$
0
0

Probably not directly. You could try using .AddFilter and adding a selection filter but I assume that would fail since it isn't something you can do in the UI and Schedules don't support visibility graphics.

 

An indirect method may be to add a shared parameter value to all elements of the category and set a uniform value for the elements within the selection, then filter by that in the schedule. This is a standard approach within the UI so could definitely be automated with the API. Would use a unique string such as a GUID so that every time the command is run elements with the parameter set previously but not currently are filtered out. Don't use a Yes/No parameter because values for Yes will remain from previous in non-selected elements and you'll have to go though those to reset them rather than just setting a new string to filter with.

Getting parameters assigned to a label

$
0
0
 

Hi All,

 

I'm interested in getting a list of all the parameter names associated with a label. I'm able to get the labels.  I'm able to get the parameters OF the label.  I've scoured Revit Lookup but can't seem to find the parameters ASSIGNED to the label. 

 

I don't even need the actual parameters, just the parameter name strings, "Detail Number" etc.

 

Seems like it should be easy...

 

image.png

 

Regards,

 

James


Re: Automatic Heating and cooling load analysis with Revit API?

$
0
0

    

Does anybody have an update regarding this topic? 

is possible to extract heating and cooling load Analytical Surace with Revit Dynamo and export it to Excel? I wish to extract parameters like Wall Area and direction, Glazing Area.
The main goal is to extract the data of wall area and direction from Revit and import to other software to conduct heat load estimation(By HAP, excel sheet).

furthermore, the gbXML from Revit does not work, the walls seemed to broken up too much in the Revit model when I open using HAP or CVS since The Analytical Model that is produced from gbXML differs from the Physical Model that is in Revit Views. I believe the best way is to find an approach to extract data by API.

 

 

Re: ElementTransformUtils.CopyElements (from linked document)

$
0
0

 ,     Can this method, or any others, work for copying model views from a linked file? Looking to copy a sheet with all views from a linked architectural model to quickly make sheets with "blank" views on them in an MEP model that match architectural package.  The main purpose for this task is to get the crop areas and view positions to match throughout the entire drawing package the vast they can.  Thanks!

Set material to a family intance

$
0
0

I´m trying to change the material aplly to a familyinstance using the Revit API C# Language. Below is the code, I can chage other parameters in the family but does not work in the same way for the material. Anyone can give me a Help?

 

Parameter pMatSimbolo = pinElemento.LookupParameter("Cor3DSimbolo");
                var sTyMatSimbolo = pMatSimbolo.StorageType.ToString();
                var IdMatSimbolo = pMatSimbolo.AsElementId();
                                                    
                Element eleMatSimbolo = doc.GetElement(IdMatSimbolo);
                Parameter paramCorSimbolo = eleMatSimbolo.get_Parameter(BuiltInParameter.MATERIAL_NAME);
                var xxxxx = paramCorSimbolo.AsString();
                FilteredElementCollector nomeMaterial = new FilteredElementCollector(doc);
                var material = nomeMaterial.WherePasses(new ElementClassFilter(typeof(Material))).Cast<Material>().First(x => x.Name == ".MVermelho");
          
                ElementId matId = material.Id;
                String matNome = material.Name;
                pinElemento.Set(".MVermelho");
                               
                //------------Retorna de paramentros
                
                TaskDialog.Show("Valor do parametro", vSatus.ToString() + "\n"
                                + vDeslo.ToString() + "\n" 
                                + vSimbolo.ToString());
                
                TaskDialog.Show("Valor do parametro", sTyMatSimbolo.ToString() + "\n"
                                + IdMatSimbolo.ToString() + "\n"
                                + paramCorSimbolo.ToString() + "\n"
                                + xxxxx + "\n"
                                + matId.ToString() + "\n"
                                + matNome.ToString());

 

 

Add select box to taskdialog

$
0
0

Hi ,

 

im trying to add some selection box to task dialog.

at first i tough that the relevant class is ComboBox but then i understated that it related to ribbon item and not to task dialog.

any ideas? any help with some sources about the issue?

Thnaks 

Amir

File Disappeared After Attempt to Cloud Render

$
0
0

I finished my product and attempted to render it to the cloud. However the program experienced an unrecoverable error and stated that there was an autosaved version available after restarting the app. After doing so the file is gone, and I can not find it no matter where I look. I have tried multiple venues such as the recent files tab, the collaboration tab where you can recover an old file, and looked at the journals as well to no avail.

 

I have spent many days on this project, and would hate to lose all of it because of an error in the application. Can anyone help me recover this file?

Re: Filter point based family

$
0
0

Hy Michel,

 

thanks for the Tipps they are helpful :).

 

Regards,

Lehel

Re: ElementTransformUtils.CopyElements (from linked document)

$
0
0

This is something ElementTransformUtils cannot do unfortunately. (As the Revit UI cant)

You can get the crop region from a view in a linked file like this:

 

ViewCropRegionShapeManager managerFromView = viewInLink.GetCropRegionShapeManager(); IList<CurveLoop> cropBoundary = managerFromView .GetCropShape();

 

and then apply that crop boundary in the host project like this:

 

viewInHost.GetCropRegionShapeManager().SetCropShape(cropBoundary.First());

 

But you need some logic or UI to determine which cropBoundary(view) in the link,
should be applied to which view in the host.
Or for each applicable view in the link create a view in the host.
Perhaps copy the linked Levels first using ElementTransformUtils if they dont exist.
And then you can think about placing them on sheets.


access app in a button command - Windows Forms

$
0
0

I'm trying to use the app from the Execute method, into a button that resides in a Windows Forms.

Bellow is the short version of the code with the location of the error:   "The name 'app' does not exist in the current context"

 

#region Namespacesusing System;using System.IO;using System.Collections.Generic;using System.Diagnostics;using Autodesk.Revit.ApplicationServices;using Autodesk.Revit.Attributes;using Autodesk.Revit.DB;using Autodesk.Revit.UI;using Autodesk.Revit.UI.Selection;using System.Text;using System.Drawing;using System.Resources;//using System.Windows.Forms;using System.Collections;using System.Xml;using Autodesk.Revit;using System.ComponentModel;using System.Linq;using System.Windows.Forms;using Form = System.Windows.Forms.Form;using System.Threading.Tasks;#endregionnamespace NameSpace1
{
    [TransactionAttribute(TransactionMode.Manual)]publicclass Class1 : IExternalCommand
    {//public static Autodesk.Revit.ApplicationServices.Application app;
        //public UIApplication uiapp;
        //public UIDocument uidoc;
        //public Document doc;
public Result Execute(ExternalCommandData commandData, refstring message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Autodesk.Revit.ApplicationServices.Application app = uiapp.Application; Document doc = uidoc.Document; MyForm form = new MyForm(); form.Show();return Result.Succeeded; } }publicpartialclass MyForm : System.Windows.Forms.Form {public MyForm() : base() {this.BackColor = System.Drawing.Color.AliceBlue;this.Size = new Size(1200, 900);this.Text = " MyForm Name";this.Dock = System.Windows.Forms.DockStyle.Fill;this.AutoScroll = true;this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;this.TopMost = true;// Add My Button
System.Windows.Forms.Button myButton = new System.Windows.Forms.Button(); myButton.Font = new System.Drawing.Font("Segoe UI", 9.75F); myButton.Location = new System.Drawing.Point(850, 400); myButton.Size = new System.Drawing.Size(290, 50); myButton.BackColor = System.Drawing.Color.Crimson; myButton.ForeColor = System.Drawing.Color.White; myButton.Text = " My Test Button "; myButton.Click += new System.EventHandler(myButton_Click);this.Controls.Add(myButton);void myButton_Click(object sender, EventArgs e) {var myFam = app.OpenDocumentFile(@"C:\myRevitFamily.rfa"); // error "The name 'app' does not exist in the current context" // Process the Opened Revit Family
myFam.Close(); } } } }

Thank you for your help!

CreateRibbonPanel expection.

$
0
0

I need some help trying to make sense of this exception I'm getting with the CreateRibbonPanel.  I'm trying beginner stuff here, just create a ribbon tab, create ribbon panel, put button on ribbon panel. If I comment out the 2 lines relating to the panel it works fine; creates ribbon tab, but obviously no ribbon panel or button on said panel. Using Revit 2020. Builds fine, just get this expection when I try to debug and open Revit.

 

 

 

natuchschererABZV8_0-1588526432311.png

 

Re: CreateRibbonPanel expection.

$
0
0

Better screen shot to show really how basic this class is.

 

natuchschererABZV8_0-1588526826640.png

 

Re: CreateRibbonPanel expection.

$
0
0

Fixed it. The guide I was following wasn't explicit in that the first string needs to be the Tab name of the tab I wanted to add the panel to not just a random string.

Access the UIDocument inside an Iupdater

$
0
0

Hello everyone, i hope you and your families are safe.

 

is it possible to access the UIDocument in a class that implements an IUpdater.

I know we can access the Document using data.GetDocument(), but is there a way to access the UIDocument ? 

 

Thanks in advance.

Viewing all 66651 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>