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

Structural Rebar Standar or Stittup

$
0
0

Good day, I am creating a scrip that executes a code to me if the selected structural bar is a Standar or Stirrup type shape, someone knows how to perform that if if I have the selected structural element rebar.


Re: Revit API with WPF

$
0
0

hi dear

i can't use transaction.start(); when open the wpf window using wpf.show(); instead of wpf.showdialog();

how can we solve that?

Re: viewId is not a view? FilteredElementCollector on Rooms

$
0
0

So, how to get elements from RevitLinkedInstance on specified view of current document? For example - i want to get elements from section view.

In RevitLinkedInstance property ActiveView is always null.

Re: Revit API with WPF

Re: Revit API with WPF

$
0
0

To add my experience to what Jeremy said (you need External Events to make your transactions work modelessly), I have built a dockable dialog with WPF that used a lot of external events. Autodesk recommends that you try to use modal dialogs as much as you can instead of modeless. It will make your project much easier.

 

However, I can tell you that a fully functional suite of tools with external events is possible. But you need to be sure that the added complexity is worth it. 

 

If you are going to have multiple external events, I strongly recommend that you look at the Revit SDK sample for External Events specifically. It shows how to use enums and a handler to swap out external events so that you do not have a sloppy mess of external events in your application.

 

You can also have a modeless dialog that, when you press a button to start a transaction, will open a modal window (progress bar or some other window), and that window will start the transaction instead. Once done, it closes, and the user feels like they are using a modeless context. A system like that would be much easier to maintain.

 

I hope this helps.

ChangeTypeId of AssemblyInstance during the DMU

$
0
0

 

---I am not good at English.---

 

I want to change the assembly type of all other instances to match the changed one, then restore the assembly type name to its original name.

However, the following error appears.

"An elements was modified in a way that yields a new cross reference with another element. Such changes are not allowed in the context the document is currently in."

 

This is part of the code. 

I am a beginner of RevitAPI.

 

What is wrong?

 

    public class AssEdit : IUpdater
    {
        public static bool _updateActive = true;
        static AddInId _appId;
        static UpdaterId _updaterId;

        static string rawAss = null;
        static string createdAss = null;
        static List<Element> toChangeAss = new List<Element>();
        static ElementId sourceAss = null;

        public AssEdit(AddInId id)
        {
            _appId = id;
            _updaterId = new UpdaterId(_appId, new Guid(
              "76DD8055-80CA-4400-847C-E77325936DDD"));
        }

        public void Execute(UpdaterData data)
        {
            if (_updateActive)
            {
                Document doc = data.GetDocument();
                Application app = doc.Application;

                rawAss = "AssemblyName0"; //RAW AssemblyName

                foreach (ElementId id in
                  data.GetAddedElementIds())
                {
                    Element elem = doc.GetElement(id);
                    string cat = elem.Category.Name;
                    if (cat == "Assemblies")
                    {
                        createdAss = elem.Name; //NEW AssemblyName

                        toChangeAss = new FilteredElementCollector(doc)
                            .OfCategory(BuiltInCategory.OST_Assemblies)
                            .WherePasses(new ElementClassFilter(typeof(AssemblyInstance)))
                            .Cast<Element>()
                            .Where(x => x.Name == rawAss)
                            .ToList();

                        createdAssId = new FilteredElementCollector(doc)
                            .OfCategory(BuiltInCategory.OST_Assemblies)
                            .Where(x => x.Name == createdAss)
                            .Select(x => x.GetTypeId())
                            .First();

                        if (toChangeAss.Count() > 0)
                        {

                            foreach (Element ass in toChangeAss)
                            {
                                try
                                {
                                    ass.ChangeTypeId(createdAssId);
                                }
                                catch(Exception e)
                                {
                                    TaskDialog.Show("Why?", e.Message);
                                }
                            }

                            return;

                        }
                    }
                }
            }
            else
            {
                return;
            }
            
        }

 

Re: Revit 2019.1 add-in and CEFsharp library

$
0
0

Thank you  for driving the investigation with the Revit team. Looking forward to hearing results of your investigation.

 

In the meantime, I spent some time looking at the implications of sharing CEF 57 across Revit and addins, here are my findings, hopefully, they will be useful to others.


Short answer: it's possible, but there are several caveats.

 

  • You should still bundle CEF57 with your addin.
    You could potentially do something clever in your installer that detects the version of Revit installed and then decides whether to lay down the CEF binaries, but I would discourage that. Many customers have multiple versions of Revit installed and having different logic for each version is a pain.
  • If you already have a version of your addin with CEF >57 in the wild, you will have to change your installer to force it to overwrite CEF binaries with older versions.
    Windows installer, by default, will not allow you to do this. Your best option is to give all CEF binaries different component/file GUIDs instead of overriding Windows installer default behavior. (Make sure to test upgrade install to verify your changes)
  • CEF 57 doesn't have many of the nice V8 serialization improvements.
    This means that if you rely on C#/JavaScript bindings you are limited to passing primitives, value types, and arrays (which can only contain the same types). Meaning serializing a custom class from C# to JS is not allowed - you will get "Complex types cannot be serialized to Cef lists" exception (see: https://github.com/cefsharp/CefSharp/blob/cefsharp/57/CefSharp.Core/Internals/Serialization/V8Serialization.cpp#L129)
  • If you are registering your own scheme handler, DON'T.
    Instead, use a RequestContext which will allow you to perform all scheme registrations local to your browser instance:

 

 

Browser = new ChromiumWebBrowser();
RequestContext addinRequestContext = new RequestContext();
string addinDomain = "addinlocal";
addinRequestContext.RegisterSchemeHandlerFactory("https", addinDomain, new FolderSchemeHandlerFactory(@"C:\My\Addin\Web\Content"));
Browser.RequestContext = addinRequestContext;

// Then you can navigate like this:
Browser.Load($"https://{addinDomain}/index.html");

 

 

  • Only initialize CEF if it hasn't been initialized yet:

 

var settings = new CefSettings {
    BrowserSubprocessPath = @"c:\path\to\my\installed\cefsharp.browsersubprocess.exe"
};

if (!Cef.IsInitialized) {
    Cef.Initialize(settings);
}
else {
    // CEF already initialized, skipping
}

 

 

  • Have a button/shortcut/whatever in your addin to show debug tools.
    Since your addin may or may not get to initialize CEF in setting debugging port parameters may not be possible. Instead, just use the Browser.ShowDevTools() method.
  • Don't modify CefSharpSettings, it's a singleton, so as long as noone touches it we will be OK.
  • Finally, the timing of initial navigation sequence is quite different in CEF 57 (vs CEF 63) so you might have to tweak your startup code.

I will update this thread if I find any other gotchas.

 

Mark

UpCodes Engineering

 

Re: ChangeTypeId of AssemblyInstance during the DMU

$
0
0

Dear Sugkj,

 

Thank you for your query.

 

Your English is just fine, no worries!

 

In this case, I would first explore exactly how you can achieve the desired operation manually through the user interface.

 

Does that produce the same error?

 

Does that operation require a special situation, some special context?

 

In general, if a feature is not available in the Revit product manually through the user interface, then the Revit API will not provide it either.

 

You should therefore research the optimal workflow and best practices to address your task at hand manually through the user interface first.

 

To do so, please discuss and analyse it with an application engineer, product usage expert, or product support.

 

Once you have got that part sorted out, it is time to step up into the programming environment.

 

I hope this helps.

 

Best regards,

 

Jeremy

 


Re: hide view in project browser not allowed in R2019?

$
0
0

Dear Chris and Nick,

 

Thank you for your update and sorry to hear the problem still persists.

 

As I said above, the development team are still working on the issue REVIT-134368 [hide view in project browser fails in R2019 -- 14238575] that I raised for this issue on your behalf, and they are waiting for input from you.

 

The reproducible case that you provided was not detailed enough.

 

Can you please provide a complete and minimal reproducible case specifying exactly which elements are causing the problem, as explained above?

 

Thank you!

 

Cheers,

 

Jeremy

 

Re: UIApplication.Idling event is not invoked when selecting special elements

$
0
0

Dear ;

 

Thanks for your code.

Please let me know, How should be done selection event in the same category?

 

Regards,

Naing Oo

 

 

 

 

Re: hide view in project browser not allowed in R2019?

$
0
0

As far as I can say, the command 'HideElements' of the 'projectbrowser view' causes a crash at Revit 2019 at any time.

 

The reproducible case is actually the code on page 1 (message 5) of this topic:

 

 

MyTrans.Commit()

MyTrans = New Transaction(MyDoc, "hide view in the browser")
MyTrans.Start()

Try

    Dim MyProjBrowser As Autodesk.Revit.DB.View = GetProjectBrowser(MyDoc)
    Dim MyList As New List(Of ElementId) From {MyNewDraftingView.Id}
    Dim MyCol As ICollection(Of ElementId) = TryCast(MyList, ICollection(Of ElementId))
    MsgBox(MyCol.Count.ToString)         '<- test if the Icollection contains my element -> returns "1"
    MyProjBrowser.HideElements(MyCol)

Catch ex As Exception

    MsgBox(ex.Message)

End Try

 

-> MyDoc = the current Autodesk Revit Document

-> MyNewDraftingView = a view, try it with any view you like, in my code a newly created Drafting View

 

To get the projectbrowser I use this code, this still works fine;

 

Public Function GetProjectBrowser(MyDoc As Autodesk.Revit.DB.Document) As Autodesk.Revit.DB.View

     Dim projectBrowser As Autodesk.Revit.DB.View = New Autodesk.Revit.DB.FilteredElementCollector(MyDoc).OfClass(GetType(Autodesk.Revit.DB.View)).Cast(Of Autodesk.Revit.DB.View).Where(Function(v) v.ViewType = Autodesk.Revit.DB.ViewType.ProjectBrowser).FirstOrDefault

     Return projectBrowser

End Function

 

I hope this is more than enough info for you and your team to get the problem solved.

 

Chris Hanschen

The Netherlands

Re: hide view in project browser not allowed in R2019?

$
0
0

Dear Chris,

 

Thank you for your update and clarification.

 

I passed it on to the development team working on the issue REVIT-134368 [hide view in project browser fails in R2019 -- 14238575].

 

Cheers,

 

Jeremy

 

Re: hide view in project browser not allowed in R2019?

$
0
0

... When you say 'crash', do you really mean CRASH?

Re: Revit Test Framework improvements

$
0
0

Dear Mark,

 

Thank you very much for your appreciation and sharing this.

 

It looks like a great piece of work to me, very useful indeed.

 

I'll repost your contribution on The Building Coder, if I may.

 

Thank you!

 

Cheers,

 

Jeremy

 

Re: Modifying wall compound structure layers via api

$
0
0

hii

IList<Autodesk.Revit.DB.CompoundStructureLayer> csl = new List<Autodesk.Revit.DB.CompoundStructureLayer>();

CompoundStructure cs = CompoundStructure.CreateSimpleCompoundStructure(csl);
                    cs.SetNumberOfShellLayers(ShellLayerType.Exterior, firstCoreLayerIndex);
                    cs.SetNumberOfShellLayers(ShellLayerType.Interior, lastCorelayerIndex);

                    if (cs.IsValid(dbDoc, out IDictionary<int, CompoundStructureError> errMap, out IDictionary<int, int> twoLayerErrorMap))
                    {
                        wallType.SetCompoundStructure(cs);
                    }

capturing dialogboxes

$
0
0

In one of my addins, i am capturing dialog boxes to automatically handle them.

I do this by implementing an new event handler based upon the DialogBoxShowingEventArgs

This seems to capture most of the dialog boxes that block revit in its code excecution, though it doesnt seem to get all of the dialogboxes.

Example Given: When exporting an empty 3D view to navisworks nwc, the Document.Export is called for the navisworks exporter.

So in this case its actually the exporter giving the DialogBox rather then revit itself, so it makes sense in some way that the eventhandler doesnt capture it. Image of the Dialogbox:

diag.png

 

i believe there is a few more of these dialogboxes in other functions that dont like to be captured, but the question would be the same:

I was wondering if it is somehow still possible to capture these dialogboxes or auto dispatch them either trough the eventhandler or otherwise?

Re: How to set the wall height?

$
0
0

Hi,

Thank you for your reply.

I can set the height of the wall now, but the result puzzle me a little. That is, I set the height to 100 in VS, but the result is 30480 in revit. screenshot attached as below. 11.png22.png

Re: How to set the wall height?

$
0
0

Hi ,

In code what you are giving is in feet (i.e)100 feet

but in Revit it is showing the units in millimeter(mm).

If you want everything in feet you can change the unit settings in Revit

Re: PSA: do NOT use CEF in your addin (and how Revit 2019.1 broke it)

$
0
0

Hi All!

 

Since our company/product ProdLib was mentioned in this post, I just wanted everyone to know that we rolled back to version 57 and made things work again, at least for a while. Luckily we were using the legacy javascript binding. I can see this issue discussed in some other forums at the moment and will continue to follow there...

 

Kim Sivonen

ProdLib Oy

Re: How to set the wall height?

Viewing all 66788 articles
Browse latest View live


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