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

Re: Importing IFC files to Revit

$
0
0

You say that the Link IFC interface button works more or less properly. Maybe the best way to start would be to research how to make that work properly. Once that is clear, we should be able to reproduce the same behaviour programmatically as well. In general, it helps a lot to develop an optimal workflow and follow best BIM practices manually in the user interface before trying to address an issue programmatically through the API. What are the problems you see there?

  


Generative Design doesn't respond. ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

$
0
0

Hi All,

When I try to use Generative Design, it stucks and I can see a error as "ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it"
in refinery server log.

Could anybody help me?

Re: Importing IFC files to Revit

$
0
0

I try to link an ifc because the create button isnt effective according to the Revit itself. I used a lot of examples of code but it doesnt work at Revit 2025. I guess the sdk is constantly updating. So I take a new view about how to achieve my goal. I think I am going to create a family with the model geometry from ifc and I will add the properties I need. Thank you for your time.

Re: Set the value of a shared parameter in a linked file.

Re: Walkthrough: Add Hello World Ribbon Panel

$
0
0

What Revit version are you testing?

What error show in the 'Show details'?

 

There is a inconsistent version configuration in your file, you are using Revit 2024 API reference and that implies you are using Revit 2024. If that the case your code is build in the TargetFramework net8.0 and is not supported in Revit 2024 only net4.8.

 

If you change to '<TargetFramework>net48</TargetFramework>' if you are running in Revit 2024.

 

Or follow Walkthrough for Revit 2024.

https://help.autodesk.com/view/RVT/2024/ENU/?guid=Revit_API_Revit_API_Developers_Guide_Introduction_Getting_Started_Walkthrough_Hello_World_html

 

 

Re: Walkthrough: Add Hello World Ribbon Panel

$
0
0

Hey Rica, I'm sorry I didn't send all the information.

What Revit version are you testing? 2024

What error show in the 'Show details'?

 

id8656_0-1737574474802.png

 

I´m gonna try your solution and I will return asap

 

Thanks for your help.

 

Marcio Mortoni

 

 

Re: PostCommand of external command (coming from ribbon) not working

$
0
0

Your command have some IExternalCommandAvailability?

 

Looks like the CanPostCommand does not check if the command is available to execute.

 

If your have a command with IExternalCommandAvailability return always false, the CanPostCommand return true.

 

Knowing that I can assume that CanPostCommand only checks if you can post the command, it doesn't mean the command is available to execute.

Re: GetChangeTypeParameter not triggered for INSTANCE_LENGTH_PARAM

$
0
0

Same issue with:

LEVEL_PARAM that is used for Floors & Ceiling, 

ROOF_BASE_LEVEL_PARAM used for FoorPrintRoof,

TRUSS_ELEMENT_REFERENCE_LEVEL_PARAM used for Truss

 

while all of the above are IsReadOnly: False, UserModifiable: False... the same applies for the parameters below that do trigger as expected:

FAMILY_BASE_LEVEL_PARAM,

FAMILY_LEVEL_PARAM,

WALL_BASE_CONSTRAINT,

STAIRS_RAILING_BASE_LEVEL_PARAM

 

What gives? We need to have ability to track changes across different types and at least be consistent about it!


Re: How to open/close workset in a linked revit programmatically

$
0
0

Still no solution for this? I am trying to open worksets from model in ACC?

Re: Open closed worksets in open document?

$
0
0

Hi, all.

Still not possible to open worksets (without workaround) using Revit API?

I have tried open the model with the worksetconfiguration but because of my models are in ACC, I cannot access the WorksetsPreview. It throws and error.

 

Run ExternalCommand from Dockable Pane Button without Registering in External Tools

$
0
0

Hello All,

I have a dockable pane in my Revit add-in that contains a button. When this button is clicked, I want to execute a specific ExternalCommand. Currently, for the ExternalCommand to run, I have to register it in the AddInManifest. However, this also makes the command visible in the "External Tools" menu in Revit, which I do not want.

My requirements are:

  1. I want the ExternalCommand to run directly when clicking the button in the dockable pane.
  2. I do not want the ExternalCommand to be listed in the "External Tools" menu.
  3. If possible, I would prefer to avoid registering the command in the AddInManifest.

Is there a way to achieve this behavior in Revit API? Any guidance or best practices would be appreciated.

Thanks in advance!

Re: PostCommand of external command (coming from ribbon) not working

$
0
0

Thank you for your reply.

This could have been a good idea, but I already tried with or without CommandAvailability but nothing changed.

According to the Revit journal, it seems that CanPostCommand does not have the correct Assembly (dll path). Please, note the following line :

in%Commands%testdoes not ex

There is no space between "test" and "does". Maybe it's just a logger issue... Whatever I didn't find a way to specify/check the CommandId Assembly.

Re: Run ExternalCommand from Dockable Pane Button without Registering in External Tools

$
0
0

Yes. This can ba achieved using an external event. Please refer to the official ModelessDialog/ModelessForm_ExternalEvent Revit SDK sample. 

      

The dockable panel is modeless. Therefore, it lives outside the valid Revit API context. The external event enables you to switch from the modeless external context to a valid Revit API context in which external commands and other Revit API interaction can take place. 

   

Read all about it in The Building Coder topic group 5.28 on Idling and External Events for Modeless Access and Driving Revit from Outside:

  

  

Re: Generative Design doesn't respond. ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

$
0
0

Is this a programming issue, or are you just using the GUI as an end user to drive this?

   

Afaict from your query and screen snapshot, you are not doing anything programmatically yourself using the Revit API, just using the standard Revit or some other user interface. In that case, unfortunately, this is not the best place to ask such a question. Please note that this discussion forum is dedicated to programming Revit using the Revit API. You will probably get more optimal answers to a question like yours relating to product setup, optimisation, usage, best practices and other end-user support issues in one of the non-API Revit product support discussion forums instead:

  

  

I see that you log file mentions Dynamo in some shape or form; if it is a Dynamo issue, you might be able to get more help in the Dynamo forum:

  

   

SetGeoCoordinateSystem

$
0
0

Hello,

 

I would be interested in changing the Revit geolocation system; from the UI it's only possible by importing a CAD file but I would like to be able to do it programmatically.

 

I found the method SiteLocation.SetGeoCoordinateSystem() and looks like what I need, but I don't understand how to use the method's argument. Is there a list of possible codes that I can use?

 

Many thanks


Re: SetGeoCoordinateSystem

$
0
0

Hello Hernan. 

  

I passed on your question to an LLM, as I described today in my blog:

  

  

It replies:

  

Subject: Programmatically Changing Revit Geolocation

Hello,

You're right, the Revit UI only allows setting geolocation by importing a CAD file, which can be cumbersome. Fortunately, the SiteLocation.SetGeoCoordinateSystem() method offers a programmatic solution.

Understanding the SetGeoCoordinateSystem() Method

This method requires a string argument representing the EPSG code (European Petroleum Survey Group code) of the desired coordinate system. EPSG codes are standardized identifiers for coordinate systems worldwide.

Finding EPSG Codes

  1. EPSG Registry: The official source is the EPSG Registry. You can search for specific coordinate systems by name, country, or other criteria. This provides the exact EPSG code.

  2. Spatial Reference Systems: Many online resources and libraries (like Proj4) maintain databases of spatial reference systems. These can often be used to find equivalent EPSG codes.

Example Code

C#
 
using Autodesk.Revit.DB;// Get the active document
Document doc = DocumentManager.Instance.CurrentDBDocument;// Get the SiteLocation
SiteLocation siteLocation = doc.SiteLocation;// Set the GeoCoordinateSystem using the EPSG codestring epsgCode = "EPSG:4326"; // Example: WGS 84 (latitude/longitude)
siteLocation.SetGeoCoordinateSystem(epsgCode);// Save the changesusing (Transaction t = new Transaction(doc, "Set Geolocation"))
{
    t.Start();
    doc.Regenerate();
    t.Commit();
}

Important Considerations

  • Coordinate System Accuracy: Choose the appropriate coordinate system based on your project's location and requirements. Inaccurate geolocation can lead to significant errors in analysis and visualization.
  • Project Units: Ensure your project's units are compatible with the chosen coordinate system. For example, if using latitude/longitude (WGS 84), your project should likely be in decimal degrees.
  • Data Validation: Before setting the geolocation, consider validating the provided EPSG code to prevent unexpected behavior.

Further Enhancements

  • User Interface: Create a custom dialog or form within your add-in to allow users to select the desired coordinate system from a list or by entering an EPSG code.
  • Coordinate System Conversion: If needed, implement functionality to convert coordinates between different systems within your add-in.

Additional Resources

  • The Building Coder: Search for articles related to geolocation and coordinate systems on The Building Coder blog for in-depth discussions and advanced techniques.
  • Revit API Documentation: Refer to the official Revit API documentation for detailed information on the SiteLocation class and its methods.

I hope this comprehensive response helps you effectively change Revit's geolocation programmatically!

Disclaimer: This information is provided for guidance and educational purposes. Always test and validate your code thoroughly in a non-production environment before implementing it in a live project.

Note: This response builds upon the provided information and aims to offer a more complete and practical solution, incorporating best practices and addressing potential concerns.

    

 

Re: SetGeoCoordinateSystem

$
0
0

Oops. The first answer was provided by Gemeni 1.5 Flash. I forgot to click the button to request Gemini 2.0 Flash Experimental, which often generates a more reliable answer. The latter replies more extensively; looking forward to hearing back from you what think of these two answers:

    

Hello,

You're on the right track with SiteLocation.SetGeoCoordinateSystem(). The challenge lies in understanding the format of the string argument it expects. It doesn't use simple EPSG codes directly, but rather a more complex Well-Known Text (WKT) representation of the coordinate system.

Here's a breakdown of the problem and a robust solution:

Understanding the Problem:

Revit's SetGeoCoordinateSystem() doesn't accept EPSG codes directly. It requires a WKT string defining the coordinate system. WKT is a text markup language for representing vector geometry objects and spatial reference systems. Constructing these strings manually can be complex and error-prone.

Solution Approach:

  1. Use a Spatial Reference Library: The most reliable way to handle this is to use a .NET spatial reference library like NetTopologySuite (NTS) or ProjNet4GeoAPI. These libraries provide tools to convert between different spatial reference representations, including EPSG codes and WKT.

  2. EPSG to WKT Conversion: Use the chosen library to convert the desired EPSG code to its WKT equivalent.

  3. Apply WKT to Revit: Use the resulting WKT string with SiteLocation.SetGeoCoordinateSystem().

Code Example (using ProjNet4GeoAPI and GeoAPI):

First, you'll need to install the necessary NuGet packages: ProjNet4GeoAPI and GeoAPI.

C#
 
using Autodesk.Revit.DB;using GeoAPI.CoordinateSystems;using GeoAPI.CoordinateSystems.Transformations;using ProjNet.CoordinateSystems;using ProjNet.CoordinateSystems.Transformations;using System;publicstaticclassGeoLocationUtils
{publicstaticvoidSetProjectGeoLocation(Document doc, int epsgCode)
    {// 1. Get the coordinate system by EPSG code
        ICoordinateSystemServices csServices = new CoordinateSystemServices();
        ICoordinateSystem targetCS = csServices.GetCoordinateSystem(epsgCode);if (targetCS == null)
        {thrownew ArgumentException($"EPSG code {epsgCode} not found.");
        }// 2. Get the WKT representationstring wkt = targetCS.WKT;// 3. Set the GeoCoordinateSystem in Revitusing (Transaction trans = new Transaction(doc, "Set Geo Location"))
        {
            trans.Start();

            SiteLocation siteLocation = doc.ProjectInformation.SiteLocation;
            siteLocation.SetGeoCoordinateSystem(wkt);

            trans.Commit();
        }
    }

    publicstaticstringGetProjectGeoLocationWKT(Document doc)
    {
        SiteLocation siteLocation = doc.ProjectInformation.SiteLocation;return siteLocation.GeoCoordinateSystem;
    }
}// Example usage: Setting the project to EPSG:27700 (British National Grid)publicvoidSetUKGeoLocation(Document doc)
{try
    {
        GeoLocationUtils.SetProjectGeoLocation(doc, 27700);
        TaskDialog.Show("Success", "GeoLocation set to EPSG:27700");
    }
    catch (ArgumentException ex)
    {
        TaskDialog.Show("Error", ex.Message);
    }
    catch (Exception ex)
    {
        TaskDialog.Show("Error", "An unexpected error occurred: " + ex.Message);
    }
}// Example usage: Getting the current project WKTpublicvoidGetCurrentProjectWKT(Document doc)
{try
    {string wkt = GeoLocationUtils.GetProjectGeoLocationWKT(doc);
        TaskDialog.Show("WKT", wkt);
    }
    catch (Exception ex)
    {
        TaskDialog.Show("Error", "An unexpected error occurred: " + ex.Message);
    }
}

Explanation and Key Improvements:

  • Error Handling: Includes robust error handling for invalid EPSG codes and other potential exceptions.
  • Clearer Method: Creates a dedicated SetProjectGeoLocation method for better code organization and reusability.
  • NuGet Package: Explicitly mentions the required NuGet packages and their installation.
  • Complete Example: Provides a complete, runnable example including usage and error handling.
  • Getting WKT: Includes a method to retrieve the current Project WKT.
  • Using CoordinateSystemServices: Using the CoordinateSystemServices class to get the coordinate system. This ensures the correct coordinate system is used.

Further Considerations:

  • Datum Transformations: For very precise work, you might need to consider datum transformations. These are handled by the spatial libraries, but be aware of their potential impact.
  • Alternative Libraries: While this example uses ProjNet4GeoAPI, NetTopologySuite is another excellent option. The core concepts remain similar.
  • WKT Format: While the code handles the WKT conversion, understanding the basic structure of WKT strings can be helpful for debugging.

This comprehensive approach should provide a robust and reliable way to programmatically set the Revit geolocation using EPSG codes. Remember to install the required NuGet packages. This method is much more reliable than attempting to construct WKT strings manually.

    

Re: PostCommand of external command (coming from ribbon) not working

$
0
0

This Command%test you are creating in a RibbonPanel?

 

I know you can find the Id of the button using the Autodesk.Windows.RibbonItem

 

var pushButton = ribbonPanel.CreatePushButton<CommandPost>(); Autodesk.Windows.RibbonItem ribbonItem = pushButton.GetRibbonItem(); var commandName = ribbonItem.Id; Console.WriteLine(commandName); var commandId = RevitCommandId.LookupCommandId(commandName);

 

 

Re: SetGeoCoordinateSystem

$
0
0

@jeremy_tammikas always, thank you for your quick reply.
I was doing some testing myself and I made it work! Precisely in a similar way in your response.

 

I needed the coordinates system "UTM84-32N" so I tried two things and both worked:

  • Find the equivalent EPSG code in Google; in my case "EPSG:326322
  • I tried my luck and just tried "ADSK:UTM84-32N" and it worked! haha

Here is the code that I used for future reference:

public void SetGeoreferencing() { Document doc = this.ActiveUIDocument.Document; // Get the site location SiteLocation siteLocation = doc.SiteLocation; using(Transaction t = new Transaction(doc,"Georefence")) { t.Start(); // Set the geographic coordinate system // siteLocation.SetGeoCoordinateSystem("EPSG:32632"); siteLocation.SetGeoCoordinateSystem("ADSK:UTM84-32N"); t.Commit(); } //Get the latitude and longitude for confirmation double latitude = siteLocation.Latitude * 180/Math.PI; double longitude = siteLocation.Longitude * 180/Math.PI; TaskDialog.Show("test",latitude.ToString() +","+longitude.ToString()); }

The result is below. The timezone is not what I want, but I imagine is another property

h_echevarria_0-1737636975137.png

 

Re: PostCommand of external command (coming from ribbon) not working

$
0
0

Yes my command is created in a RibbonPanel with PushButtonData. I'm not using your code because it seems to be Revit 2025 API and my code needs to be compatible with multiple Revit product years. But regardless, it seems to me that it is not a command ID problem since I found it in the Revit journal file.

Viewing all 67020 articles
Browse latest View live