Unable to create elbow fitting via api but able to create via command TR

Unable to create elbow fitting via api but able to create via command TR

1368026189
Enthusiast Enthusiast
1,657 Views
7 Replies
Message 1 of 8

Unable to create elbow fitting via api but able to create via command TR

1368026189
Enthusiast
Enthusiast

Unable to create elbow fitting via api but able to create via command TR

 

in revit :

first vertical then horizontal we can add elbow successfully

first horizontal unable to pick the vertical pipe.

 

attachment is my test rvt file 

the vertical pipe has a slope about to 199900%.

but i have to connect this two pipe via api.

any help?

thanks

 

0 Likes
1,658 Views
7 Replies
Replies (7)
Message 2 of 8

jlpgy
Advocate
Advocate

Hi:

What's your problem?

It's very easy to connect these two Pipes:

I have done this job by typing in codes within 5 minutes.

2019-12-16_165836.png

WHAT IS YOUR PROBLEM?

Having trouble Picking? Or having trouble Connecting?

单身狗;代码狗;健身狗;jolinpiggy@hotmail.com
0 Likes
Message 3 of 8

1368026189
Enthusiast
Enthusiast

Hello Jin

 

You pick hor pipe first or vertical first?

0 Likes
Message 4 of 8

1368026189
Enthusiast
Enthusiast
 private UIDocument uidoc;
    private Document doc;
    public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
    {


      uidoc = commandData.Application.ActiveUIDocument;

      doc = uidoc.Document;

      var sel = uidoc.Selection;


      var ref01 = sel.PickObject(ObjectType.Element);

      var ref02 = sel.PickObject(ObjectType.Element);


      var pipe01 = doc.GetElement(ref01.ElementId) as Pipe;
      var pipe02 = doc.GetElement(ref02.ElementId) as Pipe;



      var pt01 = ref01.GlobalPoint;
      var pt02 = ref02.GlobalPoint;

      var con01 = MepHelper.GetConnectorClosestTo(pipe01.ConnectorManager.Connectors, pt01);
      var con02 = MepHelper.GetConnectorClosestTo(pipe02.ConnectorManager.Connectors, pt02);


      doc.Create.NewElbowFitting(con01, con02);




      return Result.Succeeded;

---------------------------

---------------------------
Autodesk.Revit.Exceptions.InvalidOperationException: Fitting cannot be created between the input connectors because they are not close enough for intersection.
在 Autodesk.Revit.Creation.Document.NewElbowFitting(Connector connector1, Connector connector2)
 -------------------------

Hi Jin,

I add a test project and it does not work  too!

0 Likes
Message 5 of 8

jlpgy
Advocate
Advocate

Hi:

断点在这一行,break point at the following line

var con01 = MepHelper.GetConnectorClosestTo(pipe01.ConnectorManager.Connectors, pt01);

Step over it.

Check the con01.CoordinateSystem.BasisZ property.

In the rvt document you supplied, the only possible connector pair should be

  • BasisZ of one connector should be (0, 0, 1)
  • BasisZ of the other should be (0, 1, 0)

 

单身狗;代码狗;健身狗;jolinpiggy@hotmail.com
0 Likes
Message 6 of 8

1368026189
Enthusiast
Enthusiast

HI jin ,

I got (-0.000625164642542109, 0, -0.999999804584566)

         (1,0,0)

and in fact the vertical pipe is not  upright , maybe i uploaded a wrong file?

bad pipe.PNG

0 Likes
Message 7 of 8

jlpgy
Advocate
Advocate

Well:

I'm telling you that Revit API does not allow elbow connecting between ACUTE angle.

try use the following

var angle = conn1.CoordinateSystem.BasisZ.AngleTo(conn2.CoordinateSystem.BasisZ);

Check the angle value (it's is Rad unit, which means you should convert it into Degree if it's inconvenient for you to read the value).

In your issue, notice that one conn.BasisZ == (1,0,0).

Remeber that API forbits elbow connection for an "Acute" angle, so the other connector.BasisZ MUST NOT be negative.

Got my point?

In your case, the correct connector pair should be

  1. (1,0,0)
  2. (0,0,1)

 

Besides, in you rvt document, if you want to create an elbow, one connector is (1,0,0), and another should be nearly (0,0,1) , but not (0,0,-1) which is the wrong connector.

If I had guessed correctly, pay more attention to the Pick point (you mouse left click point), make sure that the pick point is close to the "NEAR" end of a Pipe.

 

To my experience, 2 issues:

  1. wrong connector
  2. the wrong connector leads to an "ACUTE" angle
单身狗;代码狗;健身狗;jolinpiggy@hotmail.com
0 Likes
Message 8 of 8

1368026189
Enthusiast
Enthusiast

Thanks Jin,

 

0 Likes