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

Re: get category visibility

$
0
0

Hi,

 

no need for Elements at all, the Category visibility is always attached to a given view, not to the model itself.

 

Revit 2018:

View.GetCategoryHidden(catId)

View.SetCategoryHidden(catId, bool hide)

 

Previous:

View.GetVisibility(catId)

View.SetVisibility(catId, bool show)

 

Note the unnecessary negation in 2018 :-(

 

You can create the needed ElementId just by using the BuiltInCategory in the constructor, "new ElementId(BuiltInCategory.OST_DetailComponents)".

 

 

Revitalizer


FileExportingEvent not consistently triggering

$
0
0

I am looking to monitor file exports.  In my addin application I am subscribing to both FileExporting and FileExported events. When running the addin, I am experiencing what looks to be an issue with the API.

 

In testing, file formats that trigger FileExportingEvent are: DWG, DXF, DGN, SAT, DWF, ADSK Building Site, gbXML,  and IFC.

Those that don't trigger are: FBX and NWC.

I didn't test Family types, ODBC, Images and Animations, and Reports.

 

Looking at the documentation, ImportExportFileFormat enumeration list contains both FBX and NWC.  This makes me believe that exporting to those formats should trigger the FileExport events. I also checked and they are not triggered with a SaveAs event.

How to obtain the Id of the Fill Solid Pattern

Re: How to obtain the Id of the Fill Solid Pattern

$
0
0

The following code allows to solve this problem for the french Revit version 2016.

 

FillPatternElement fillPatternElement;
fillPatternElement = FillPatternElement.GetFillPatternElementByName(doc, FillPatternTarget.Drafting, "Uni");

filterSettings.SetProjectionFillPatternId(fillPatternElement.Id);

 

For another version of Revit use the translation of "Uni" in this version.

Re: get category visibility

$
0
0

Revitalizer,

 

1. thank you for your help

 

2. the method format is:

 

bool View.GetVisibility(Category cat);     // Revit 2015

 

so what i did is this:

 

 bool isCategoryVisibile(Autodesk.Revit.DB.ViewPlan view)

{

  ElementId eid = newElementId(BuiltInCategory.OST_DetailComponents);

  Element element = m_doc.GetElement(eid);

 

  return view.GetVisibility(element.Category);

}

 

but i get exception saids "Object reference not set to an instance of an object."

 

 

 

and if i may ask (with your permission?) i would like you also to know how to check if an Element is inVisibile by VG Filter and WorkSet

 

thanks again

Moshe

 

 

 

 

 

 

Dissable space button

$
0
0

How can I dissable space button for rotate example generic model.

 

I want for specified generic model wall hosted disable space button for rotate....can use arrow for dissable rotation but not don't dissable space button if you are in create mode for place generic model in project.

 

thx.

Re: get category visibility

$
0
0

found this solution

 

privatebool isCategoryVisibile(Autodesk.Revit.DB.ViewPlan view)

{

  Category category = doc.Settings.Categories.get_Item(BuiltInCategory.OST_DetailComponents);

 

  return view.GetVisibility(category);

}

 

would be grateful if you reply my other questions.

 

 

Best way to get material information


Displaying static results from an external appliction

$
0
0

The API about the topic is very brief.

What are the preconditions for displaying of "deformation" state of an analytical model (surface) in Revit?

Does anyone have experience with the topic in general?

Re: How to obtain the Id of the Fill Solid Pattern

$
0
0

Hi,

 

the API gives you a language-independent approach, no need for string comparison at all.

 

For each FillPatternElement (can be got via FilteredElementCollector), you can get its FillPattern (GetFillPattern()).

FillPattern.IsSolidFill is the property you need to check.

 

 

Revitalizer

Re: get category visibility

Re: How to obtain the Id of the Fill Solid Pattern

How to Use NewFamilyInstance on Opposite Side of Wall for Wall-Mounted Families

$
0
0

I made a simple wall-mounted family using the "Generic Model wall based.rft" template. The family is just an extrusion attached to the top side of the wall as viewed in the Ref. Level

 

wall-mounted-box.rfa:

wall-mounted-box.PNG

I want to import this wall-mounted-box.rfa into another Family (I will call this import.rfa) that also uses the "Generic Model wall based.rft" template. I want to place the box on the opposite side of the wall though, like the picture below. I can do this easily within the Revit UI. But I can't figure it out with the Revit API.

 

import.rfa:

Capture.PNG

 

Here is code showing the methods I've tested

 

string templateFileName =
    @"C:\ProgramData\Autodesk\RAC 2016\Family Templates\English_I\Generic Model wall based.rft";
Document document = uiApplication.Application.NewFamilyDocument(templateFileName);
Family family;
using (Transaction transaction = new Transaction(document))
{
    transaction.Start("Load Family");
    document.LoadFamily(@"...\wall-mounted-box.rft", out family);
    transaction.Commit();
}
FamilySymbol symbol = document.GetElement(family.GetFamilySymbolIds().First()) as FamilySymbol;

FilteredElementCollector wallCollector = new FilteredElementCollector(document);
Wall wall = wallCollector.OfClass(typeof(Wall)).FirstElement() as Wall;

using (Transaction transaction = new Transaction(document))
{
    tx.Start("Instantiate Family");
    symbol.Activate();
    // METHOD 1: Default wall host
    FamilyInstance familyInstance = document.FamilyCreate.NewFamilyInstance(new XYZ(0,0,0), symbol, wall, StructuralType.NonStructural);

    // METHOD 2: try setting referenceDirection
    document.FamilyCreate.NewFamilyInstance(new XYZ(0,0,0), symbol, new XYZ(0,-1,0), wall, StructuralType.NonStructural);

// METHOD 3: Try flipping the FamilyInstance
familyInstance.flipFacing();

// setup for METHOD 4/5 Reference reference = HostObjectUtils.GetSideFaces(wall, ShellLayerType.Interior).First(); // METHOD 4: use reference to face with method from this site // http://adndevblog.typepad.com/aec/2015/06/revitapi-create-familyinstance-on-a-wall-face.html document.FamilyCreate.NewFamilyInstance(reference, new XYZ(0, 0, 0), new XYZ(0, -1, 0), symbol); // METHOD 5: Get the face to place on // I just grabbed the index-2 face arbitrarily since this method doesn't work anyways Options opt = new Options(); opt.ComputeReferences = true; Face face = (wall.get_Geometry(opt).First() as Solid).Faces.get_Item(2); document.FamilyCreate.NewFamilyInstance(face, new XYZ(0, 0, 0), new XYZ(0, -1, 0), symbol); tx.Commit(); } SaveAsOptions saveAsOptions = new SaveAsOptions(); saveAsOptions.OverwriteExistingFile = true; document.SaveAs(@"...\import.rft", saveAsOptions);

 

METHOD 1 and METHOD 2 just places the box on the default side of the wall which is the top. Looks exactly like the wall-mounted-box.rfa picture.

 

METHOD 3 doesn't work because familyInstance.CanFlipFacing is false.

Here are the properties I grabbed from FamilyInstances I creating using the Revit UI.

 

default orientation on top of wall:

2017-07-18

 

opposite orientation on bottom of wall:

2017-07-18

 

METHOD 5 says "Family cannot be placed as hosted on an input face reference, because its FamilyPlacementType is not WorkPlaneBased"

METHOD 4 also says that FamilyPlacementType is not WorkPlaneBase.

 

How do I do this?

Can Revit add-in update itself?

$
0
0

Hi everyone,

 

I wonder, is it possible to implement an auto-update functionality into the Revit add-in? I understand that the external application can run the code only when called from Revit, but if I place a button "Update add-in" on a ribbon, is there a way to implement it (download and rewrite itself)? If so, has anyone tried this successfully? Is there any code sample?

 

Thank you in advance,

 

Martin

DUM - for generic model

$
0
0

I need use DUM for specified generic models that have special parameter.

 

But work only if I have only one typ of generic model ...other don't work..why?

 

 var otCategoryFilter = new ElementCategoryFilter(BuiltInCategory.OST_GenericModel);

            var familyInstanceFilter = new ElementClassFilter(typeof(FamilyInstance));
            FilteredElementCollector eCollector = new FilteredElementCollector(doc);
            eCollector.OfCategory(BuiltInCategory.OST_GenericModel);


            String parameterName = "Type E";
            ParameterValueProvider pvp;
            FilterStringRuleEvaluator ele = new FilterStringEquals();
            FilterStringRule frule;

            UpdaterRegistry.RegisterUpdater(this, doc);

            foreach (Element e in eCollector)
            {
                foreach (Parameter p in e.Parameters)
                {
                    if (p.Definition.Name == parameterName)
                    {
                        ElementId idparametru = p.Id as ElementId;
                        pvp = new ParameterValueProvider(idparametru);


                        frule = new FilterStringRule(pvp, ele, "TEST", true);
                        epf = new ElementParameterFilter(frule);

                    }
                    else
                    { }
                }
            }



            LogicalAndFilter otInstanceFilter = new LogicalAndFilter(new List<ElementFilter> { otCategoryFilter, familyInstanceFilter, epf });

            UpdaterRegistry.AddTrigger(m_updaterId, doc, otInstanceFilter, Element.GetChangeTypeElementAddition());
            UpdaterRegistry.AddTrigger(m_updaterId, doc, otInstanceFilter, Element.GetChangeTypeGeometry());

Re: Revit 2018 API - Undocumented Changes - Have you found any?

$
0
0

Hi Jeremy,

 

I still have not received any advice as to how to get around not being able to duplicate dimension styles in 2018. I had hoped it would be fixed or workaround suggested before we released our product.

 

Best regards

Paul

Re: Known Bug List

Re: Can Revit add-in update itself?

$
0
0

 

Hi 

 

I think that your code needs to copy/paste the new .dll file to the correct location (something like Appdata\Roaming\Autodesk\Revit\Addin\XXXX) to do it. It should work with that.

 

Regards,

 

GM

Re: Revit 2018 API - Undocumented Changes - Have you found any?

$
0
0

Hi Paul,

2018.1 is out. Have you tested using that version?

 

If you're desperate for an API workaround, here's one way to do it:

  1. Open a second model. (I think you can do this without a template now?)
  2. Use the copy-paste utils to copy your main model dimension style to the second model.
  3. Rename the style in the second model.
  4. Copy-paste the renamed style back to your main model and modify as necessary.
  5. Close the second model.

It'll be slow, but it should work.

 

[Edit]

p.s. If you've not signed up to Revit Beta testing, then it would be worthwhile doing (to see if the issue persists there).

[/Edit]

Re: WPF window loses control when Revit API displays an error message

$
0
0

I tried with an ElementHost in a wpf window but I still have the problem of loss of focus

 

FormElementHost : (lose focus)

 

 - Command :

 

 [Transaction(TransactionMode.Manual)]
    public class FormElementHostCommand : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            FormElementHost form = new FormElementHost(commandData);

            form.ShowDialog();

            return Result.Succeeded;
        }
    }

 - Form (System.Windows.Forms.Form) :

 

  public partial class FormElementHost : Forms.Form
    {
        ExternalCommandData _commandData;

        public FormElementHost(ExternalCommandData commandData)
            : this()
        {
            _commandData = commandData;
        }

        public FormElementHost()
        {
            InitializeComponent();
            this.userControl11.ClickEvent += UserControl11_ClickEvent;
        }

        private void UserControl11_ClickEvent(object sender, EventArgs e)
        {
            Family family;
            string message;
            UtilsFamily.LoadFamily(_commandData.Application.ActiveUIDocument.Document, out family, out message);
        }
    }

 

- UserControl WPF (System.Windows.Controls.UserControl) :

 

public partial class UserControl1 : UserControl
    {
        public event EventHandler ClickEvent;

        private void RaisesEventClick()
        {
            if (this.ClickEvent != null)
                this.ClickEvent(this, new EventArgs());
        }

        public UserControl1()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            RaisesEventClick();
        }
    }

 

 

 

 

FormNoElementHost : (not lose focus)

 - Command :

 

 [Transaction(TransactionMode.Manual)]
    public class FormNoElementHostCommand : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            FormNoElementHost form = new FormNoElementHost(commandData);

            form.ShowDialog();

            return Result.Succeeded;
        }
    }

 - Form (System.Windows.Forms.Form) :

 

public partial class FormNoElementHost : Forms.Form
    {
        ExternalCommandData _commandData;

        public FormNoElementHost(ExternalCommandData commandData)
            : this()
        {
            _commandData = commandData;
        }

        public FormNoElementHost()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Family family;
            string message;
            UtilsFamily.LoadFamily(_commandData.Application.ActiveUIDocument.Document, out family, out message);
        }
    }

 

WindowWPF: (lose focus)

 - Command :

    [Transaction(TransactionMode.Manual)]
    public class WindowWPFCommand : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            WindowWPF  window = new WindowWPF(commandData);

            window.ShowDialog();

            return Result.Succeeded;
        }
    }

 - Window (System.Windows.Window) :

 

 

    public partial class WindowWPF : Window
    {
        ExternalCommandData _commandData;

        public WindowWPF(ExternalCommandData commandData)
            : this()
        {
            _commandData = commandData;
        }

        public WindowWPF()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Family family;
            string message;
            UtilsFamily.LoadFamily(_commandData.Application.ActiveUIDocument.Document, out family, out message);
        }
    }

 

 

 

 

 

UtilsFamily :

 

 

    public class UtilsFamily
    {
        public static bool LoadFamily(Document doc, out Family family, out string message)
        {
            family = null;
            message = null;

            // ask user to select a family file
            System.Windows.Forms.OpenFileDialog fileDlg = new System.Windows.Forms.OpenFileDialog();
            fileDlg.Filter = "Revit family (*.rfa)|*.rfa";
            fileDlg.Multiselect = false;
            if (fileDlg.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
                return false;

            using (Transaction tr = new Transaction(doc))
            {
                tr.Start("Load family");

                if (!doc.LoadFamily(fileDlg.FileName, new FamilyOption(), out family))
                {
                    message = "Could not load family !";
                    tr.RollBack();
                    return false;
                }

                tr.Commit();
            }
            return true;
        }
    }

 

 

 

 

 

Viewing all 67020 articles
Browse latest View live


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