Create an instance of a family on work plane.

Create an instance of a family on work plane.

Yonas89
Collaborator Collaborator
4,421 Views
9 Replies
Message 1 of 10

Create an instance of a family on work plane.

Yonas89
Collaborator
Collaborator

Hello, I am struggling to place an instance of a profile family on a work plane. I am not sure if I am moving to write direction, so maybe someone could check my code or give a link to solution how to place family instance on a work plane.

ReferencePlane frbackPlane = null;
// get a reference plane FilteredElementCollector planescollector = new FilteredElementCollector(RvtDoc.revdoc); ICollection<Element> planesInProject = planescollector.OfClass(typeof(ReferencePlane)).ToElements(); foreach (ReferencePlane planeEl in planesInProject) { if (planeEl.Name == "Center (Front/Back)") { frbackPlane = planeEl; } } // place family instance
FamilySymbol famsym = RvtDoc.revdoc.GetElement(loadedfamel) as FamilySymbol; XYZ startLoc = new XYZ(0, 0, 0); XYZ endLoc = new XYZ(0, 0, 100); famsym.Activate(); famsym.get_Parameter(BuiltInParameter.FAMILY_WORK_PLANE_BASED).Set(0); FamilyInstance instance = RvtDoc.revdoc.FamilyCreate.NewFamilyInstance(frbackPlane.GetReference(), startLoc, endLoc, famsym);
0 Likes
4,422 Views
9 Replies
Replies (9)
Message 2 of 10

Yonas89
Collaborator
Collaborator

I wanted to elaborate a bit o my question. Please fin an attached image below, which represents my goal. I believe I have to use NewFamilyInstance Method (Reference, Line, FamilySymbol)  method. However struggle to implement it as I get an error that Lines is not on face. 

Capture.PNG

0 Likes
Message 3 of 10

JimJia
Alumni
Alumni

dear Jonas Grazys,

 

can you provide a reproducible case for it?


In order to explore this matter further, we will need to provide a minimal reproducible case for the development team to analyse in depth.


In order to understand exactly what you mean and be able to research possible reasons for the discrepancy between the observed and expected behaviour, they require: 
· A short exact description of what you are trying to achieve.
· The behavior you observe versus what you expect, and why this is a problem.
· A complete yet minimal Revit sample model to run a test in.
· A complete yet minimal macro embedded in the sample model or Visual Studio solution with add-in manifest that can be compiled, loaded, run and debugged with a single click to analyse its behavior live in the sample model.
· Detailed step-by-step instructions for reproducing the issue, e.g. which element to pick, what command to launch etc.
· http://thebuildingcoder.typepad.com/blog/about-the-author.html#1b

 

 


Jim Jia
Autodesk Forge Evangelist
https://forge.autodesk.com
Developer Technical Services
Autodesk Developer Network
Email: [email protected]
0 Likes
Message 4 of 10

stever66
Advisor
Advisor

I'm not sure how you are getting your family symbol, but this works when ran as a macro.  I changed the family name to match one I had.  I assume you are aware this has to run from within the family editor, since its using the FamilyCreate method.

 

UIDocument uidoc = ActiveUIDocument;
            Document doc = ActiveUIDocument.Document;
            Autodesk.Revit.DB.View pView = ActiveUIDocument.Document.ActiveView;
            ReferencePlane frbackPlane = null;

            // get a reference plane 
                FilteredElementCollector planescollector = new FilteredElementCollector(doc);
                ICollection<Element> planesInProject = planescollector.OfClass(typeof(ReferencePlane)).ToElements();
                foreach (ReferencePlane planeEl in planesInProject)
                {
                 if (planeEl.Name == "Center (Front/Back)")
                    {
                      frbackPlane = planeEl;
                      TaskDialog.Show("Revit", frbackPlane.Name.ToString());
                    }
                }
            // place family instance

            FilteredElementCollector familyCollector = new FilteredElementCollector(doc);
            familyCollector.OfClass(typeof(FamilySymbol));
            FamilySymbol famsym = null;
                   foreach (FamilySymbol familySymbol in familyCollector)

                    {

                        //To search by Family name and FamilySymbol name
                            //if (familySymbol.Name == "receptacle" && familySymbol.Family.Name == "duplex")
                        //To search by FamilySymbol name
                            if (familySymbol.Name == "loadedfamily1")
                            {
                                famsym = familySymbol;
                                TaskDialog.Show("Revit", famsym.Name.ToString());
                                
                            }

                        

                    }// end foreach

                    //uidoc.PromptForFamilyInstancePlacement(familySymbolToFind);

            
        //FamilySymbol famsym = doc.GetElement(loadedfamel) as FamilySymbol;
        TaskDialog.Show("Revit""Continue");
        XYZ startLoc = new XYZ(000);
        XYZ endLoc = new XYZ(000);
        //famsym.Activate();
        //famsym.get_Parameter(BuiltInParameter.FAMILY_WORK_PLANE_BASED).Set(0);
        //FamilyInstance instance = doc.FamilyCreate.NewFamilyInstance(frbackPlane.GetReference(), startLoc, endLoc, famsym);
        using (Transaction t = new Transaction(doc, "Set Param"))
        {
            
            t.Start();
            FamilyInstance instance = doc.FamilyCreate.NewFamilyInstance(frbackPlane.GetReference(), startLoc, endLoc, famsym);
            t.Commit();
        }
        }

 

0 Likes
Message 5 of 10

Yonas89
Collaborator
Collaborator

@stever66, thanks for your reply. 

I have luck in  placing family instance with these methods : "NewFamilyInstance Method (XYZ, FamilySymbol, Element, StructuralType)", "NewFamilyInstance Method (XYZ, FamilySymbol, StructuralType)", however none of these assigns host element to my family instance. @JimJia  I need to create new family instance which would be placed on "Center/Back" work plane. It looks that I cannot change a default family placement type to work plane based and when I try to use  "NewFamilyInstance Method (Reference, XYZ, XYZ, FamilySymbol)" method, I get an error that FamilyPlacementType is not WorkPlaneBased.

0 Likes
Message 6 of 10

stever66
Advisor
Advisor
0 Likes
Message 7 of 10

Yonas89
Collaborator
Collaborator

@stever66,

thank you for the information. I cannot find such parameter "Work plane based" in my family. Does it mean it's not work plane based. As much as I know the family has been created using one of the structural framing templates coming along with Revit.

0 Likes
Message 8 of 10

stever66
Advisor
Advisor

Then it probably isn't a workplane based family.   A "hosted" family cannot be changed to a workplane based family.

 

I've attached a sample of a workplane based family that is a simple cube.  (Revit 2018).

 

Message 9 of 10

Yonas89
Collaborator
Collaborator

@stever66

 

thanks for your reply. I have decided to place a dummy profile ( family instance) manually, thus I can select that it could be placed on a work place. Then with my code I  switch family symbols, make copies of that profiles and transform where I need. That's a bit nasty, but still a workaround.

0 Likes
Message 10 of 10

barody_unique
Community Visitor
Community Visitor

plz could you comment with proper code , I searched about it and tried many codes but invain .

0 Likes