Create Pipe from CAD, using the Pipe.Create Placeholder method (PipeSegment = null).Why?

Create Pipe from CAD, using the Pipe.Create Placeholder method (PipeSegment = null).Why?

reylorente1
Collaborator Collaborator
836 Views
6 Replies
Message 1 of 7

Create Pipe from CAD, using the Pipe.Create Placeholder method (PipeSegment = null).Why?

reylorente1
Collaborator
Collaborator

From a CAD, I am creating piping of a defined layer, using
the method Pipe.CreatePlaceholder(doc,......)

It works well for me, but it gives me a warning, that I should check, PipeSegment, since it gives me null

Try this way,
// ........

using (Transaction curves = new Transaction(doc, "Create P1pe"))
{
    curves.Start();
    try
    {
        foreach (Curve c in curves11)
        {
            XYZ start = c.GetEndPoint(0);
            XYZ end = c.GetEndPoint(1);
            if (pipeType != null)
            {

                //dl = doc.Create.NewDetailCurve(doc.ActiveView, c);
                Pipe pipeHolder = Pipe.CreatePlaceholder(doc, systemType.Id, pipeType.Id, level, start, end);
                Parameter param = pipeHolder.get_Parameter(BuiltInParameter.RBS_PIPE_DIAMETER_PARAM);
                param.Set(0.041666666);
                string pipeSegmentNames = "PVC_ATA - Serie 40";
                var dfg = pipeHolder.get_Parameter(BuiltInParameter.RBS_PIPE_SEGMENT_PARAM).AsValueString();
                dfg = pipeSegmentNames;
                listPlaceholder.Add(pipeHolder.Id);
            }
        }
        doc.Regenerate();
    }
    catch (System.Exception ex)
    {
        TaskDialog.Show("Info", ex.Message);
    }
    curves.Commit();

PipeSegment = null


// ..........

I made another change, adding RoutingPreferenceManager as I show below and it also gives me that the Pipe Segment = null

 

PipeType pipeType = (from PipeType x in new FilteredElementCollector(doc).OfClass(typeof(PipeType))
                     where x.Name == "PVC - HID"
                     select x).First();
RoutingPreferenceManager rpm = pipeType.RoutingPreferenceManager;

int segmentCount = rpm.GetNumberOfRules(RoutingPreferenceRuleGroupType.Segments);

for (int index = 0; index != segmentCount; ++index)
{
    RoutingPreferenceRule segmentRule = rpm.GetRule(RoutingPreferenceRuleGroupType.Segments, index);
    Segment segment = doc.GetElement(segmentRule.MEPPartId) as Segment;

    string nombre = segment.Name; 
//.....
    
}

I really don't know how to continue...
Any ideas....??

0 Likes
837 Views
6 Replies
Replies (6)
Message 2 of 7

Moustafa_K
Advisor
Advisor

Can you check the pipe segment name is a valid name and does exists in your project.

string pipeSegmentNames = "PVC_ATA - Serie 40";

your method works fine for me when i set the name correctly, if i used any other name, it indeed returns a null segment without giving any error 

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
0 Likes
Message 3 of 7

reylorente1
Collaborator
Collaborator

Hello, yes it is correct, here in the image I show you that it exists. Hello, yes it is correct, here I show you in the images, that it existsCaptura de pantalla 2024-05-21 101525.pngCaptura de pantalla 2024-05-21 101629.png

In the third image, it is the warning that it gives me

Captura de pantalla 2024-05-21 101735.png

Also, I added this, but it gives me the same error:

string pipeSegmentNames = new FilteredElementCollector(doc)
.OfClass(typeof(PipeSegment))
.Cast<PipeSegment>()
.Where(s => s.Name == "PVC_ATA - Serie 40")
.Select(s => s.Name).First();

0 Likes
Message 4 of 7

reylorente1
Collaborator
Collaborator

And also edit Routing Preference. Here is the image:Captura de pantalla 2024-05-21 112122.png

0 Likes
Message 5 of 7

MarryTookMyCoffe
Collaborator
Collaborator

1)it look more like you try to set diameter that is not in pipie segement size.
try to turn off setting diameter and see if it will repeat. Revit can be annoying with dangling double.
2)I would check in Revit look up how segments look up.
3) try to cast it as PipeSegment it shouldn't make difference but revit api can be weird sometimes, and we will try to catch everything we can

4) if it is null try to create it and see what will happen, maybe it is problem with string coding

5) see if setting culture to en-US for some thing it help

I honestly don't see anything wrong in code, that would make problem

-------------------------------------------------------------
--------------------------------|\/\/|------------------------
do not worry it only gonna take Autodesk 5 years to fix bug
0 Likes
Message 6 of 7

reylorente1
Collaborator
Collaborator

I was reading your recommendation; I did a little test. I created a pipe from two points, and the result seemed a little strange to me.

Here is the code (Test):

 

public void CreatePipe(UIDocument uidoc)
{
    Document doc = uidoc.Document;
    //UnitSystem unitsSystem = UnitSystem.Imperial;
    
    //Get PipingSystemType
    var systemType = new FilteredElementCollector(doc).OfClass(typeof(PipingSystemType)).FirstElementId();

    Level level = uidoc.ActiveView.GenLevel;

    //Get PipeType
    var pipeTypeId = new FilteredElementCollector(doc).OfClass(typeof(PipeType)).FirstElementId();

    string val = GetNameSegmentPipeTypeFromDocument(doc, pipeTypeId);

    XYZ StarPoint = new XYZ(0,0,0);
    XYZ EndPoint = new XYZ(60,0,0);

    using (Transaction curves = new Transaction(doc, "Create P1pe"))
    {
        curves.Start();
        Pipe pipeHolder = Pipe.Create(doc, systemType, pipeTypeId, level.Id, StarPoint, EndPoint);
        doc.Regenerate();
        curves.Commit();
    }
}

 

I first opened it with a metric template and it kept giving me the same no result (PipeSegment = empty)

Plumbing-Default_Metric.rte

Captura de pantalla 2024-05-22 114016.png

Then I opened it with an Imperial screen and then it works, that is, the result appears.

Plumbing-Default.rte

Captura de pantalla 2024-05-22 114233.png

And then it could be a Revit problem or something is missing in the code, so that it recognizes the value?

0 Likes
Message 7 of 7

h.f.h
Contributor
Contributor

Hey there, I found this post because I am trying to do basically the same but for plumbing porpoises. Do you have any thoughts to share? I am stuck on the pipe system, the program always returns an error. 

 

I just published something here:

 

https://forums.autodesk.com/t5/revit-api-forum/creating-pipe-placeholder-from-line/td-p/12911712

0 Likes