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

Re: Importing an excel sheet using c#

$
0
0

Use this code 

usingSystem;usingSystem.Data;usingSystem.Data.OleDb;usingSystem.IO;usingSystem.Windows.Forms;namespaceWindowsFormsApplication3{publicpartialclassForm2:Form{publicForm2(){InitializeComponent();}privatevoid button1_Click(object sender,EventArgs e){var dt =newDataTable();var fileName =Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"File1.xlsx");var query ="SELECT F1 As A, F2 As B, F3 As C FROM [Sheet1$]";using(OleDbConnection cn =newOleDbConnection{ConnectionString=ConnectionString(fileName,"No")}){using(OleDbCommand cmd =newOleDbCommand{CommandText= query,Connection= cn }){
                    cn.Open();OleDbDataReader dr = cmd.ExecuteReader();
                    dt.Load(dr);}}if(dt.Rows.Count>1){// remove header
                dt.Rows[0].Delete();}
            dt.AcceptChanges();Console.WriteLine();}publicstringConnectionString(stringFileName,stringHeader){OleDbConnectionStringBuilderBuilder=newOleDbConnectionStringBuilder();if(Path.GetExtension(FileName).ToUpper()==".XLS"){Builder.Provider="Microsoft.Jet.OLEDB.4.0";Builder.Add("Extended Properties",string.Format("Excel 8.0;IMEX=1;HDR={0};",Header));}else{Builder.Provider="Microsoft.ACE.OLEDB.12.0";Builder.Add("Extended Properties",string.Format("Excel 12.0;IMEX=1;HDR={0};",Header));}Builder.DataSource=FileName;returnBuilder.ConnectionString;}}}


or try to ZetExcel.com this would help you.
Thanks

 


External Command Initialization issue

$
0
0

I have completed the Revit API tutorials and written a number of example classes with general success.

 

However I am having a strange issue that I cannot seem to resolve. 

I created a code snippet of the External Command instantiation rather than type all that into each class. But when I use the snippet VS is erroring out on the IExternalcommand.Execute statement. Now if I type that into a new class it works fine but copy/paste or Snippet generates an error and the class will not debug or build properly. Delete the text and type it verbatim it works. 

The error is 

"Must declare a body because its not marked abstract, extern or partial"

Here is how I am declaring it:

 

 [TransactionAttribute(TransactionMode.Manual)]
    public class DeleteElement : IExternalCommand
    {
        Result IExternalCommand.Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
 
Again this works fine when I type it even using suggestion to fill in, but past or snippet does not work.

Re: Line length

$
0
0

The model line (and in fact all database elements) has a property named Location:

 

https://apidocs.co/apps/revit/2019/89438f4f-7e15-835a-0c66-d6adbc8dd00c.htm

 

You can cast the value returned by it to a LocationCurve object:

 

https://apidocs.co/apps/revit/2019/9dd6eb99-f105-a05f-dc1b-dfde17b8768c.htm

 

For a straight model line, the curve is in fact a line segment.

 

You can obtain the line endpoints from that.

 

You can also modify the model line by setting its Location property to a new LocationCurve object with a different defining geometry curve.

 

Cheers,

 

Jeremy

 

 

 

 

Re: External Command Initialization issue

$
0
0

Dear Chubbard,

 

Thank you for your query and congratulations on your success so far.

 

Looking at your code snippet above, I see a function signature with no body.

 

Therefore, the error message 'must declare a body' makes perfect sense.

 

I don't quite see what you are trying to achieve.

 

If you like, take a look at The Building Coder samples:

 

https://github.com/jeremytammik/the_building_coder_samples

 

They define a large number of external commands and simply repeat the declaration of the Execute method signature for each.

 

Best regards,

 

Jeremy

 

Re: External Command Initialization issue

$
0
0

Jeremy

 

I didn't post the entire class, just the signature. In my snippet I have the signature and closing braces defined, I then insert the body code. 

Now if I type the function signature my class builds and runs fine. If I use the exact same code via cut paste or snippet it will not build or run and the error is below. I cannot figure out why it makes any difference how the text gets added to the class. 

What I am trying to accomplish is to be able to create a new class quickly. I have snippets of all sorts of code stored on my system, I have never run into this issue where typing vs insert makes a difference. 

IFCExportConfigurationsMap AddSavedConfigurations not working

$
0
0

Hello,

I'm trying to add the IFC Export configurations to my IFC Exporter add on.

However when I use the following code the Saved Configurations are not added.

Using 'C:\Program Files\Autodesk\Revit 2018\AddIns\IFCExporterUI\IFCExportUI.dll' > Not shown at all.

Using 'C:\ProgramData\Autodesk\ApplicationPlugins\IFC 2018.bundle\Contents\2018\IFCExportUIOverride.dll' > Only shown once the File Export IFC command is initialised.

 

            Dim configurationsMap As IFCExportConfigurationsMap = New IFCExportConfigurationsMap()
            configurationsMap.Add(IFCExportConfiguration.GetInSession)
            configurationsMap.AddBuiltInConfigurations()
            configurationsMap.AddSavedConfigurations()

Any ideas why this is and what I can add to my code to initialise/force the Saved Configurations to display?

Kind Regards

David

 

Re: Creating new Entity stops the external event handler

$
0
0

Uh! This has actually been missed in the copy paste process. I tried to clean and simplify my copied code and apparently I messed it up. My apologies. I assure you the original version that I run has got t.Start() and t.Commit() within the same scope.

 

So my question is still standing valid.

 

Here's the correct code:

 

            // get the DataStorage element that is associated to our schema
            DataStorage dataStorage = DataHelpers.GetDataStorage(doc);
            if (null == dataStorage)
            {
                // then it means it's the first time this tool is used on this project. then let's create the DataStorage element and fill it the CSDataItems
                using (Transaction t = new Transaction(doc, "Setting up CS Data in RevitDB"))
                {
                    t.Start();

                    // create DataStorage element
                    dataStorage = DataStorage.Create(doc);

                    // create Entity
                    Entity entity = new Entity(schema);

                    // up to this stage needs to be done and stored in the documents whether or not we have any CSDataItems.
                    // created items above will be used in future if CSDataItems is empty. Otherwise we'll fill the DataStorage with CSDataItems.
                    if (BindDataToElementTypesForm.TheForm.CSDataItems != null)
                    {

                        // Map fields
                        IDictionary<string, Entity> mapOfEntities = new Dictionary<string, Entity>();

                        foreach (CSDataItem cSData in BindDataToElementTypesForm.TheForm.CSDataItems)
                        {

                            // create sub-Entity
                            Entity subEntity = new Entity(new Guid("90BA988E-BE74-46BE-A2E4-1F23367621CA"));// this is the line where the code stops
                            subEntity.Set("ElementTag", cSData.ElementTag);
                            subEntity.Set("ElementName", cSData.ElementName);
                            subEntity.Set("Category", cSData.Category);
                            subEntity.Set("Website", cSData.Website);
                            subEntity.Set("ProjectId", cSData.ProjectId);
                            subEntity.Set("Section", cSData.Section);

                            subEntity.Set("BoundToElementUniqueId", String.Empty); // to be filled with elem.UniqueId
                            subEntity.Set("BindDate", String.Empty); //to be filled with DateTime.Now.ToString("MM/dd/yyyy")
                            subEntity.Set("BoundBy", String.Empty); //to be filled with UserPrincipal.Current.DisplayName

                            mapOfEntities.Add(cSData.ElementId, subEntity);
                        }

                        entity.Set("MapField", mapOfEntities);

                        dataStorage.SetEntity(entity);
                    }

                    t.Commit();

                }

            }

Re: Creating new Entity stops the external event handler

$
0
0

I found this  in the remarks of SetSubSchemaGUID method:

 

"Fields of type Entity - subentities - need to specify their Schema. The framework will prevent subentities with incorrect schemas from being stored in the entity. Additionally, the access level of the subschema will be checked against the currently executing add-in and access to restricted subentities will be prevented."

 

I'm creating my sub-entities with a new Guid (or do I have to pass the main schema to the constructor?) and testing my add-in with Add-in Manager tool. Could this be part of the problem?

 

Here's how I created my schema:

                Guid schemaGuid = new Guid("A10D426E-5899-45E6-979C-BAE987B564B5");
                //Guid schemaGuid = Guid.NewGuid();

                SchemaBuilder schemaBuilder = new SchemaBuilder(schemaGuid);

                // set read access
                //schemaBuilder.SetReadAccessLevel(AccessLevel.Public);

                // set write access
                //schemaBuilder.SetWriteAccessLevel(AccessLevel.Public);

                // set schema name
                schemaBuilder.SetSchemaName("CSDataItems");

                // set documentation
                //schemaBuilder.SetDocumentation("Schema to hold construction schedule data items.");

                var mapField = schemaBuilder.AddMapField("MapField", typeof(string), typeof(Entity));

                mapField.SetSubSchemaGUID(new Guid("90BA988E-BE74-46BE-A2E4-1F23367621CA"));

                mapField.SetDocumentation("Each item in this map is corresponding to one CSDataItem. The int will be ElementId of the element & the Entity will store the rest of data.");

                // register the schema
                schema = schemaBuilder.Finish();

 


Re: Creating new Entity stops the external event handler

$
0
0

Update: creating sub-entities with a newly created "sub-schema" fixed the problem (instead of passing a new Guid). So not sure how the example above has been working in the past. It didn't work in my case. I had to create simple fields for my sub-schema. Here's the code:

 

            Guid subschemaGuid = new Guid("90BA988E-BE74-46BE-A2E4-1F23367621CA");

            SchemaBuilder subSchemaBuilder = new SchemaBuilder(subschemaGuid);

            // set schema name
            subSchemaBuilder.SetSchemaName("CSDataSubSchema");

            // create a fields to store CS values of  ElementTag, ElementName, ElementID, Category, Website, ProjectId
            subSchemaBuilder.AddSimpleField("ElementTag", typeof(String));
            subSchemaBuilder.AddSimpleField("ElementName", typeof(String));
            subSchemaBuilder.AddSimpleField("ElementId", typeof(String));
            subSchemaBuilder.AddSimpleField("Category", typeof(String));
            subSchemaBuilder.AddSimpleField("Section", typeof(String));
            subSchemaBuilder.AddSimpleField("Website", typeof(String));
            subSchemaBuilder.AddSimpleField("ProjectId", typeof(String));

            subSchemaBuilder.AddSimpleField("BindDate", typeof(String)); // date which the element got bound to this CSDataItem
            subSchemaBuilder.AddSimpleField("BoundToElementUniqueId", typeof(String)); // the UniqueId of the element which is bound to that CSDataItem
            subSchemaBuilder.AddSimpleField("BoundBy", typeof(String));

            // register the schema
            Schema subSchema = subSchemaBuilder.Finish();
            Entity subEntity = new Entity(subSchema);

 

Thanks!

CustomExport, how to speed up Export Time?

$
0
0

How can one successfully implement multithreading into CustomExporter / IExportContext?

 

 

Is there really no way to implement concurrency?

 

Have tried multithreading using window's TAP data flow, introducing queues and concurrent dictionaries as well to store a memory buffer of vital node information. However, the export time barely experiences any / much boosts in efficiency.

Am wondering if anyone has played around with the customexporter handling huge models, or know some one / link who might.

Is it really impossible to implement multi threading to facilitate export process? 

 

Or could there be a better way that I have yet to explore in order to speedup the export process?

Re: External Command Initialization issue

$
0
0

It definitely makes no difference whatsoever whether the text is typed in character by character or pasted from the clipboard. The result is identical. The difference must lie elsewhere.

 

Re: Creating new Entity stops the external event handler

$
0
0

Congratulations on solving this.

 

Why do you need a subschema at all? Do you have a complex collection of schemata?

 

All other samples I have seen just use the one single main schema, no subschemata at all.

 

 

Re: CustomExport, how to speed up Export Time?

$
0
0

The Revit API and all the functionality it provides cannot make use of multithreading:

 

 

If you wish to use multithreading to speed up the custom export, the only possibility to do so is by using it in pieces of your code that are completely independent of Revit.

 

For instance, you could use your Revit add-in and the Revit API to retrieve the custom exported information, and then pass it on for further complex processing into other threads.

 

I hope this helps.

 

Cheers,

 

Jeremy

 

Re: IFCExportConfigurationsMap AddSavedConfigurations not working

Re: Creating new Entity stops the external event handler

$
0
0

Yes the data structure is a bit complex. So I thought firstly storing one DataStorage element in the document and populating the data inside it using one complex schema would be much neater as opposed to creating multiple DataStorages for each "DataItem" that I have. Secondly using a map field of type IDictionary<string, Entity> suddenly makes all the IDictionary methods available to me to retrieve & manipulate the data, and also makes it easier to check for existing "DataItems". 

 

 

Cheers.

Hoss


Re: Perspective View 2019 Field of View

Re: Creating new Entity stops the external event handler

$
0
0

Thank you for the answer! That makes total sense.

 

Re: how to verify label on element using revit api?

Re: how to verify label on element using revit api?

$
0
0

Hi 

Do we able to get relation between tag and its element?

as in above case  able to get independent tags of particular category.

for eg having 6 doors got 6 door tags in above case

suppose one of door does not have tag then it should able to find particular door does not having tag.

so it is require find relation between element category and element tag category.

 

Re: i want to check whether tag is present on door by api how should i checked?

$
0
0
var doorTagsIds = new HashSet<ElementId>(collector.OfClass(typeof(IndependentTag)).OfCategory(BuiltInCategory.OST_DoorTags).OfType<IndependentTag>().Select(x => x.GetTaggedLocalElement()?.Id).Where(x => x != null));

this collect door not doortag

able to collect door tag by this

 FilteredElementCollector Collector1 = new FilteredElementCollector(activeDoc, vp.ViewId).OfCategory(BuiltInCategory.OST_DoorTags).WhereElementIsNotElementType();

 

but now my problem is getting collection doorTags Ids.But to compare with doors ids are different than their tags.

So how do we get relation between element and element Tag?

So that able to verify whether element is contain tag or not? 

Viewing all 60418 articles
Browse latest View live




Latest Images