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

Re: Find perpendicular point from one point to a line

$
0
0

Hey,

Use:

 

Line lineBC;

XYZ pointA;

XYZ pointH = lineBC.Project(pointA).XYZPoint;

 

Bye

Benoit


Re: Split wall

$
0
0

Hi,

 

you can set Wall's LocationCurve with another curve.

Note:

If your Wall's LocationCurve is a straight line, so must be the target curve.

If it is an Arc, target curve must be an Arc, too.

 

 

Revitalizer

Re: Load application

Get Section of FamilySymbol

$
0
0

How to get the cross section of a beam or column from the FamilySymbol? Must I collect the FamilyInstances of this FamilySymbol and then get the Geometry of a FamilyInstance? Is there a simpler way?

Re: Split wall

$
0
0

Interesting, but how do you do that?

Location is Lecture only.

You find the parameter and replace it? Can you give me a hint?

 

Thanks

Benoit

Re: Split wall

Re: Temporarily highlight an element (without selecting)

$
0
0

I believe the problem there will be the persistent open transaction. I'm pretty sure Revit does not allow more than one open transaction at a time, and therefore would not be able to make any further edits to the model until the transaction is closed.

 

I managed to get this to work using 's solution but the downside is it does require an open transaction, meaning the highlight operation is listed in the undo menu once committed.

 

 

SAT Family Import UI works, API doesn't

$
0
0

Hello,

 

The past few days I've been trying to work out an issue I've been having with SAT imports. Per the Revit API example (http://www.revitapidocs.com/2018/d6120e08-f260-577d-b6cf-3fe5b042a54e.htm) it looks like I'm doing everything appropriately, but certain SAT objects will just not import, literally there are no shapes being pulled in from the SAT file. However, if I try to import the SAT file directly from the UI, it works just fine and the shape is visible and present.

 

Any thoughts?

 

def createFamily(file, mainView):
    t.Start()
    #===========Create new Family Document from Generic Model Template============#
    try:
        templateFileName = app.FamilyTemplatePath + "\Generic Model.rft"
        famDoc = app.NewFamilyDocument(templateFileName)
    except Exception as e:
        Console(context=locals())
        error = 1
    t.Commit()
    if file.split(".")[-1].lower() == "sat" or file.split(".")[-1].lower() == "3dm":
        shapeImporter = ShapeImporter()
        shapeImporter.InputFormat = ShapeImporterSourceFormat.Auto
        shapes = List[GeometryObject](shapeImporter.Convert(famDoc, file))
        if shapes.Count > 0:
            famDocT = Transaction(famDoc, "FamilyImport")
            try:
                ####################################################
                #"Start" the transaction
                famDocT.Start()
                dsImportSat = DirectShape.CreateElement(famDoc, ElementId(BuiltInCategory.OST_GenericModel))
                dsImportSat.SetShape(shapes)
                # "End" the transaction
                famDocT.Commit()
                fam = famDoc.LoadFamily(doc, FamilyOption())
            except Exception as e:
#Console Debugging Console(context=locals()) finally: famDoc.Close(False) return fam else:
#Console Debugging Console(context=locals()) famDoc.Close(False) messages.append("An Error occured when trying to import: " + file.split("\\")[-1] + ". No geometry could be found to import.") return None

Re: Get Section of FamilySymbol

$
0
0

Hi,

 

I didn't test this, but give it a try...

 

Family fam = yourFamilySymbol.Family;

if(fam.CanHaveStructuralSection())
{
	StructuralSection ss = yourFamilySymbol.GetStructuralSection();

	if(ss!=null)
	{
		// the StructuralSectionAnalysisParams property is a container object
		double area = ss.StructuralSectionAnalysisParams.SectionArea;
		// and so on...
	
		// depending of StructuralSectionShape, cast StructuralSection into a more specified object
	
		switch(ss.StructuralSectionShape) // or fam.StructuralSectionShape
		{
			case StructuralSectionShape.RectangleHSS:
			
			StructuralSectionRectangleHSS ssrhss = ss as StructuralSectionRectangleHSS;
			double height = ssrhss.height;
			// more properties to get...
			break;
			
			case StructuralSectionShape.PipeStandard:
			
			StructuralSectionPipeStandard  ssps = ss as StructuralSectionPipeStandard;
			double diameter = ssps.Diameter;
			
			break;
			
			case StructuralSectionShape.NotDefined:
			// you could analyze the geometry, as you wrote
			break;
			
		}
	}
}

There are many, many classes derived from StructuralSection class, so feel free to explore them in detail and to add them to the switch/case block.

I think the resulting geometry, the curve loops of the sections, can be reproduced by combining the available properties of each derived class, i.e. corner radii, distances, thicknesses and so on.

 

There is also another approach using REX framework:

https://thebuildingcoder.typepad.com/blog/2015/03/framing-cross-section-analyser-and-rex-in-revit-2015.html

 

Revitalizer

Re: Set HalfTone

$
0
0

I'm fairly new to C#. I'm also trying to create a command to make an element halftone in view.  I want it to first test whether the element is halftone and then switch states so I can use the command to flip-flop the element's halftone display.  I think I've incorporated the Halftone { get; } correctly to do this.

 

I have successfully gotten the command to make an element halftone, but I cannot yet get it to change that same element back again.

Re: Issue with RevitAddInUtility for Revit 2019 and customized installer

$
0
0

I agree with you so much Max! The same as you. I cannot make work a simple setup project qith my installer class calling the RevitAddInApplication class to do all the stuff for the manifests.

 

I have been using RevitAddInUtility for many years and since version 2019, it is no more MSIL. As an installer class is by default executed as x86, it's a trap, excepting going deeper in installUtil.exe

https://blogs.msdn.microsoft.com/heaths/2006/02/01/64-bit-managed-custom-actions-with-visual-studio/

Something so old. Go back to 2006?

 

Unbelievable to get here and make RevitInstallUtil unusable !!! This must be a compilation directive error in the release.  I hope Autodesk will correct that very soon.

Re: Quick way of counting rows in a schedule?

$
0
0

You can find all the elements in a schedule using a FilteredElementCollector(document, scheduleview.Id).

Delete a row from the schedule in a temporary transaction and compare the elements before and after to determine the Elements on a row in the schedule.

 

public void CountScheduleEntriesOnRow()
 {
   StringBuilder sb = new StringBuilder();
   Document doc = this.ActiveUIDocument.Document;
   ViewSchedule view = doc.ActiveView as ViewSchedule;
   if (view==null) return;
   TableData table =  view.GetTableData();
   TableSectionData section = table.GetSectionData(SectionType.Body);

   List<ElementId> elems = new FilteredElementCollector(doc,view.Id)
        	.ToElementIds()
        	.ToList();
   List<Element> ElementsOnRow = new List<Element>();
   List<ElementId> Remaining = null;
   int RowToAnalyse = 2;

   using(Transaction t = new Transaction(doc,"dummy"))
	{
		t.Start();
		using (SubTransaction st = new SubTransaction(doc))
		{
			st.Start();
			section.RemoveRow(RowToAnalyse);
			st.Commit();
		}
		Remaining = new FilteredElementCollector(doc,view.Id)
			.ToElementIds()
			.ToList();
		t.RollBack();
	}
   foreach(ElementId id in elems)
   {
      	if(Remaining.Contains(id)) continue;
       	ElementsOnRow.Add(doc.GetElement(id));
   }
   sb.AppendLine(string.Format("{0} elements on row {1}",ElementsOnRow.Count,RowToAnalyse));
   foreach(Element e in ElementsOnRow)
   {
      	sb.AppendLine(string.Format("<{0}> {1} {2}",e.Id,e.Name, e.GetType()));
   }
   TaskDialog.Show("debug",sb.ToString());
}

Re: Find perpendicular point from one point to a line

$
0
0

Thank you so much for your great simple solution Smiley Very Happy.

Re: Find perpendicular point from one point to a line

$
0
0

Hi :

Notice if your are dealing with the following situation:

图像 1.png

Your codes should be little bit more complicated then.

// Suppose you have already got these points
XYZ pointA, pointB, pointC;
Line unboundLine = Line.CreateBound(pointB, pointC);
unboundLine.MakeUnbound();

XYZ pointH = unboundLine.Project(pointA).XYZPoint;

There is another method: Line.CreateUnbound(XYZ, XYZ), which is easier for creating unbound line. Remember to immediately dispose the Line if you are sensitive with performance.

 

 

In my projects, we have wrapped them into several methods:

        public static XYZ UnboundProject(this Line line, XYZ point)
        {
            using (Line unboundLine = line.GetUnbound())
            {
                IntersectionResult result = unboundLine.Project(point);
                Debug.Assert(result != null);

                return result.XYZPoint;
            }
        }
        public static Line GetUnbound(this Line line)
        {
            if (line.IsBound)
            {
                Line cloned = line.Clone() as Line;
                cloned.MakeUnbound();
                return cloned;
            }
            else
            {
                return line.Clone() as Line;
            }
        }

 

 

Re: Temporarily highlight an element (without selecting)

$
0
0

Thank you for replying:

I have tried 's solution and the code ran without exceptions.

As I post, I wrap the 'highlight' operation into a sub-transaction. I did the following steps:

  1. Start transaction
  2. Pick an element (for example, a duct, I didn't tried many other elements because my work is focused on MEP)
  3. Start subtransaction
  4. Override the graphic settings of the picked Duct element
  5. Commit subtransaction
  6. Now we are back to the open 'main' transaction. I start another pick operation to prompt the user to pick something (for example, a point on the former picked element)
  7. Do other job, like modify the documents .

Codes ran well, no exception. But, in step 6, when picking, Revit does NOT display the correct graphic settings.

Here are my codes:

 

            using (SubTransaction subt = new SubTransaction(doc))
            {
// GetActiveUIView() is my own extension method View v = doc.GetElement(Workspace.UiDoc.GetActiveUIView().ViewId) as View; OverrideGraphicSettings oldOgs = new OverrideGraphicSettings(v.GetElementOverrides(mainRefer.Id)); OverrideGraphicSettings newOgs = new OverrideGraphicSettings(oldOgs); // 临时修改求出的参照主管的显示颜色
// Temporarily change line color subt.Start(); newOgs.SetProjectionLineColor(new Color(200, 0, 0)); v.SetElementOverrides(mainRefer.Id, newOgs);
// Workspace is my own Utility static class for easy approach of common API objects, such as doc, uidoc... Workspace.Doc.Regenerate(); Workspace.UiDoc.RefreshActiveView(); subt.Commit(); // 在参照主管上拾取一个用来求出行进方向的参照点 mainPickRef = Workspace.UiDoc.Selection.PickObject( ObjectType.PointOnElement, filter, "单击拾取一个参照点以确定偏移的行进方向"); // 复位参照图元的显示设置 subt.Start(); v.SetElementOverrides(mainRefer.Id, oldOgs); subt.Commit(); }

Here is the screen shot of Revit UI:

图像 1.png

In the View settings, all ducts should be displayed with blue line.

Notice there is a dark gray line duct. I picked that Duct ahead, and invoke another Pick operation. At this moment, it should be displayed with RED line.

 

I was thinking that perhaps it's because I had not commit the main Transaction.

If I override the graphic settings in a Transaction, it works. But in my former mentioned steps, it does NOT work as I demanded.

 

To be honest, I don't want this CHANGING COLOR operation to be listed in the UNDO list Man Frustrated

 

 

 


Re: Find perpendicular point from one point to a line

$
0
0

Hi ,

 

Thank you so much for the great solution. I just implemented your suggestion into my code and it worked great. 

Million likes Smiley Very Happy

 

Best Regards,

 

Cherry Truong

Ducts are disconnected after changing size using code

$
0
0

Hi everyone,

 

I am trying to create an automated script to generate duct from Air Terminal to Main Duct.  Following is my code: 

 

// Create first Duct
                                Duct firstduct = Duct.Create(document, filterelements2.Where(o => o.Name == selectedDuctType).First().Id, selectedDuct.ReferenceLevel.Id, AirTerminalConnector, B);


                                // Get unused connector of the first duct
                                ConnectorSet unusedConnector1 = firstduct.ConnectorManager.UnusedConnectors;
                                List<Connector> list3 = new List<Connector>();
                                foreach (Connector c in unusedConnector1)
                                {
                                    list3.Add(c);

                                }
                                Connector unused1 = list3.First();

                                // Create seconduct
                                Duct seconduct = Duct.Create(document, pipeSysTypeId, firstduct.DuctType.Id, selectedDuct.ReferenceLevel.Id, B, D);
                               

                                ConnectorSet seconductConnectors = seconduct.ConnectorManager.Connectors;
                                List<Connector> list4 = new List<Connector>();
                                foreach (Connector c in seconductConnectors)
                                {
                                    list4.Add(c);
                                }

									// Connect 2 connectors of 2 pipe to create the fitting
                                    unused1.ConnectTo(list4.First());
									
									
                                    // Create take off fitting
                                    document.Create.NewTakeoffFitting(list4.Last(), selectedDuct);
                                  //  seconduct.Document.Regenerate();

and the result is as following image: 

 

Capture.PNG

The problem is the Second Duct have difference size with the first Duct. Then I tried to change the size of the Second Duct equal to the First Duct by following Code: 

BuiltInParameter daimeterpara = BuiltInParameter.RBS_CURVE_DIAMETER_PARAM;
                                Parameter parameter = seconduct.get_Parameter(daimeterpara);
                                parameter.Set(Convert.ToDouble(firstduct.Diameter));
                                seconduct.Document.Regenerate();

But the result is the First Duct disconnected with the Second Duct as following image: 

Capture.PNG

If anyone had experience with this issue please help me, I would be very appreciated your help :).

Thank you.

 

Best Regards,

 

Cherry Truong

 

 

Re: Set HalfTone

$
0
0

hi ,

Try using the below code

ElementId eid;
if(doc.ActiveView.GetElementOverrides(eid).Halftone==true)
                   {
                        OverrideGraphicSettings ORGS = new OverrideGraphicSettings();
                        ORGS.SetHalftone(false);
                        doc.ActiveView.SetElementOverrides(eid, ORGS);
                   }
                   else if (doc.ActiveView.GetElementOverrides(eid).Halftone == false)
                   {
                        OverrideGraphicSettings ORGS = new OverrideGraphicSettings();
                        ORGS.SetHalftone(true);
                        doc.ActiveView.SetElementOverrides(eid, ORGS);
                   }

If this helped solve your problem please mark it as solution, so other users can get this solutions as wellSmiley Happy

回复: Ducts are disconnected after changing size using code

$
0
0

Hi :

This is good post, and you stated your question clearly.

I did not completely test your smaple codes in my enrionment. But I am afraid that you did not correctly connet two ducts.

You did not invoke the method Create.NewElbowFitting() in your codes. For my experience, you should not get an elbow......Smiley Sad

You used this line to connect two ducts:

// Connect 2 connectors of 2 pipe to create the fitting
unused1.ConnectTo(list4.First());

You should try to invoke Create.NewElbowFitting() method instead of the above one.

According to your sample codes, I do believe that you are able to figure out how to use this method.!

Try it and let us know how you get Man Happy

 

In my solutions, I had tested ConnectTo method. And it sometimes leads to very wierd results or behaviours.

Re: Get Section of FamilySymbol

Viewing all 67020 articles
Browse latest View live


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