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

Re: Retrieving certain family type parameters out of a bunch of *.rfa files


Re: SpectrumBIM Gamut crashes Revit

$
0
0

Here is a full recap of what is going on:

 

  1. Revit starts and loads all third-party addons
  2. SpectrumBIM Gamut App starts and attaches an event listener for the AppDomain.ResolveAssembly event in which they try to load one of their assemblies in case it was not successfully loaded. What they do not suspect is that this event handler will be called for ALL assemblies that failed to load in this AppDomain -- not just theirs.
  3. V-Ray for Revit starts and load the Grpc.Core.dll assembly. This assembly tries to load some "UnityEngine" assembly and fails but this is fine for V-Ray for Revit because we do not need it and everything is working properly.
  4. The event that this UnityEngine assembly has failed to load reaches the SPTR.Gamut.Revit.App.GamutApp.CurrentDomain_AssemblyResolve event handler where they expect some comma in the name and of course there is no comma because this is about the UnityEngine assembly and of course the call to String.Substring throws bringing the entire Revit app down.

The only resolution is for SpectrumBIM Gamut to fix their event handler to expect all kinds of different assembly load failures or to uninstall their add from Revit

 

---OR---

 

Revit to provide a separate AppDomain for each addon, instead of throwing all of them to fight in the same AppDomain.

Load a shared parameter through the API

$
0
0

Hello, All. I am wondering on what is the best way to load a shared parameter in a file, using the API? I have been studying Python and experimenting with the API for not more than a few months now. I have been working on several scripts. One of them reads the Family and Type names for certain categories and then copies the values as strings to newly created parameters, that can be used in schedules for filtering. It is doing something similar for Links - by reading their names, name of the file and name of the site. I am generally really happy with the way it works, I simply want to check whether those parameters are loaded and in case they are not, to load them 🙂 Thanks in advace! Here is the script:


# Import from Autodesk API
from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory, ElementMulticategoryFilter, Transaction
from System.Collections.Generic import List

# Define short variable for current document
doc = __revit__.ActiveUIDocument.Document

# Filter multiple categories, reffering to non system families
category_list = [BuiltInCategory.OST_PlumbingFixtures, BuiltInCategory.OST_Furniture, BuiltInCategory.OST_Windows, BuiltInCategory.OST_Doors]
filter_list = List[BuiltInCategory](category_list)
filter = ElementMulticategoryFilter(filter_list)
category_collector = FilteredElementCollector(doc).WherePasses(filter).WhereElementIsNotElementType().ToElements()

# Filter Multiple categories, reffering to system families
system_list = [BuiltInCategory.OST_Walls, BuiltInCategory.OST_Ceilings, BuiltInCategory.OST_Floors, BuiltInCategory.OST_Roofs, BuiltInCategory.OST_Walls, BuiltInCategory.OST_RvtLinks]
system_filter_list = List[BuiltInCategory](system_list)
system_filter = ElementMulticategoryFilter(system_filter_list)
system_collector = FilteredElementCollector(doc).WherePasses(system_filter).WhereElementIsNotElementType().ToElements()

# Filter Revit Links
links_collector = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_RvtLinks).WhereElementIsNotElementType().ToElements()

# Define and open transaction
t = Transaction(doc, "Update Family/Type Name")

t.Start()

# Starting with non system families
for i in category_collector:

# Set duplicate for the TypeName
TypeName = i.Name
TypeNameDuplicate = i.LookupParameter('TypeNameDuplicate')
if TypeNameDuplicate:
TypeNameDuplicate.Set(TypeName)

# Set duplicate for the FamilyName
type_id = i.GetTypeId()
element_type = doc.GetElement(type_id)
family = element_type.Family
name = family.Name
FamilyNameDuplicate = i.LookupParameter('FamilyNameDuplicate')
if FamilyNameDuplicate:
FamilyNameDuplicate.Set(name)

# Duplicates for the system families
for s in system_collector:
SystemTypeName = s.Name
TypeNameDuplicate = s.LookupParameter('TypeNameDuplicate')
if TypeNameDuplicate:
TypeNameDuplicate.Set(SystemTypeName)

# Duplicates for linked files
for link in links_collector:
link_filename = link.Name.split(' : ')[0]
LinkFileName = link.LookupParameter('LinkFileName')
if LinkFileName:
LinkFileName.Set(link_filename)

link_name = link.Name.split(' : ')[1]
LinkName = link.LookupParameter('LinkName')
if LinkName:
LinkName.Set(link_name)

link_site = link.Name.split(' : ')[2]
LinkSite = link.LookupParameter('LinkSite')
if LinkSite:
LinkSite.Set(link_site)

# Close transaction
t.Commit()

Re: What Programming Language ?

$
0
0

I'd suggest C#.  Its what all the cool kids are using😊

 

If you look at the Revit API documentation, they include examples in both C# and Visual Basic.  Sorry, no examples for Python users.

 

If you look at the questions on this site, I think most people use C#, and some type of Python would be second most popular.  So in terms of getting examples and questions answered (very important for a Revit API programmer) C# seems to be the clear winner.

 

The Visual Studio IDE or Sharp Develop( the Macro IDE) will do any of the above in addition to something called F which I've never heard of anyone using.   Either IDE will even convert your code or any examples from one language to another, although I'm not sure if that will work 100% of the time.

 

And some people use either the Revit Python Shell, or PyRevit addins to write python addins.   I'm not sure why these are necessary since more recent versions of Visual Studio and Sharp Develop both include python.   Maybe it has something to do with the different flavors of python (Iron Python for example)?

 

I started with Python but I always had trouble with the line returns not compiling correctly.  Maybe its the way I would copy and past examples from the internet, but I always wound up deleting and retyping the same code just to get it to compile.

 

Some say C# is more difficult to understand, but to me, the main difference is that you just have to declare the variable types.  

 

Re: What Programming Language ?

$
0
0

thank you Very Much for the Answer !

Re: What Programming Language ?

$
0
0

Hahahha the Cool Kids sounds Cool. Thank You for the Answer ! I guess you guys won a new C# student 👨🏽‍🎓😊

Re: See Grouptype member elements without an instance present

$
0
0

Thank you for the roll back idea, it is very helpful!

 

Unfortunately I think I'm doing something wrong....

 

The output includes elements from a placed group (the one with missing elements I'm using as a comparison) they are easy to remove.

 

I also get double the quantity of elements actually in the group...

 

Of course it is easy to half my output, but I'd like to understand what's going on 🙂  Any comments gratefully received!

e80bc09006cff3b735562ebd97f208950fd56469.png

 

 

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

from System import Enum

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

#The inputs to this node will be stored as a list in the IN variable.
groupsList, categoryNames = UnwrapElement(IN)

#what we want to get is a new instance of the group
groupTypesAll = []
groupTypesAllNames = []
groupTypesAllMembers = []
for groups in groupsList:
	groupTypes = []
	groupTypesNames = []
	groupTypesMembers = []		
	for group in groups:			
		id = group.GetTypeId()
		gTypeElement = doc.GetElement(id)
		gTypeName = Element.Name.GetValue(gTypeElement)		
		gType = group.GetType()
		groupTypes.append(gType)
		groupTypesNames.append(gTypeName)
		
		#this creates a temporary transaction
		#the temporary transaction needs to be a sub-transaction
		#feeding the type element's id gives you all the ids it deletes... 
		#ie. all the members
		#we then undo the delete
		idList = []
		TransactionManager.Instance.EnsureInTransaction(doc)
		#temporary sub-transaction
		trans = Autodesk.Revit.DB.SubTransaction(doc)
		trans.Start()
		idList = doc.Delete(gTypeElement.Id)
		#finish temporary sub-transaction
		trans.RollBack()
		#finish transaction
		TransactionManager.Instance.TransactionTaskDone()
		#get elements from ids
		elements = []			
		for id in idList:
			#there are all sorts of things included in the delete
			#we only want specific categories
			element = doc.GetElement(id)
			try:
				elementCategoryName = element.Category.Name
				for category in categoryNames:			
					if elementCategoryName == category:
						elements.append(element)
			except:
				pass
					
		groupTypesMembers.append(elements)
	groupTypesAllMembers.append(groupTypesMembers)

OUT = groupTypesAllMembers

Full post with attachments here... https://forum.dynamobim.com/t/model-group-excluded-members/45251

 

Re: Element Selection Changed Event - Implementation Struggles

$
0
0

Wow! I wish I could allot more than one like for this. It deserves dozens, at least.

 


Access to Site Settings

$
0
0

is there an API access to Topography Intervals, or generally to Site Settings?

image.png

Re: How to get default button name

$
0
0

Thanks for your suggestion   I'll try and have a look at it

Re: How to get default button name

Re: FBX_LIGHT_PHOTOMETRIC_FILE, absolute IES path issue

$
0
0

Hi Jeremy,

 

I see that trying to explain the complexity of my plugin as a whole is too difficult and time wasting both for me and for you…

So, I’ve simplified it the most I can. I’ve written a simple code in which there are no lists and variables but all the values to be set are explicit.

 

Here it is:

 

private void Create_rfa_files()
    {
        this.doc = application.OpenDocumentFile(@"C:\Users\bianc\Desktop\Template1.rfa");

        Transaction transaction = new Transaction(doc);
        transaction.Start("Set IES file");

        LightFamily lightFamily = LightFamily.GetLightFamily(doc);
        lightFamily.SetLightDistributionStyle(LightDistributionStyle.PhotometricWeb);

        for (int index = 0; index < lightFamily.GetNumberOfLightTypes(); index++)
        {
            LightType lightData = lightFamily.GetLightType(index);

            PhotometricWebLightDistribution lightDistribution = lightData.GetLightDistribution() as PhotometricWebLightDistribution;
            lightDistribution.PhotometricWebFile = @"C:\Users\bianc\Desktop\PIL_071451.IES";
            lightDistribution.TiltAngle = Math.PI / 2;    // use radian value to set
            lightData.SetLightDistribution(lightDistribution);  // set back

            InitialColor initColor = lightData.GetInitialColor();
            CustomInitialColor customInitialColor = initColor as CustomInitialColor;
            double colorTemperature = customInitialColor.Temperature;
            customInitialColor.Temperature = 2577;
            lightData.SetInitialColor(customInitialColor);

            double efficacy = 9387.55 / 123.33;
            lightData.SetInitialIntensity(new InitialWattageIntensity(efficacy, 123.33));
            lightData.SetInitialIntensity(new InitialFluxIntensity(9387.55));
        }

        transaction.Commit();

        string destinationFile = @"C:\Users\bianc\Desktop\familyTest.rfa";
        doc.SaveAs(destinationFile);
    }

 

As you can see, the code takes one .rfa file as a starting point (Template1.rfa).

The .rfa has already two types in it (see Template1.jpg as a reference)

For every type, the “for” cycle writes the same values for Initial Intensity, Initial Color,Tilt Angle and Photometric Web File parameters.

 

As you can see in the two attached files named Type1.jpg and Type2.jpg, the issue I mentioned in my first message is still the same:

  • For Type1, the values of the parameters Initial Intensity and Initial Color are set to their correct values, but the Photometric Web File parameter presents the full path;
  • For Type2, instead, the values of Initial Intensity and Initial Color are left to their default values, but the .IES file is loaded correctly.

Tilt Angle seems to be set correctly for both types.

 

As already said, if the file contains more than two types, only the last processed will behave like “Type2” in the example, while all the others will behave like “Type1” in the example.

 

Am I doing something wrong? Or this issue cannot be fixed (for the moment at least)?

 

PLEASE NOTE: I have tried it with Revit versions 2017, 2018, 2019 and 2020, and the behaviour is always the same.

 

 

Any help will be greatly appreciated.

Thanks in advance.

 

Re: How to get DuctSystemType color

Re: See Grouptype member elements without an instance present

$
0
0

Apologies, it was a different issue.

WPF with datagrid

$
0
0

Hello,

I am starting change Winform to WPF.

I have datagrid with abou 50 fields from Revit.


But I can't read some field currently invisible in datagrid. (visible when I scroll down)

 

TextBlock item= datagrid1.Columns[2].GetCellContent(datagrid1.Items[15]) as TextBlock;
            MessageBox.Show(item.Text);

this make error in revit...

but if I scroll to item 15 and click - it work correctly.

 

thanks..


Re: WPF with datagrid

$
0
0

Hi:

Here is my simple conclusion:

Your code is not MVVM.

 

Let's suppose that you have the cell that you are visiting has not yet been displayed on the screen (not yet rendered).

In WPF DataGrid control ( as well as most other controls), data won't be prepared before rendering.

Think abt it in another way. Bind DataGrid.ItemsSource property to a IEnumerable<T> collection property in your view model, then each single item has already been prepared whether the DataGrid control having been rendered or not.

The spirit of MVVM is that both the view and the view model can run without knowing each other.

Which means that you should *NEVER* visit DataGridCell.Content to get a TextBox.Text data. You should directly visit the collection property in you view model.

It's a gap for developers from WinForm 🙂

Re: REST requests through pyRevit

$
0
0

Hi,
Thanks for the reply.

No, I haven't built it myself.
BUT in the meanwhile I managed to figure out how to use WebRequest to get the info from the API, now I'm struggling to understand how to post info back to the api 🙂

There isn't enough solid info about using WebRequest with IronPython out there, at least not enough for a newbie...

 

Best,

Ifat.

 

Re: Rotating a group

$
0
0

Thank you so very much. I really appreciate your help. I was stuck with this problem for 2 days. Thank god that I came across to your comment. 🙂

Questions/Bugs regarding CustomExporter & selection

$
0
0

Hello,

 

right now I'm looking at a problem again, which we work-arounded a few years ago. It seems like the workaround has unwanted side effects. Any input is welcome.

 

Our plugin (Enscape) extracts all the geometry by using the CustomExporter.Export method. However, sometimes when calling that method while some special elements are selected, some other elements which have geometry just don't receive geometry in the OnPolymesh (et al.) method.

Example:

  1. Start Revit 2020 (same behavior since at least 5 years)
  2. Open RAC_basic_sample_project.rvt
  3. Select #812954 (lighting fixture above kitchen table)
  4. CustomExporter.Export does not report any geometry for elements #176804, #198694, #198749, #211850, #213811, #234869, #243274

The workaround we used: call ActiveUIDocument.Selection.{Get/Set}ElementIds to deselect all elements before calling CustomExporter and restore afterwards. This seemed to work fine.

 

Unfortunately we want to export the geometry as a reaction to a UIControlledApplication.DocumentChanged event, and when doing so, the mentioned workaround breaks the Properties Panel in Revit.

 

Normally, when performing changes in the Properties Panel, every single change leads to a single DocumentChanged event. As soon as the mouse cursor leaves the Properties Panel, the changes get assimilated into a single undo step and are finally commited to the document.

 

With the active workaround, when the mouse cursor leaves the Properties Panel, the changes are reverted, they are no longer visible in the project file and we receive an empty DocumentChanged event with Operation == UndoOperation.TransactionGroupRolledBack. This is bad for the user.

 

In my opinion something goes wrong when deselecting the element that is currently modified via the Properties Panel.

 

Ideally the missing geometry will be fixed by Autodesk. But until that happens, we need another solution. How can we detect that the selected element will lead to missing geometry? How can we detect that there are pending changes in the Properties Panel?

 

Regards,

Simon Weinberger

How to get geometrical parameters of a generic model element

$
0
0

Hi everyone,

 

I’m trying to make an API able to get different instance parameters of an element in a family. In my case, I want to catch the value of  « hauteur » , « Epaisseur » and « longueur » parameters of the element « mur de front » wich is a genreic model. After that i would like to store thoses parameters into variables to make a calcul.

 

Capture.PNGI highlighted in yellow values i want to get

 

 

I succeeded to make a code to store the parameters value for a classic wall with thoses commands


Parameter l = e.get_Parameter(BuiltInParameter.FAMILY_HEIGHT_PARAM);
Parameter h = e.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM);

 

but i can’t find the solution for a generic model element … I found some codes on differents forums but i’m not able to compil them correctly in my program. Obvoiusly i’m a beginner...


If anyone can give me suggestions or a sample code to catch thoses parameters it would be nice and helpfull for me to understand😊.

Viewing all 67020 articles
Browse latest View live


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