Align Pipe object and clip model and lock using alignment method

Align Pipe object and clip model and lock using alignment method

Anonymous
Not applicable
606 Views
0 Replies
Message 1 of 1

Align Pipe object and clip model and lock using alignment method

Anonymous
Not applicable

Hello,

 

 

I have to align Pipe and our clip model using centerlines but not able able to get center-line(axis) of oriented clip and its reference. Once it is aligned we want to lock the clip also.

 

Steps followed :

1. Drawn a pipe.

2. Inserted clip model on the pipe.

3. In the below code- selecting pipe and clip and aligning them using center line.

 

 

Below is the i am using.

 

pipeObjectreference                         = choices.PickObject(ObjectType.PointOnElement, pipeSelectionFilter, "Please select pipe");
                                       
            if (pipeObjectreference != null)
            {
                Element pipeElement                    = document_.GetElement(pipeObjectreference.ElementId);
                Pipe pipe = pipeElement as Pipe;
                endPoint                             = ((pipeElement.Location as LocationCurve).Curve as Line).GetEndPoint(1);
                startPoint                             = ((pipeElement.Location as LocationCurve).Curve as Line).GetEndPoint(0);
                pipeAxis                             = Line.CreateBound(startPoint, endPoint);
                Reference pipeReference             = GetCenterline(pipe);
                pipeDirection                         = (endPoint - startPoint).Normalize();
                
                
                clipObjectreference                 = choices.PickObject(ObjectType.PointOnElement, clipSelectionFilter, "Please select clip");
                FamilyInstance clipInstance            = document_.GetElement(clipObjectreference.ElementId) as FamilyInstance;
                Reference clipReference                = centerXRef(clipInstance); // not returning the oriented center line of clip
                if(clipObjectreference != null)
                {
                    using (Transaction transaction = new Transaction(document_))
                    {
                        try
                        {
                            transaction.Start("Align clip on pipe");
                            dimension = document_.Create.NewAlignment(view, pipeReference ,clipReference);  // throwing an exception                         
                            transaction.Commit();
                        }
                        catch (Exception ex)
                        {
                            Autodesk.Revit.UI.TaskDialog.Show("Valsir Clip Insertion Tool"""+ex.ToString());
                        }
                    }
                }

 

 

 

 

Functions used above :

public Reference centerXRef(FamilyInstance fi)
        {
            Reference reference = null;
            Options opt = new Options();
            opt.ComputeReferences = true;
            opt.IncludeNonVisibleObjects = true;
            opt.View = document_.ActiveView;            
            GeometryElement geometryElement = fi.get_Geometry(opt);
            GeometryInstance geometryInstance = geometryElement.First() as GeometryInstance;
            foreach (var obj in geometryInstance.GetInstanceGeometry())
            {
                Line lineObj = obj as Line;
                if (lineObj != null)
                {
                    reference = lineObj.Reference;
                    return reference;
                }
            }
            return null;
        }
        
        private Reference GetCenterline(Pipe pipe)
        {
            Options options = new Options();
            options.ComputeReferences = true//!!!
            options.IncludeNonVisibleObjects = true//!!! 
            if (pipe.Document.ActiveView != null)
                options.View = pipe.Document.ActiveView;
            else
                options.DetailLevel = ViewDetailLevel.Fine;
        
            var geoElem = pipe.get_Geometry(options);
            
            foreach (var item in geoElem)
            {
                Line lineObj = item as Line;
                if (lineObj != null)
                {
                    return lineObj.Reference;
                }
            }
            return null;
        }

0 Likes
607 Views
0 Replies
Replies (0)