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

Re: Running code from btn_Click event on custom form

$
0
0

"You can make the text from the text box a static variable so it is available after the dialog box is gone."

I tried this but I get the red line under TxtExst of the TxtExst.Text. I think I'm placing them in the wrong spot. Doesn't work under the Btn_Click event.

 

public static string ExstDes = TxtExst.Text;
public static string NewDes = TxtNew.Text;

 

Thanks for the help.

 


Extend/Trim Grids in a view

$
0
0

Hi All,

 

I'm trying to Extend/Trim grid lines as part of a process I'm working in but I'm facing the following issue:

 

When I use the method grid.SetVerticalExtents(double bottom, double top) I get an error saying:

 

"The bottom and top ranges are reversed for the extents.
Parameter name: bottom"

 

using (Transaction tx = new Transaction(doc, "Redimension de Grids"))
                {
                    tx.Start("Se ajusta la dimension de los grids.");
                    foreach (ElementId id in gridsIds)
                    {
                        Grid grid = doc.GetElement(id) as Grid;
                        IList<Curve> curvasGrid = grid.GetCurvesInView(DatumExtentType.ViewSpecific, doc.ActiveView);
                        Curve linea = curvasGrid.First();

                        // Se compara la direccion de los vectores para obtener el que está más a la izquierda.
                        XYZ centro = rle.PointOntoPlane(planoVista, linea.Evaluate(0.5, true));
                        centro = new XYZ(centro.X, centro.Y, 0);

                        // Se corrigen los grids en la vista para que todos queden de la misma longitud.

                        Outline ext = grid.GetExtents();
                    
                        double limiteVert = rle.cm_to_ft(300); 
                        double extendBottom = 0;
                        double extendTop = ((puntoMasAlto.Z + limiteVert) - linea.GetEndPoint(1).Z);
                        grid.SetVerticalExtents(extendBottom, extendTop);

                        grids.Add((centro - rIzq).GetLength(), grid);
                    }
                    tx.Commit();
                }

I don't know what am I missing here.

 

Any tip of advice will be well received.

 

Regards!

Re: multistorey stair subements

Re: Running code from btn_Click event on custom form

Re: Extend/Trim Grids in a view

$
0
0

I found my error.  I was trying to set as the "delta" (variation) in each attribute but it needs the global Z double of the XYZ you want to extend/trim.

 

Now, after correcting this there is no error but the elements are not changing.

 

 

using (Transaction tx = new Transaction(doc, "Redimension de Grids"))
                {
                    tx.Start("Se ajusta la dimension de los grids.");
                    foreach (ElementId id in gridsIds)
                    {
                        Grid grid = doc.GetElement(id) as Grid;
                        IList<Curve> curvasGrid = grid.GetCurvesInView(DatumExtentType.ViewSpecific, doc.ActiveView);
                        Curve linea = curvasGrid.First();

                        // Se compara la direccion de los vectores para obtener el que está más a la izquierda.
                        XYZ centro = rle.PointOntoPlane(planoVista, linea.Evaluate(0.5, true));
                        centro = new XYZ(centro.X, centro.Y, 0);

                        // Se corrigen los grids en la vista para que todos queden de la misma longitud.
                        Outline inOut = grid.GetExtents(); // used to check what are the extents before the change
                        double limiteVert = rle.cm_to_ft(300);
                        double bott = linea.GetEndPoint(0).Z;
                        double top = (puntoMasAlto.Z + limiteVert);
                        grid.SetVerticalExtents(bott, top);
                        Outline output = grid.GetExtents(); // used to check the extents after the change

                        grids.Add((centro - rIzq).GetLength(), grid);
                    }
                    tx.Commit();
                }

In the code is shown that I put "GetExtents" to monitor the change in the extents. When debugging, I can see they are changing as I want, but in the model, they are not being changed.

 

What am I missing here?

 

Cheers!

 

Re: Running code from btn_Click event on custom form

$
0
0

Its probably easier (and better) to just make a static string variable at the start of your code;

 

public static string mystring ="";

 

Then in the click event, you should have access to the textbox contents and the string, so you can easily set the string equal to the contents of the textbox with something like:

 

mystring = textbox1.Text.ToString();

 

Then you can close the form from within the button click.  That will return to the code af, and put all the heavy lifting code after the form show event.  

 

The cancel click event can just close the whole addin. 

 

Re: Running code from btn_Click event on custom form

$
0
0

That’s exactly what I ended up doing. Thanks for the help!!!

Re: TagText From Room Tags

$
0
0

Hi,

 

they are RoomTag elements, not IndependentTag elements.

 

Revitalizer


Add shared Parameters to all Families in Folder

$
0
0

Hi forum,

 

i created a little Macro that lets me add some shared paramers from the current set SP file to a family. See here


UIDocument uidoc = this.ActiveUIDocument;	
Document doc = uidoc.Document;		
DefinitionFile SP_DefFile = Application.OpenSharedParameterFile();
TaskDialog.Show("Title",SP_DefFile.Filename);
using (Transaction t = new Transaction(doc, "Add shared Parameters from current SP File" + SP_DefFile.Filename))
{
	t.Start();
	FamilyManager mgr = doc.FamilyManager;
	foreach(DefinitionGroup defGroup in SP_DefFile.Groups)
	{
		foreach(ExternalDefinition def in defGroup.Definitions)
		{
			sb += "   " + def.Name + "\n";
			mgr.AddParameter(def,Autodesk.Revit.DB.BuiltInParameterGroup.PG_IDENTITY_DATA,true);
		}
	}
	t.Commit();
}

i would like to expand this by wrapping the code above into the method 

public void AddAllSpToFamFromSpFile(string filePath)

so that all the families in the folder "filePath" will get the Parameters.

I did some reasearch but i did not find a way to get the families into the FamilyManager one at a time.

 

any ideas?

Re: browsing model files in the cloud (A360 C4R)

$
0
0

HI,

 

we also try to achive this. i am not able to find any APIs regarding this so we created an Addin which stores the BIM 360 central path to our DB while adding files to BIM 360. From our DB we will populate a Grid and shows all the Files which is added.

For creating local copy i am using the below method.

 

 private static Document OpenNewLocal(Autodesk.Revit.ApplicationServices.Application app, ModelPath centralPath, ModelPath localPath)
        {
            // Create the new local at the given path
            WorksharingUtils.CreateNewLocal(centralPath, localPath);

       }

I dont know is this valid for the current senario.

Re: multistorey stair subements

$
0
0

Dear Paul,

 

Thank you for your update and pointer to the wish list item.

 

Based on that, it would appear that no solution is currently known for what you are after.

 

By the way, can you achieve what you want in the user interface?

 

Please be aware that the Revit API hardly ever supports any functionality that is not also available in the user interface.

 

Therefore, if the UI does not support this, the API will probably not do so either.

 

Still, I asked the development team again for a response.

 

Cheers,

 

Jeremy

 

Re: Add shared Parameters to all Families in Folder

$
0
0

You ae now using your active  UI document to run the script in. This is wrong.

If with 'folder' you mean folder on your harddrive or network, you should tell Revit to open the families (file in the folder) one by one in the background, and then you can access the family's familymanager to do your work with.

 

This code should do the trick:

 

UIApplication uiapp = commandData.Application;
Document fDoc = uiapp.Application.OpenDocumentFile(// your file path here);
if (fDoc.IsFamilyDocument)
{
// your code here
}

 EDIT: not sure how to do this from a macro, but the idea should be the same (probably should be an Application level macro).

Re: Create dimensions for familyinstance in linked file

$
0
0

For some reason, the NewDimension method expects a slightly different reference then the one you get from PickObject(). This method gets you a reference you can use.

 

		private Reference MakeLinkedReference4Dimension(Document doc, Reference r)
		{
			if (r.LinkedElementId==ElementId.InvalidElementId) return null;
			string[] ss = r.ConvertToStableRepresentation(doc).Split(':');
			string res = string.Empty;
			bool first = true;
			foreach(string s in ss)
			{
				string t = s;
				if (s.Contains("RVTLINK")) t = "RVTLINK";
				if(!first)
				{
					res = string.Concat(res,":",t);
				}
				else
				{
					res = t;
					first = false;
				}
			}
			return  Reference.ParseFromStableRepresentation(doc,res);
		}

 

How to change settings in snap dialog by Revit API?

$
0
0

Hello,

in Revit's ribbon [Manage] - [Snaps] dialog, I want to uncheck the two options: [snap to remote objects ], [snap to point clouds ]. How to do it by Revit API?

QQ截图20180907103810.png

Re: Raising ExternalEvent stops before Execute method

$
0
0

I too have this problem now. 
The wierd thing is that sometimes it works and sometimes it doesnt. 
I have wrapped the entire Execute-method in a try catch block and I've set a breakpoint at the first line in the method, but nothing. 

 

Is there any way of figuring out what is wrong?


Re: browsing model files in the cloud (A360 C4R)

Re: Add shared Parameters to all Families in Folder

$
0
0

Dear Jeff,

 

Thank you for your query, and many thanks to Bram for answering.

 

I fully agree with him.

 

In addition, you could use generic .NET and OS functionality to determine all the family files in the folder, and you need to open a separate transaction on each family document to modify:

 

  • Retrieve all RFA files in the given folder
  • For each RFA:
  • fDoc = OpenDocumentFile...
  • using (Transaction t = new Transaction(fDdoc...

 

There no reason why this needs to be in an application level macro.

 

The Revit API functionality is identical in all types of macros.

 

I hope this helps.

 

Cheers,

 

Jeremy

 

Re: Extend/Trim Grids in a view

$
0
0

Dear Jorge,

 

Thank you for your query and congratulations on solving your first problem.

 

You say that your call to GetExtents is clearly showing you that an update is taking place successfully.

 

After you terminate the operation, the changes are lost again.

 

Obviously, then, some of the changes are being ignored.

 

One possibility is that each of the changes you make is referring to the last regenerated state of the Revit model.

 

If that is so, then each individual modification would be performed successfully, but overwritten by the following one.

 

In the end, when you commit the transaction, only the last modification is actually committed.

 

Please try adding a call to regenerate the document after each one of the individual modifications is applied, and see whether that helps.

 

Thank you!

 

Best regards,

 

Jeremy

 

Re: Running code from btn_Click event on custom form

$
0
0

"The cancel click event can just close the whole addin."

 

I'm using this.close(); in both instances and it seems to be working. Is there a better way?

 

        private void BtnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void BtnProceed_Click(object sender, EventArgs e)
        {
            ExstDes = TxtExst.Text.ToString();
            NewDes = TxtNew.Text.ToString();
            this.Close();
        }

Re: Running code from btn_Click event on custom form

$
0
0

Good programming practice isolates components as much as possible and defines clear and minimal interfaces between them.

  

You should read up on that.

  

Therefore, I would advise against defining global and static variables as much as possible (and it is mostly easy to avoid them).

  

Try passing the required data in and out of methods via arguments and return values, or encapsulate data together with the associated functionality processing it into its own dedicated little class.

 

That is one of the paradigms of object-oriented programming, aka OO.

 

Here is the first thing that came up performing an Internet search for "OO .NET":

 

https://duckduckgo.com/?q=oo+.net

 

https://www.c-sharpcorner.com/UploadFile/84c85b/object-oriented-programming-using-C-Sharp-net/

 

Cheers,

 

Jeremy

 

Viewing all 67020 articles
Browse latest View live


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